Skip to content

Commit 2466594

Browse files
authored
Merge pull request #6184 from ykakarap/e2e-detect-rollout
🌱 [e2e] Checks unexpected rollouts during clusterctl upgrade
2 parents 6d672ea + 2a84de8 commit 2466594

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

test/e2e/clusterctl_upgrade.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,17 @@ func ClusterctlUpgradeSpec(ctx context.Context, inputGetter func() ClusterctlUpg
292292
input.PreUpgrade(managementClusterProxy)
293293
}
294294

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+
295306
By("Upgrading providers to the latest version available")
296307
clusterctl.UpgradeManagementClusterAndWait(ctx, clusterctl.UpgradeManagementClusterAndWaitInput{
297308
ClusterctlConfigPath: input.ClusterctlConfigPath,
@@ -307,6 +318,19 @@ func ClusterctlUpgradeSpec(ctx context.Context, inputGetter func() ClusterctlUpg
307318
input.PostUpgrade(managementClusterProxy)
308319
}
309320

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+
310334
// After upgrading we are sure the version is the latest version of the API,
311335
// so it is possible to use the standard helpers
312336

@@ -550,3 +574,24 @@ func waitForClusterDeletedV1alpha4(ctx context.Context, input waitForClusterDele
550574
return apierrors.IsNotFound(input.Getter.Get(ctx, key, cluster))
551575
}, intervals...).Should(BeTrue())
552576
}
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

Comments
 (0)