@@ -211,16 +211,17 @@ func Test_shouldUpgrade(t *testing.T) {
211
211
objs []unstructured.Unstructured
212
212
}
213
213
tests := []struct {
214
- name string
215
- configVersion string
216
- args args
217
- wantFromVersion string
218
- wantToVersion string
219
- want bool
220
- wantErr bool
214
+ name string
215
+ configVersion string
216
+ args args
217
+ wantFromVersion string
218
+ hasDiffInstallObjs bool
219
+ want bool
220
+ wantErr bool
221
221
}{
222
222
{
223
- name : "Version is not defined (e.g. cluster created with clusterctl < v0.3.9), should upgrade" ,
223
+ name : "Version is not defined (e.g. cluster created with clusterctl < v0.3.9), should upgrade" ,
224
+ configVersion : config .CertManagerDefaultVersion ,
224
225
args : args {
225
226
objs : []unstructured.Unstructured {
226
227
{
@@ -229,12 +230,12 @@ func Test_shouldUpgrade(t *testing.T) {
229
230
},
230
231
},
231
232
wantFromVersion : "v0.11.0" ,
232
- wantToVersion : config .CertManagerDefaultVersion ,
233
233
want : true ,
234
234
wantErr : false ,
235
235
},
236
236
{
237
- name : "Version is equal, should not upgrade" ,
237
+ name : "Version is equal, should not upgrade" ,
238
+ configVersion : config .CertManagerDefaultVersion ,
238
239
args : args {
239
240
objs : []unstructured.Unstructured {
240
241
{
@@ -249,7 +250,6 @@ func Test_shouldUpgrade(t *testing.T) {
249
250
},
250
251
},
251
252
wantFromVersion : config .CertManagerDefaultVersion ,
252
- wantToVersion : config .CertManagerDefaultVersion ,
253
253
want : false ,
254
254
wantErr : false ,
255
255
},
@@ -270,7 +270,6 @@ func Test_shouldUpgrade(t *testing.T) {
270
270
},
271
271
},
272
272
wantFromVersion : "v1.5.3" ,
273
- wantToVersion : "v1.5.3+h4fd4" ,
274
273
want : true ,
275
274
wantErr : false ,
276
275
},
@@ -291,7 +290,6 @@ func Test_shouldUpgrade(t *testing.T) {
291
290
},
292
291
},
293
292
wantFromVersion : "v1.5.3+h4fd5" ,
294
- wantToVersion : "v1.5.3+h4fd4" ,
295
293
want : true ,
296
294
wantErr : false ,
297
295
},
@@ -312,7 +310,6 @@ func Test_shouldUpgrade(t *testing.T) {
312
310
},
313
311
},
314
312
wantFromVersion : "v1.5.3+h4fd5" ,
315
- wantToVersion : "v1.5.3+h4fd5" ,
316
313
want : false ,
317
314
wantErr : false ,
318
315
},
@@ -333,7 +330,6 @@ func Test_shouldUpgrade(t *testing.T) {
333
330
},
334
331
},
335
332
wantFromVersion : "v1.5.3+build.2" ,
336
- wantToVersion : "v1.5.3+build.1" ,
337
333
want : false ,
338
334
wantErr : false ,
339
335
},
@@ -354,12 +350,33 @@ func Test_shouldUpgrade(t *testing.T) {
354
350
},
355
351
},
356
352
wantFromVersion : "v1.5.3+build.2" ,
357
- wantToVersion : "v1.5.3+build.3" ,
358
353
want : true ,
359
354
wantErr : false ,
360
355
},
361
356
{
362
- name : "Version is older, should upgrade" ,
357
+ name : "Version is equal, but should upgrade because objects to install are a different size" ,
358
+ configVersion : config .CertManagerDefaultVersion ,
359
+ args : args {
360
+ objs : []unstructured.Unstructured {
361
+ {
362
+ Object : map [string ]interface {}{
363
+ "metadata" : map [string ]interface {}{
364
+ "annotations" : map [string ]interface {}{
365
+ clusterctlv1 .CertManagerVersionAnnotation : config .CertManagerDefaultVersion ,
366
+ },
367
+ },
368
+ },
369
+ },
370
+ },
371
+ },
372
+ wantFromVersion : config .CertManagerDefaultVersion ,
373
+ hasDiffInstallObjs : true ,
374
+ want : true ,
375
+ wantErr : false ,
376
+ },
377
+ {
378
+ name : "Version is older, should upgrade" ,
379
+ configVersion : config .CertManagerDefaultVersion ,
363
380
args : args {
364
381
objs : []unstructured.Unstructured {
365
382
{
@@ -374,12 +391,12 @@ func Test_shouldUpgrade(t *testing.T) {
374
391
},
375
392
},
376
393
wantFromVersion : "v0.11.0" ,
377
- wantToVersion : config .CertManagerDefaultVersion ,
378
394
want : true ,
379
395
wantErr : false ,
380
396
},
381
397
{
382
- name : "Version is newer, should not upgrade" ,
398
+ name : "Version is newer, should not upgrade" ,
399
+ configVersion : config .CertManagerDefaultVersion ,
383
400
args : args {
384
401
objs : []unstructured.Unstructured {
385
402
{
@@ -394,12 +411,13 @@ func Test_shouldUpgrade(t *testing.T) {
394
411
},
395
412
},
396
413
wantFromVersion : "v100.0.0" ,
397
- wantToVersion : config .CertManagerDefaultVersion ,
398
414
want : false ,
399
415
wantErr : false ,
400
416
},
417
+
401
418
{
402
- name : "Endpoint are ignored" ,
419
+ name : "Endpoint are ignored" ,
420
+ configVersion : config .CertManagerDefaultVersion ,
403
421
args : args {
404
422
objs : []unstructured.Unstructured {
405
423
{
@@ -415,7 +433,6 @@ func Test_shouldUpgrade(t *testing.T) {
415
433
},
416
434
},
417
435
wantFromVersion : "" ,
418
- wantToVersion : config .CertManagerDefaultVersion ,
419
436
want : false ,
420
437
wantErr : false ,
421
438
},
@@ -431,7 +448,16 @@ func Test_shouldUpgrade(t *testing.T) {
431
448
}
432
449
cm := newCertManagerClient (fakeConfigClient , nil , proxy , pollImmediateWaiter )
433
450
434
- fromVersion , toVersion , got , err := cm .shouldUpgrade (tt .args .objs )
451
+ // By default, make the installed and to-be-installed objects the same, but if hasDiffInstallObjs is set,
452
+ // just append an empty unstructured object at the end to make them different.
453
+ installObjs := tt .args .objs
454
+ if tt .hasDiffInstallObjs {
455
+ installObjs = make ([]unstructured.Unstructured , len (tt .args .objs ))
456
+ copy (installObjs , tt .args .objs )
457
+ installObjs = append (installObjs , unstructured.Unstructured {})
458
+ }
459
+
460
+ fromVersion , got , err := cm .shouldUpgrade (tt .configVersion , tt .args .objs , installObjs )
435
461
if tt .wantErr {
436
462
g .Expect (err ).To (HaveOccurred ())
437
463
return
@@ -440,7 +466,6 @@ func Test_shouldUpgrade(t *testing.T) {
440
466
441
467
g .Expect (got ).To (Equal (tt .want ))
442
468
g .Expect (fromVersion ).To (Equal (tt .wantFromVersion ))
443
- g .Expect (toVersion ).To (Equal (tt .wantToVersion ))
444
469
})
445
470
}
446
471
}
@@ -718,7 +743,17 @@ func Test_certManagerClient_PlanUpgrade(t *testing.T) {
718
743
pollImmediateWaiter := func (context.Context , time.Duration , time.Duration , wait.ConditionWithContextFunc ) error {
719
744
return nil
720
745
}
721
- cm := newCertManagerClient (fakeConfigClient , nil , proxy , pollImmediateWaiter )
746
+
747
+ // Prepare a fake memory repo from which getManifestObjs(), called from PlanUpgrade() will fetch to-be-installed objects.
748
+ fakeRepositoryClientFactory := func (ctx context.Context , provider config.Provider , configClient config.Client , _ ... repository.Option ) (repository.Client , error ) {
749
+ repo := repository .NewMemoryRepository ().
750
+ WithPaths ("root" , "components.yaml" ).
751
+ WithDefaultVersion (config .CertManagerDefaultVersion ).
752
+ WithFile (config .CertManagerDefaultVersion , "components.yaml" , certManagerDeploymentYaml )
753
+ return repository .New (ctx , provider , configClient , repository .InjectRepository (repo ))
754
+ }
755
+
756
+ cm := newCertManagerClient (fakeConfigClient , fakeRepositoryClientFactory , proxy , pollImmediateWaiter )
722
757
723
758
actualPlan , err := cm .PlanUpgrade (ctx )
724
759
if tt .expectErr {
0 commit comments