From ae0f0348ab26df47162630ce604a4de4c9f931ec Mon Sep 17 00:00:00 2001 From: Danil-Grigorev Date: Wed, 27 Nov 2024 11:23:42 +0100 Subject: [PATCH] Cover image substitution in e2e tests Signed-off-by: Danil-Grigorev --- internal/controllers/clusterctl/config.yaml | 2 ++ .../chart-upgrade/chart_upgrade_test.go | 33 +++++++++++++++++-- test/framework/turtles.go | 21 +++++++++++- 3 files changed, 53 insertions(+), 3 deletions(-) diff --git a/internal/controllers/clusterctl/config.yaml b/internal/controllers/clusterctl/config.yaml index 4ed93342..df2f9a7d 100644 --- a/internal/controllers/clusterctl/config.yaml +++ b/internal/controllers/clusterctl/config.yaml @@ -69,3 +69,5 @@ data: repository: "registry.suse.com/rancher" infrastructure-azure: repository: "registry.suse.com/rancher" + infrastructure-vsphere: + repository: "registry.suse.com/rancher" diff --git a/test/e2e/suites/chart-upgrade/chart_upgrade_test.go b/test/e2e/suites/chart-upgrade/chart_upgrade_test.go index b14a7625..b979f2bd 100644 --- a/test/e2e/suites/chart-upgrade/chart_upgrade_test.go +++ b/test/e2e/suites/chart-upgrade/chart_upgrade_test.go @@ -103,8 +103,13 @@ var _ = Describe("Chart upgrade functionality should work", Label(e2e.ShortTestL upgradeInput.PostUpgradeSteps = append(upgradeInput.PostUpgradeSteps, func() { framework.WaitForCAPIProviderRollout(ctx, framework.WaitForCAPIProviderRolloutInput{ - Getter: setupClusterResult.BootstrapClusterProxy.GetClient(), - Version: e2e.CAPIVersion, + Getter: setupClusterResult.BootstrapClusterProxy.GetClient(), + Version: e2e.CAPIVersion, + Deployment: &appsv1.Deployment{ObjectMeta: metav1.ObjectMeta{ + Name: "capi-controller-manager", + Namespace: "capi-system", + }}, + Image: "registry.suse.com/rancher/cluster-api-controller:", Name: "cluster-api", Namespace: "capi-system", }, e2eConfig.GetIntervals(setupClusterResult.BootstrapClusterProxy.GetName(), "wait-controllers")...) @@ -115,6 +120,30 @@ var _ = Describe("Chart upgrade functionality should work", Label(e2e.ShortTestL Name: "kubeadm-control-plane", Namespace: "capi-kubeadm-control-plane-system", }, e2eConfig.GetIntervals(setupClusterResult.BootstrapClusterProxy.GetName(), "wait-controllers")...) + }, func() { + framework.WaitForCAPIProviderRollout(ctx, framework.WaitForCAPIProviderRolloutInput{ + Getter: setupClusterResult.BootstrapClusterProxy.GetClient(), + Version: e2e.CAPIVersion, + Deployment: &appsv1.Deployment{ObjectMeta: metav1.ObjectMeta{ + Name: "rke2-bootstrap-controller-manager", + Namespace: "rke2-bootstrap-system", + }}, + Image: "registry.suse.com/rancher/cluster-api-provider-rke2-bootstrap:", + Name: "rke2-bootstrap", + Namespace: "rke2-bootstrap-system", + }, e2eConfig.GetIntervals(setupClusterResult.BootstrapClusterProxy.GetName(), "wait-controllers")...) + }, func() { + framework.WaitForCAPIProviderRollout(ctx, framework.WaitForCAPIProviderRolloutInput{ + Getter: setupClusterResult.BootstrapClusterProxy.GetClient(), + Version: e2e.CAPIVersion, + Deployment: &appsv1.Deployment{ObjectMeta: metav1.ObjectMeta{ + Name: "rke2-control-plane-controller-manager", + Namespace: "rke2-control-plane-system", + }}, + Image: "registry.suse.com/rancher/cluster-api-provider-rke2-controlplane:", + Name: "rke2-control-plane", + Namespace: "rke2-control-plane-system", + }, e2eConfig.GetIntervals(setupClusterResult.BootstrapClusterProxy.GetName(), "wait-controllers")...) }, func() { framework.WaitForCAPIProviderRollout(ctx, framework.WaitForCAPIProviderRolloutInput{ Getter: setupClusterResult.BootstrapClusterProxy.GetClient(), diff --git a/test/framework/turtles.go b/test/framework/turtles.go index 3ac6e4c9..cba15b7e 100644 --- a/test/framework/turtles.go +++ b/test/framework/turtles.go @@ -18,19 +18,23 @@ package framework import ( "context" + "strings" "k8s.io/apimachinery/pkg/types" "k8s.io/klog/v2" turtlesv1 "github.com/rancher/turtles/api/v1alpha1" + appsv1 "k8s.io/api/apps/v1" capiframework "sigs.k8s.io/cluster-api/test/framework" + "sigs.k8s.io/controller-runtime/pkg/client" . "github.com/onsi/gomega" ) type WaitForCAPIProviderRolloutInput struct { capiframework.Getter - Name, Namespace, Version string + Deployment *appsv1.Deployment + Name, Namespace, Version, Image string } func WaitForCAPIProviderRollout(ctx context.Context, input WaitForCAPIProviderRolloutInput, intervals ...interface{}) { @@ -49,4 +53,19 @@ func WaitForCAPIProviderRollout(ctx context.Context, input WaitForCAPIProviderRo }, intervals...).Should(Succeed(), "Failed to get CAPIProvider %s with version %s. Last observed: %s", key.String(), input.Version, klog.KObj(capiProvider)) + + if input.Deployment != nil && input.Version != "" { + Eventually(func(g Gomega) { + g.Expect(input.Getter.Get(ctx, client.ObjectKeyFromObject(input.Deployment), input.Deployment)).To(Succeed()) + found := false + for _, container := range input.Deployment.Spec.Template.Spec.Containers { + if strings.HasPrefix(container.Image, input.Image) { + found = true + } + } + g.Expect(found).To(BeTrue()) + }, intervals...).Should(Succeed(), + "Failed to get Deployemnt %s with image %s. Last observed: %s", + client.ObjectKeyFromObject(input.Deployment).String(), input.Image, klog.KObj(input.Deployment)) + } }