@@ -18,8 +18,10 @@ package controller
18
18
19
19
import (
20
20
"testing"
21
+ "time"
21
22
22
23
. "github.com/onsi/gomega"
24
+ appsv1 "k8s.io/api/apps/v1"
23
25
corev1 "k8s.io/api/core/v1"
24
26
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
25
27
"k8s.io/apimachinery/pkg/runtime"
@@ -39,7 +41,7 @@ apiVersion: clusterctl.cluster.x-k8s.io/v1alpha3
39
41
releaseSeries:
40
42
- major: 0
41
43
minor: 4
42
- contract: v1alpha4
44
+ contract: v1beta1
43
45
`
44
46
testComponents = `
45
47
apiVersion: apps/v1
@@ -215,22 +217,47 @@ func TestReconcilerPreflightConditions(t *testing.T) {
215
217
}
216
218
}
217
219
218
- func TestUpgradeDowngradeProvider (t * testing.T ) {
220
+ func TestAirGappedUpgradeDowngradeProvider (t * testing.T ) {
221
+ currentVersion := "v999.9.2"
222
+ futureMetadata := `
223
+ apiVersion: clusterctl.cluster.x-k8s.io/v1alpha3
224
+ releaseSeries:
225
+ - major: 999
226
+ minor: 9
227
+ contract: v1beta1
228
+ `
229
+
230
+ dummyFutureConfigMap := func (ns , name string ) * corev1.ConfigMap {
231
+ return & corev1.ConfigMap {
232
+ ObjectMeta : metav1.ObjectMeta {
233
+ Name : name ,
234
+ Namespace : ns ,
235
+ Labels : map [string ]string {
236
+ "test" : "dummy-config" ,
237
+ },
238
+ },
239
+ Data : map [string ]string {
240
+ "metadata" : futureMetadata ,
241
+ "components" : testComponents ,
242
+ },
243
+ }
244
+ }
245
+
219
246
testCases := []struct {
220
247
name string
221
248
newVersion string
222
249
}{
223
250
{
224
251
name : "same provider version" ,
225
- newVersion : "v0.4 .2" ,
252
+ newVersion : "v999.9 .2" ,
226
253
},
227
254
{
228
255
name : "upgrade provider version" ,
229
- newVersion : "v0.4 .3" ,
256
+ newVersion : "v999.9 .3" ,
230
257
},
231
258
{
232
259
name : "downgrade provider version" ,
233
- newVersion : "v0.4 .1" ,
260
+ newVersion : "v999.9 .1" ,
234
261
},
235
262
}
236
263
@@ -244,7 +271,7 @@ func TestUpgradeDowngradeProvider(t *testing.T) {
244
271
},
245
272
Spec : operatorv1.CoreProviderSpec {
246
273
ProviderSpec : operatorv1.ProviderSpec {
247
- Version : testCurrentVersion ,
274
+ Version : currentVersion ,
248
275
},
249
276
},
250
277
}
@@ -254,7 +281,7 @@ func TestUpgradeDowngradeProvider(t *testing.T) {
254
281
t .Log ("Ensure namespace exists" , namespace )
255
282
g .Expect (env .EnsureNamespaceExists (ctx , namespace )).To (Succeed ())
256
283
257
- g .Expect (env .CreateAndWait (ctx , dummyConfigMap (namespace , testCurrentVersion ))).To (Succeed ())
284
+ g .Expect (env .CreateAndWait (ctx , dummyFutureConfigMap (namespace , currentVersion ))).To (Succeed ())
258
285
259
286
insertDummyConfig (provider )
260
287
provider .SetNamespace (namespace )
@@ -266,7 +293,7 @@ func TestUpgradeDowngradeProvider(t *testing.T) {
266
293
return false
267
294
}
268
295
269
- if provider .GetStatus ().InstalledVersion == nil || * provider .GetStatus ().InstalledVersion != testCurrentVersion {
296
+ if provider .GetStatus ().InstalledVersion == nil || * provider .GetStatus ().InstalledVersion != currentVersion {
270
297
return false
271
298
}
272
299
@@ -283,13 +310,16 @@ func TestUpgradeDowngradeProvider(t *testing.T) {
283
310
}, timeout ).Should (BeEquivalentTo (true ))
284
311
285
312
// creating another configmap with another version
286
- if tc .newVersion != testCurrentVersion {
287
- g .Expect (env .CreateAndWait (ctx , dummyConfigMap (namespace , tc .newVersion ))).To (Succeed ())
313
+ if tc .newVersion != currentVersion {
314
+ g .Expect (env .CreateAndWait (ctx , dummyFutureConfigMap (namespace , tc .newVersion ))).To (Succeed ())
288
315
}
289
316
290
317
// Change provider version
291
318
providerSpec := provider .GetSpec ()
292
319
providerSpec .Version = tc .newVersion
320
+ providerSpec .Deployment = & operatorv1.DeploymentSpec {
321
+ Replicas : pointer .Int (2 ),
322
+ }
293
323
provider .SetSpec (providerSpec )
294
324
295
325
// Set label (needed to start a reconciliation of the provider)
@@ -315,23 +345,68 @@ func TestUpgradeDowngradeProvider(t *testing.T) {
315
345
return false
316
346
}
317
347
348
+ allFound := false
318
349
for _ , cond := range provider .GetStatus ().Conditions {
319
350
if cond .Type == operatorv1 .PreflightCheckCondition {
320
351
t .Log (t .Name (), provider .GetName (), cond )
321
352
if cond .Status == corev1 .ConditionTrue {
322
- return true
353
+ allFound = true
354
+ break
323
355
}
324
356
}
325
357
}
326
358
327
- return false
359
+ if ! allFound {
360
+ return false
361
+ }
362
+
363
+ allFound = tc .newVersion == currentVersion
364
+ for _ , cond := range provider .GetStatus ().Conditions {
365
+ if cond .Type == operatorv1 .ProviderUpgradedCondition {
366
+ t .Log (t .Name (), provider .GetName (), cond )
367
+ if cond .Status == corev1 .ConditionTrue {
368
+ allFound = tc .newVersion != currentVersion
369
+ break
370
+ }
371
+ }
372
+ }
373
+
374
+ if ! allFound {
375
+ return false
376
+ }
377
+
378
+ // Ensure customization occurred
379
+ dep := & appsv1.Deployment {ObjectMeta : metav1.ObjectMeta {
380
+ Namespace : provider .Namespace ,
381
+ Name : "capd-controller-manager" ,
382
+ }}
383
+ if err := env .Get (ctx , client .ObjectKeyFromObject (dep ), dep ); err != nil {
384
+ return false
385
+ }
386
+
387
+ return dep .Spec .Replicas != nil && * dep .Spec .Replicas == 2
328
388
}, timeout ).Should (BeEquivalentTo (true ))
329
389
390
+ g .Consistently (func () bool {
391
+ allSet := tc .newVersion == currentVersion
392
+ for _ , cond := range provider .GetStatus ().Conditions {
393
+ if cond .Type == operatorv1 .ProviderUpgradedCondition {
394
+ t .Log (t .Name (), provider .GetName (), cond )
395
+ if cond .Status == corev1 .ConditionTrue {
396
+ allSet = tc .newVersion != currentVersion
397
+ break
398
+ }
399
+ }
400
+ }
401
+
402
+ return allSet
403
+ }, 2 * time .Second ).Should (BeTrue ())
404
+
330
405
// Clean up
331
406
objs := []client.Object {provider }
332
407
objs = append (objs , & corev1.ConfigMap {
333
408
ObjectMeta : metav1.ObjectMeta {
334
- Name : testCurrentVersion ,
409
+ Name : currentVersion ,
335
410
Namespace : namespace ,
336
411
},
337
412
})
0 commit comments