@@ -18,10 +18,10 @@ package controllers
18
18
19
19
import (
20
20
"context"
21
+ "time"
21
22
22
23
. "github.com/onsi/ginkgo"
23
24
. "github.com/onsi/gomega"
24
-
25
25
appsv1 "k8s.io/api/apps/v1"
26
26
corev1 "k8s.io/api/core/v1"
27
27
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -32,6 +32,7 @@ import (
32
32
33
33
tenancyv1alpha1 "sigs.k8s.io/cluster-api-provider-nested/virtualcluster/pkg/apis/tenancy/v1alpha1"
34
34
"sigs.k8s.io/cluster-api-provider-nested/virtualcluster/pkg/controller/secret"
35
+ "sigs.k8s.io/cluster-api-provider-nested/virtualcluster/pkg/syncer/constants"
35
36
)
36
37
37
38
func getClusterObjectKey (instance * tenancyv1alpha1.VirtualCluster , name string ) client.ObjectKey {
@@ -41,11 +42,14 @@ func getClusterObjectKey(instance *tenancyv1alpha1.VirtualCluster, name string)
41
42
var _ = Describe ("VirtualCluster Controller" , func () {
42
43
43
44
Context ("Reconcile VirtualCluster Cluster" , func () {
45
+ var cvInstance * tenancyv1alpha1.ClusterVersion
46
+ var instance * tenancyv1alpha1.VirtualCluster
47
+
44
48
It ("Should create resources successfully" , func () {
45
49
ctx := context .TODO ()
46
50
Expect (cli ).ShouldNot (BeNil ())
47
51
48
- cvInstance : = createClusterVersion ()
52
+ cvInstance = createClusterVersion ()
49
53
Expect (cli .Create (ctx , cvInstance )).Should (Succeed ())
50
54
51
55
By ("Fetching ClusterVersion" )
@@ -55,7 +59,7 @@ var _ = Describe("VirtualCluster Controller", func() {
55
59
return ! apierrors .IsNotFound (err )
56
60
}, timeout , interval ).Should (BeTrue ())
57
61
58
- instance : = & tenancyv1alpha1.VirtualCluster {
62
+ instance = & tenancyv1alpha1.VirtualCluster {
59
63
ObjectMeta : metav1.ObjectMeta {
60
64
GenerateName : "virtualcluster-sample" ,
61
65
Namespace : "default" ,
@@ -161,9 +165,71 @@ var _ = Describe("VirtualCluster Controller", func() {
161
165
By ("Faking controller-manager STS Status Updates" )
162
166
err = cli .Status ().Update (ctx , cmSts )
163
167
Expect (err ).To (BeNil ())
168
+ })
169
+ It ("Should upgrade resources successfully" , func () {
170
+ ctx := context .TODO ()
171
+ Expect (cli ).ShouldNot (BeNil ())
172
+
173
+ objectKey := client .ObjectKeyFromObject (instance )
174
+
175
+ By ("Checking cluster phase" )
176
+ Eventually (func () bool {
177
+ err := cli .Get (ctx , objectKey , instance )
178
+ return err == nil && instance .Status .Phase == tenancyv1alpha1 .ClusterRunning
179
+ }, time .Minute * 5 , interval ).Should (BeTrue ())
180
+
181
+ By ("Updating ClusterVersion" )
182
+ cvInstance .Spec .ETCD .StatefulSet .Spec .Template .Spec .Containers [0 ].Args = append ([]string {"-debug" }, cvInstance .Spec .ETCD .StatefulSet .Spec .Template .Spec .Containers [0 ].Args ... )
183
+ cvInstance .Spec .APIServer .StatefulSet .Spec .Template .Spec .Containers [0 ].Args = append ([]string {"-v=7" }, cvInstance .Spec .APIServer .StatefulSet .Spec .Template .Spec .Containers [0 ].Args ... )
184
+ if cvInstance .Spec .APIServer .Service .Labels == nil {
185
+ cvInstance .Spec .APIServer .Service .Labels = map [string ]string {}
186
+ }
187
+ cvInstance .Spec .APIServer .Service .Labels ["test-label" ] = "test"
188
+ cvInstance .Spec .ControllerManager .StatefulSet .Spec .Template .Spec .Containers [0 ].Args = append ([]string {"-v=7" }, cvInstance .Spec .ControllerManager .StatefulSet .Spec .Template .Spec .Containers [0 ].Args ... )
189
+ cvInstance .ObjectMeta .ManagedFields = nil
190
+ forceTrue := true
191
+ Expect (cli .Patch (ctx , cvInstance , client .Apply , & client.PatchOptions {Force : & forceTrue , FieldManager : "test" })).Should (Succeed ())
192
+
193
+ By ("Enable upgrade for cluster" )
194
+ instance .Labels [constants .LabelVCReadyForUpgrade ] = "true"
195
+ instance .ObjectMeta .ManagedFields = nil
196
+ Expect (cli .Patch (ctx , instance , client .Apply , & client.PatchOptions {Force : & forceTrue , FieldManager : "test" })).Should (Succeed ())
197
+
198
+ By ("APIServer Service upgraded" )
199
+ Eventually (func () bool {
200
+ svcObjectKey := getClusterObjectKey (instance , "apiserver-svc" )
201
+ svc := & corev1.Service {}
202
+ err := cli .Get (ctx , svcObjectKey , svc )
203
+ return ! apierrors .IsNotFound (err ) && svc .Labels ["test-label" ] == "test"
204
+ }, time .Minute * 2 , interval ).Should (BeTrue ())
164
205
206
+ etcdSts := & appsv1.StatefulSet {}
207
+ By ("Control Plane etcd StatefulSet upgraded" )
208
+ Eventually (func () bool {
209
+ stsObjectKey := getClusterObjectKey (instance , "etcd" )
210
+ err := cli .Get (ctx , stsObjectKey , etcdSts )
211
+ return ! apierrors .IsNotFound (err ) && etcdSts .Spec .Template .Spec .Containers [0 ].Args [0 ] == "-debug"
212
+ }, time .Minute * 2 , interval ).Should (BeTrue ())
213
+
214
+ apiserverSts := & appsv1.StatefulSet {}
215
+ By ("Control Plane apiserver StatefulSet upgraded" )
216
+ Eventually (func () bool {
217
+ stsObjectKey := getClusterObjectKey (instance , "apiserver" )
218
+ err := cli .Get (ctx , stsObjectKey , apiserverSts )
219
+ return ! apierrors .IsNotFound (err ) && apiserverSts .Spec .Template .Spec .Containers [0 ].Args [0 ] == "-v=7"
220
+ }, time .Minute * 2 , interval ).Should (BeTrue ())
221
+
222
+ cmSts := & appsv1.StatefulSet {}
223
+ By ("Control Plane controller-manager StatefulSet upgraded" )
224
+ Eventually (func () bool {
225
+ stsObjectKey := getClusterObjectKey (instance , "controller-manager" )
226
+ err := cli .Get (ctx , stsObjectKey , cmSts )
227
+ return ! apierrors .IsNotFound (err ) && cmSts .Spec .Template .Spec .Containers [0 ].Args [0 ] == "-v=7"
228
+ }, time .Minute * 2 , interval ).Should (BeTrue ())
229
+ })
230
+ It ("Should delete cluster" , func () {
165
231
By ("Deleting VirtualCluster" )
166
- Expect (cli .Delete (ctx , instance )).To (BeNil ())
232
+ Expect (cli .Delete (context . TODO () , instance )).To (BeNil ())
167
233
})
168
234
})
169
235
})
0 commit comments