From 4afdbd17ebb9bfc9c72ba8e0f3b14dd82134fe14 Mon Sep 17 00:00:00 2001 From: mboukhalfa Date: Thu, 13 Oct 2022 10:49:12 +0300 Subject: [PATCH] Add custom upgrade option to e2e --- test/e2e/clusterctl_upgrade.go | 38 ++++++++++++--- test/framework/clusterctl/client.go | 48 +++++++++++++++---- .../clusterctl/clusterctl_helpers.go | 35 ++++++++++---- 3 files changed, 97 insertions(+), 24 deletions(-) diff --git a/test/e2e/clusterctl_upgrade.go b/test/e2e/clusterctl_upgrade.go index 8adc64106b9a..8baaa97026a3 100644 --- a/test/e2e/clusterctl_upgrade.go +++ b/test/e2e/clusterctl_upgrade.go @@ -81,6 +81,11 @@ type ClusterctlUpgradeSpecInput struct { MgmtFlavor string CNIManifestPath string WorkloadFlavor string + // Custom providers can be specified to upgrade to a pre-release or a custom version instead of upgrading to the latest using contact + CoreProvider string + BootstrapProviders []string + ControlPlaneProviders []string + InfrastructureProviders []string } // ClusterctlUpgradeSpec implements a test that verifies clusterctl upgrade of a management cluster. @@ -327,13 +332,32 @@ func ClusterctlUpgradeSpec(ctx context.Context, inputGetter func() ClusterctlUpg ) Expect(err).NotTo(HaveOccurred()) - By("Upgrading providers to the latest version available") - clusterctl.UpgradeManagementClusterAndWait(ctx, clusterctl.UpgradeManagementClusterAndWaitInput{ - ClusterctlConfigPath: input.ClusterctlConfigPath, - ClusterProxy: managementClusterProxy, - Contract: clusterv1.GroupVersion.Version, - LogFolder: filepath.Join(input.ArtifactFolder, "clusters", cluster.Name), - }, input.E2EConfig.GetIntervals(specName, "wait-controllers")...) + // Check if the user want a custom upgrade + isCustomUpgrade := input.CoreProvider != "" || + len(input.BootstrapProviders) > 0 || + len(input.ControlPlaneProviders) > 0 || + len(input.InfrastructureProviders) > 0 + + if isCustomUpgrade { + By("Upgrading providers to custom versions") + clusterctl.UpgradeManagementClusterAndWait(ctx, clusterctl.UpgradeManagementClusterAndWaitInput{ + ClusterctlConfigPath: input.ClusterctlConfigPath, + ClusterProxy: managementClusterProxy, + CoreProvider: input.CoreProvider, + BootstrapProviders: input.BootstrapProviders, + ControlPlaneProviders: input.ControlPlaneProviders, + InfrastructureProviders: input.InfrastructureProviders, + LogFolder: filepath.Join(input.ArtifactFolder, "clusters", cluster.Name), + }, input.E2EConfig.GetIntervals(specName, "wait-controllers")...) + } else { + By("Upgrading providers to the latest version available") + clusterctl.UpgradeManagementClusterAndWait(ctx, clusterctl.UpgradeManagementClusterAndWaitInput{ + ClusterctlConfigPath: input.ClusterctlConfigPath, + ClusterProxy: managementClusterProxy, + Contract: clusterv1.GroupVersion.Version, + LogFolder: filepath.Join(input.ArtifactFolder, "clusters", cluster.Name), + }, input.E2EConfig.GetIntervals(specName, "wait-controllers")...) + } By("THE MANAGEMENT CLUSTER WAS SUCCESSFULLY UPGRADED!") diff --git a/test/framework/clusterctl/client.go b/test/framework/clusterctl/client.go index 187d30939c05..3341e61579ff 100644 --- a/test/framework/clusterctl/client.go +++ b/test/framework/clusterctl/client.go @@ -115,24 +115,56 @@ func InitWithBinary(_ context.Context, binary string, input InitInput) { // UpgradeInput is the input for Upgrade. type UpgradeInput struct { - LogFolder string - ClusterctlConfigPath string - KubeconfigPath string - Contract string + LogFolder string + ClusterctlConfigPath string + ClusterName string + KubeconfigPath string + Contract string + CoreProvider string + BootstrapProviders []string + ControlPlaneProviders []string + InfrastructureProviders []string } // Upgrade calls clusterctl upgrade apply with the list of providers defined in the local repository. func Upgrade(ctx context.Context, input UpgradeInput) { - log.Logf("clusterctl upgrade apply --contract %s", - input.Contract, - ) + // Check if the user want a custom upgrade + isCustomUpgrade := input.CoreProvider != "" || + len(input.BootstrapProviders) > 0 || + len(input.ControlPlaneProviders) > 0 || + len(input.InfrastructureProviders) > 0 + + Expect((input.Contract != "" && !isCustomUpgrade) || (input.Contract == "" && isCustomUpgrade)).To(BeTrue(), `Invalid arguments. Either the input.Contract parameter or at least one of the following providers has to be set: + input.CoreProvider, input.BootstrapProviders, input.ControlPlaneProviders, input.InfrastructureProviders, input.IPAMProviders, input.RuntimeExtensionProviders`) + + if isCustomUpgrade { + log.Logf("clusterctl upgrade apply --core %s --bootstrap %s --control-plane %s --infrastructure %s --config %s --kubeconfig %s", + input.CoreProvider, + strings.Join(input.BootstrapProviders, ","), + strings.Join(input.ControlPlaneProviders, ","), + strings.Join(input.InfrastructureProviders, ","), + input.ClusterctlConfigPath, + input.KubeconfigPath, + ) + } else { + log.Logf("clusterctl upgrade apply --contract %s --config %s --kubeconfig %s", + input.Contract, + input.ClusterctlConfigPath, + input.KubeconfigPath, + ) + } upgradeOpt := clusterctlclient.ApplyUpgradeOptions{ Kubeconfig: clusterctlclient.Kubeconfig{ Path: input.KubeconfigPath, Context: "", }, - Contract: input.Contract, + Contract: input.Contract, + CoreProvider: input.CoreProvider, + BootstrapProviders: input.BootstrapProviders, + ControlPlaneProviders: input.ControlPlaneProviders, + InfrastructureProviders: input.InfrastructureProviders, + WaitProviders: true, } clusterctlClient, log := getClusterctlClientWithLogger(input.ClusterctlConfigPath, "clusterctl-upgrade.log", input.LogFolder) diff --git a/test/framework/clusterctl/clusterctl_helpers.go b/test/framework/clusterctl/clusterctl_helpers.go index 6f0579c9b4be..1a2ae254b676 100644 --- a/test/framework/clusterctl/clusterctl_helpers.go +++ b/test/framework/clusterctl/clusterctl_helpers.go @@ -123,10 +123,14 @@ func InitManagementClusterAndWatchControllerLogs(ctx context.Context, input Init // UpgradeManagementClusterAndWaitInput is the input type for UpgradeManagementClusterAndWait. type UpgradeManagementClusterAndWaitInput struct { - ClusterProxy framework.ClusterProxy - ClusterctlConfigPath string - Contract string - LogFolder string + ClusterProxy framework.ClusterProxy + ClusterctlConfigPath string + Contract string + CoreProvider string + BootstrapProviders []string + ControlPlaneProviders []string + InfrastructureProviders []string + LogFolder string } // UpgradeManagementClusterAndWait upgrades provider a management cluster using clusterctl, and waits for the cluster to be ready. @@ -134,14 +138,27 @@ func UpgradeManagementClusterAndWait(ctx context.Context, input UpgradeManagemen Expect(ctx).NotTo(BeNil(), "ctx is required for UpgradeManagementClusterAndWait") Expect(input.ClusterProxy).ToNot(BeNil(), "Invalid argument. input.ClusterProxy can't be nil when calling UpgradeManagementClusterAndWait") Expect(input.ClusterctlConfigPath).To(BeAnExistingFile(), "Invalid argument. input.ClusterctlConfigPath must be an existing file when calling UpgradeManagementClusterAndWait") - Expect(input.Contract).ToNot(BeEmpty(), "Invalid argument. input.Contract can't be empty when calling UpgradeManagementClusterAndWait") + // Check if the user want a custom upgrade + isCustomUpgrade := input.CoreProvider != "" || + len(input.BootstrapProviders) > 0 || + len(input.ControlPlaneProviders) > 0 || + len(input.InfrastructureProviders) > 0 + + Expect((input.Contract != "" && !isCustomUpgrade) || (input.Contract == "" && isCustomUpgrade)).To(BeTrue(), `Invalid argument. Either the input.Contract parameter or at least one of the following providers has to be set: + input.CoreProvider, input.BootstrapProviders, input.ControlPlaneProviders, input.InfrastructureProviders, input.IPAMProviders, input.RuntimeExtensionProviders`) + Expect(os.MkdirAll(input.LogFolder, 0750)).To(Succeed(), "Invalid argument. input.LogFolder can't be created for UpgradeManagementClusterAndWait") Upgrade(ctx, UpgradeInput{ - ClusterctlConfigPath: input.ClusterctlConfigPath, - KubeconfigPath: input.ClusterProxy.GetKubeconfigPath(), - Contract: input.Contract, - LogFolder: input.LogFolder, + ClusterctlConfigPath: input.ClusterctlConfigPath, + ClusterName: input.ClusterProxy.GetName(), + KubeconfigPath: input.ClusterProxy.GetKubeconfigPath(), + Contract: input.Contract, + CoreProvider: input.CoreProvider, + BootstrapProviders: input.BootstrapProviders, + ControlPlaneProviders: input.ControlPlaneProviders, + InfrastructureProviders: input.InfrastructureProviders, + LogFolder: input.LogFolder, }) client := input.ClusterProxy.GetClient()