From 16a61b6e1956039e08e3c5d28ac844ce140d09d3 Mon Sep 17 00:00:00 2001 From: Yuvaraj Kakaraparthi Date: Mon, 21 Feb 2022 14:52:02 -0800 Subject: [PATCH] [e2e] Checks unexpected rollouts during clusterctl upgrade --- test/e2e/clusterctl_upgrade.go | 45 ++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/test/e2e/clusterctl_upgrade.go b/test/e2e/clusterctl_upgrade.go index 5fb56dbfaa5b..e544d85d064f 100644 --- a/test/e2e/clusterctl_upgrade.go +++ b/test/e2e/clusterctl_upgrade.go @@ -292,6 +292,17 @@ func ClusterctlUpgradeSpec(ctx context.Context, inputGetter func() ClusterctlUpg input.PreUpgrade(managementClusterProxy) } + // Get the workloadCluster before the management cluster is upgraded to make sure that the upgrade did not trigger + // any unexpected rollouts. + preUpgradeMachineList := &clusterv1alpha3.MachineList{} + err = managementClusterProxy.GetClient().List( + ctx, + preUpgradeMachineList, + client.InNamespace(testNamespace.Name), + client.MatchingLabels{clusterv1.ClusterLabelName: workLoadClusterName}, + ) + Expect(err).NotTo(HaveOccurred()) + By("Upgrading providers to the latest version available") clusterctl.UpgradeManagementClusterAndWait(ctx, clusterctl.UpgradeManagementClusterAndWaitInput{ ClusterctlConfigPath: input.ClusterctlConfigPath, @@ -307,6 +318,19 @@ func ClusterctlUpgradeSpec(ctx context.Context, inputGetter func() ClusterctlUpg input.PostUpgrade(managementClusterProxy) } + // After the upgrade check that there were no unexpected rollouts. + Consistently(func() bool { + postUpgradeMachineList := &clusterv1.MachineList{} + err = managementClusterProxy.GetClient().List( + ctx, + postUpgradeMachineList, + client.InNamespace(testNamespace.Name), + client.MatchingLabels{clusterv1.ClusterLabelName: workLoadClusterName}, + ) + Expect(err).NotTo(HaveOccurred()) + return machinesMatch(preUpgradeMachineList, postUpgradeMachineList) + }, "3m", "30s").Should(BeTrue(), "Machines should remain the same after the upgrade") + // After upgrading we are sure the version is the latest version of the API, // so it is possible to use the standard helpers @@ -550,3 +574,24 @@ func waitForClusterDeletedV1alpha4(ctx context.Context, input waitForClusterDele return apierrors.IsNotFound(input.Getter.Get(ctx, key, cluster)) }, intervals...).Should(BeTrue()) } + +func machinesMatch(oldMachineList *clusterv1alpha3.MachineList, newMachineList *clusterv1.MachineList) bool { + if len(oldMachineList.Items) != len(newMachineList.Items) { + return false + } + + // Every machine from the old list should be present in the new list + for _, oldMachine := range oldMachineList.Items { + found := false + for _, newMachine := range newMachineList.Items { + if oldMachine.Name == newMachine.Name && oldMachine.Namespace == newMachine.Namespace { + found = true + break + } + } + if !found { + return false + } + } + return true +}