From 3037432b5f809330936c47d2b05add30955f0a84 Mon Sep 17 00:00:00 2001 From: Danil-Grigorev Date: Wed, 11 Sep 2024 18:24:33 +0200 Subject: [PATCH] Fix: e2e failures in CI due to metrics collection Signed-off-by: Danil-Grigorev --- test/e2e/common.go | 60 ++++++++++++++++++++++++++++++++++++ test/e2e/e2e_upgrade_test.go | 2 +- 2 files changed, 61 insertions(+), 1 deletion(-) diff --git a/test/e2e/common.go b/test/e2e/common.go index 8de682b9..7afc7fd6 100644 --- a/test/e2e/common.go +++ b/test/e2e/common.go @@ -35,6 +35,7 @@ import ( "sigs.k8s.io/cluster-api/test/framework" "sigs.k8s.io/cluster-api/test/framework/clusterctl" "sigs.k8s.io/cluster-api/util" + "sigs.k8s.io/controller-runtime/pkg/log" "sigs.k8s.io/yaml" ) @@ -191,3 +192,62 @@ func localLoadE2EConfig(configPath string) *clusterctl.E2EConfig { return config } + +// UpgradeManagementClusterAndWait upgrades provider a management cluster using clusterctl, and waits for the cluster to be ready. +func UpgradeManagementClusterAndWait(ctx context.Context, input clusterctl.UpgradeManagementClusterAndWaitInput, intervals ...interface{}) { + 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") + + log := log.FromContext(ctx) + + // Check if the user want a custom upgrade + isCustomUpgrade := input.CoreProvider != "" || + len(input.BootstrapProviders) > 0 || + len(input.ControlPlaneProviders) > 0 || + len(input.InfrastructureProviders) > 0 || + len(input.IPAMProviders) > 0 || + len(input.RuntimeExtensionProviders) > 0 || + len(input.AddonProviders) > 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, input.AddonProviders`) + + Expect(os.MkdirAll(input.LogFolder, 0750)).To(Succeed(), "Invalid argument. input.LogFolder can't be created for UpgradeManagementClusterAndWait") + + upgradeInput := clusterctl.UpgradeInput{ + ClusterctlConfigPath: input.ClusterctlConfigPath, + ClusterctlVariables: input.ClusterctlVariables, + ClusterName: input.ClusterProxy.GetName(), + KubeconfigPath: input.ClusterProxy.GetKubeconfigPath(), + Contract: input.Contract, + CoreProvider: input.CoreProvider, + BootstrapProviders: input.BootstrapProviders, + ControlPlaneProviders: input.ControlPlaneProviders, + InfrastructureProviders: input.InfrastructureProviders, + IPAMProviders: input.IPAMProviders, + RuntimeExtensionProviders: input.RuntimeExtensionProviders, + AddonProviders: input.AddonProviders, + LogFolder: input.LogFolder, + } + + client := input.ClusterProxy.GetClient() + + clusterctl.Upgrade(ctx, upgradeInput) + + log.Info("Waiting for provider controllers to be running") + + controllersDeployments := framework.GetControllerDeployments(ctx, framework.GetControllerDeploymentsInput{ + Lister: client, + }) + + Expect(controllersDeployments).ToNot(BeEmpty(), "The list of controller deployments should not be empty") + + // We have to skip collecting metrics, as it causes failures in CI + for _, deployment := range controllersDeployments { + framework.WaitForDeploymentsAvailable(ctx, framework.WaitForDeploymentsAvailableInput{ + Getter: client, + Deployment: deployment, + }, intervals...) + } +} diff --git a/test/e2e/e2e_upgrade_test.go b/test/e2e/e2e_upgrade_test.go index 77594396..03ec8809 100644 --- a/test/e2e/e2e_upgrade_test.go +++ b/test/e2e/e2e_upgrade_test.go @@ -115,7 +115,7 @@ var _ = Describe("Workload cluster creation", func() { }, e2eConfig.GetIntervals(specName, "wait-control-plane")...) By("Upgrading to latest boostrap/controlplane provider version") - clusterctl.UpgradeManagementClusterAndWait(ctx, clusterctl.UpgradeManagementClusterAndWaitInput{ + UpgradeManagementClusterAndWait(ctx, clusterctl.UpgradeManagementClusterAndWaitInput{ ClusterProxy: bootstrapClusterProxy, ClusterctlConfigPath: clusterctlConfigPath, BootstrapProviders: []string{"rke2-bootstrap:v0.7.99"},