@@ -292,6 +292,17 @@ func ClusterctlUpgradeSpec(ctx context.Context, inputGetter func() ClusterctlUpg
292
292
input .PreUpgrade (managementClusterProxy )
293
293
}
294
294
295
+ // Get the workloadCluster before the management cluster is upgraded to make sure that the upgrade did not trigger
296
+ // any unexpected rollouts.
297
+ preUpgradeMachineList := & clusterv1alpha3.MachineList {}
298
+ err = managementClusterProxy .GetClient ().List (
299
+ ctx ,
300
+ preUpgradeMachineList ,
301
+ client .InNamespace (testNamespace .Name ),
302
+ client.MatchingLabels {clusterv1 .ClusterLabelName : workLoadClusterName },
303
+ )
304
+ Expect (err ).NotTo (HaveOccurred ())
305
+
295
306
By ("Upgrading providers to the latest version available" )
296
307
clusterctl .UpgradeManagementClusterAndWait (ctx , clusterctl.UpgradeManagementClusterAndWaitInput {
297
308
ClusterctlConfigPath : input .ClusterctlConfigPath ,
@@ -307,6 +318,19 @@ func ClusterctlUpgradeSpec(ctx context.Context, inputGetter func() ClusterctlUpg
307
318
input .PostUpgrade (managementClusterProxy )
308
319
}
309
320
321
+ // After the upgrade check that there were no unexpected rollouts.
322
+ Consistently (func () bool {
323
+ postUpgradeMachineList := & clusterv1.MachineList {}
324
+ err = managementClusterProxy .GetClient ().List (
325
+ ctx ,
326
+ postUpgradeMachineList ,
327
+ client .InNamespace (testNamespace .Name ),
328
+ client.MatchingLabels {clusterv1 .ClusterLabelName : workLoadClusterName },
329
+ )
330
+ Expect (err ).NotTo (HaveOccurred ())
331
+ return machinesMatch (preUpgradeMachineList , postUpgradeMachineList )
332
+ }, "3m" , "30s" ).Should (BeTrue (), "Machines should remain the same after the upgrade" )
333
+
310
334
// After upgrading we are sure the version is the latest version of the API,
311
335
// so it is possible to use the standard helpers
312
336
@@ -550,3 +574,24 @@ func waitForClusterDeletedV1alpha4(ctx context.Context, input waitForClusterDele
550
574
return apierrors .IsNotFound (input .Getter .Get (ctx , key , cluster ))
551
575
}, intervals ... ).Should (BeTrue ())
552
576
}
577
+
578
+ func machinesMatch (oldMachineList * clusterv1alpha3.MachineList , newMachineList * clusterv1.MachineList ) bool {
579
+ if len (oldMachineList .Items ) != len (newMachineList .Items ) {
580
+ return false
581
+ }
582
+
583
+ // Every machine from the old list should be present in the new list
584
+ for _ , oldMachine := range oldMachineList .Items {
585
+ found := false
586
+ for _ , newMachine := range newMachineList .Items {
587
+ if oldMachine .Name == newMachine .Name && oldMachine .Namespace == newMachine .Namespace {
588
+ found = true
589
+ break
590
+ }
591
+ }
592
+ if ! found {
593
+ return false
594
+ }
595
+ }
596
+ return true
597
+ }
0 commit comments