From 908dcd24b693b0e1da4312c61b1bda44810e199d Mon Sep 17 00:00:00 2001 From: Furkat Gofurov Date: Wed, 7 Aug 2024 11:40:55 +0300 Subject: [PATCH] Remove legacy tests and related code Signed-off-by: Furkat Gofurov (cherry picked from commit bc00f06ef2840a7be8c8cfe5cd1b654536a9068f) --- test/e2e/config/e2e_conf.yaml | 49 ----- .../cluster-template-docker-legacy.yaml | 171 ------------------ .../cluster-template-docker.yaml | 2 +- test/e2e/e2e_suite_test.go | 13 +- test/e2e/e2e_upgrade_test.go | 67 ++----- test/e2e/helpers.go | 143 +-------------- 6 files changed, 38 insertions(+), 407 deletions(-) delete mode 100644 test/e2e/data/infrastructure/cluster-template-docker-legacy.yaml diff --git a/test/e2e/config/e2e_conf.yaml b/test/e2e/config/e2e_conf.yaml index 043cecbb..d19cdfec 100644 --- a/test/e2e/config/e2e_conf.yaml +++ b/test/e2e/config/e2e_conf.yaml @@ -40,7 +40,6 @@ providers: contract: v1beta1 files: - sourcePath: "../data/infrastructure/cluster-template-docker.yaml" - - sourcePath: "../data/infrastructure/cluster-template-docker-legacy.yaml" - sourcePath: "../data/shared/v1beta1/metadata.yaml" replacements: - old: "imagePullPolicy: Always" @@ -52,30 +51,6 @@ providers: - name: rke2-control-plane type: ControlPlaneProvider versions: - - name: "v0.2.7" - value: "https://github.com/rancher/cluster-api-provider-rke2/releases/download/v0.2.7/control-plane-components.yaml" - type: "url" - contract: v1beta1 - files: - - sourcePath: "../../../metadata.yaml" - targetName: "metadata.yaml" - replacements: - - old: "imagePullPolicy: Always" - new: "imagePullPolicy: IfNotPresent" - - old: "--leader-elect" - new: "--leader-elect=false" - - name: "v0.3.0" - value: "https://github.com/rancher/cluster-api-provider-rke2/releases/download/v0.3.0/control-plane-components.yaml" - type: "url" - contract: v1beta1 - files: - - sourcePath: "../../../metadata.yaml" - targetName: "metadata.yaml" - replacements: - - old: "imagePullPolicy: Always" - new: "imagePullPolicy: IfNotPresent" - - old: "--leader-elect" - new: "--leader-elect=false" - name: "v0.4.0" value: "https://github.com/rancher/cluster-api-provider-rke2/releases/download/v0.4.0/control-plane-components.yaml" type: "url" @@ -114,30 +89,6 @@ providers: - name: rke2-bootstrap type: BootstrapProvider versions: - - name: "v0.2.7" - value: "https://github.com/rancher/cluster-api-provider-rke2/releases/download/v0.2.7/bootstrap-components.yaml" - type: "url" - contract: v1beta1 - files: - - sourcePath: "../../../metadata.yaml" - targetName: "metadata.yaml" - replacements: - - old: "imagePullPolicy: Always" - new: "imagePullPolicy: IfNotPresent" - - old: "--leader-elect" - new: "--leader-elect=false" - - name: "v0.3.0" - value: "https://github.com/rancher/cluster-api-provider-rke2/releases/download/v0.3.0/bootstrap-components.yaml" - type: "url" - contract: v1beta1 - files: - - sourcePath: "../../../metadata.yaml" - targetName: "metadata.yaml" - replacements: - - old: "imagePullPolicy: Always" - new: "imagePullPolicy: IfNotPresent" - - old: "--leader-elect" - new: "--leader-elect=false" - name: "v0.4.0" value: "https://github.com/rancher/cluster-api-provider-rke2/releases/download/v0.4.0/bootstrap-components.yaml" type: "url" diff --git a/test/e2e/data/infrastructure/cluster-template-docker-legacy.yaml b/test/e2e/data/infrastructure/cluster-template-docker-legacy.yaml deleted file mode 100644 index 65fcd2de..00000000 --- a/test/e2e/data/infrastructure/cluster-template-docker-legacy.yaml +++ /dev/null @@ -1,171 +0,0 @@ -apiVersion: v1 -data: - value: |- - # generated by kind - global - log /dev/log local0 - log /dev/log local1 notice - daemon - # limit memory usage to approximately 18 MB - # (see https://github.com/kubernetes-sigs/kind/pull/3115) - maxconn 100000 - - resolvers docker - nameserver dns 127.0.0.11:53 - - defaults - log global - mode tcp - option dontlognull - # TODO: tune these - timeout connect 5000 - timeout client 50000 - timeout server 50000 - # allow to boot despite dns don't resolve backends - default-server init-addr none - - frontend stats - bind *:8404 - stats enable - stats uri / - stats refresh 10s - - frontend control-plane - bind *:{{ .FrontendControlPlanePort }} - {{ if .IPv6 -}} - bind :::{{ .FrontendControlPlanePort }}; - {{- end }} - default_backend kube-apiservers - - backend kube-apiservers - option httpchk GET /healthz - http-check expect status 401 - # TODO: we should be verifying (!) - {{range $server, $address := .BackendServers}} - server {{ $server }} {{ JoinHostPort $address $.BackendControlPlanePort }} check check-ssl verify none resolvers docker resolve-prefer {{ if $.IPv6 -}} ipv6 {{- else -}} ipv4 {{- end }} - {{- end}} - - frontend rke2-join - bind *:9345 - {{ if .IPv6 -}} - bind :::9345; - {{- end }} - default_backend rke2-servers - - backend rke2-servers - option httpchk GET /v1-rke2/readyz - http-check expect status 403 - {{range $server, $address := .BackendServers}} - server {{ $server }} {{ $address }}:9345 check check-ssl verify none - {{- end}} -kind: ConfigMap -metadata: - name: ${CLUSTER_NAME}-lb-config ---- -apiVersion: cluster.x-k8s.io/v1beta1 -kind: Cluster -metadata: - name: ${CLUSTER_NAME} -spec: - clusterNetwork: - pods: - cidrBlocks: - - 10.45.0.0/16 - services: - cidrBlocks: - - 10.46.0.0/16 - serviceDomain: cluster.local - controlPlaneRef: - apiVersion: controlplane.cluster.x-k8s.io/v1alpha1 - kind: RKE2ControlPlane - name: ${CLUSTER_NAME}-control-plane - infrastructureRef: - apiVersion: infrastructure.cluster.x-k8s.io/v1beta1 - kind: DockerCluster - name: ${CLUSTER_NAME} ---- -apiVersion: infrastructure.cluster.x-k8s.io/v1beta1 -kind: DockerCluster -metadata: - name: ${CLUSTER_NAME} -spec: - loadBalancer: - customHAProxyConfigTemplateRef: - name: ${CLUSTER_NAME}-lb-config ---- -apiVersion: controlplane.cluster.x-k8s.io/v1alpha1 -kind: RKE2ControlPlane -metadata: - name: ${CLUSTER_NAME}-control-plane -spec: - replicas: ${CONTROL_PLANE_MACHINE_COUNT} - agentConfig: - version: ${KUBERNETES_VERSION}+rke2r1 - nodeAnnotations: - test: "true" - serverConfig: - disableComponents: - kubernetesComponents: - - cloudController - infrastructureRef: - apiVersion: infrastructure.cluster.x-k8s.io/v1beta1 - kind: DockerMachineTemplate - name: "${CLUSTER_NAME}-control-plane" - nodeDrainTimeout: 30s ---- -apiVersion: infrastructure.cluster.x-k8s.io/v1beta1 -kind: DockerMachineTemplate -metadata: - name: "${CLUSTER_NAME}-control-plane" -spec: - template: - spec: - customImage: kindest/node:${KIND_IMAGE_VERSION} - bootstrapTimeout: 15m ---- -apiVersion: cluster.x-k8s.io/v1beta1 -kind: MachineDeployment -metadata: - name: ${CLUSTER_NAME}-md-0 -spec: - clusterName: ${CLUSTER_NAME} - replicas: ${WORKER_MACHINE_COUNT} - selector: - matchLabels: - cluster.x-k8s.io/cluster-name: ${CLUSTER_NAME} - template: - spec: - version: ${KUBERNETES_VERSION}+rke2r1 - clusterName: ${CLUSTER_NAME} - bootstrap: - configRef: - apiVersion: bootstrap.cluster.x-k8s.io/v1alpha1 - kind: RKE2ConfigTemplate - name: ${CLUSTER_NAME}-md-0 - infrastructureRef: - apiVersion: infrastructure.cluster.x-k8s.io/v1beta1 - kind: DockerMachineTemplate - name: ${CLUSTER_NAME}-md-0 ---- -apiVersion: infrastructure.cluster.x-k8s.io/v1beta1 -kind: DockerMachineTemplate -metadata: - name: ${CLUSTER_NAME}-md-0 -spec: - template: - spec: - customImage: kindest/node:${KIND_IMAGE_VERSION} - bootstrapTimeout: 15m ---- -apiVersion: bootstrap.cluster.x-k8s.io/v1alpha1 -kind: RKE2ConfigTemplate -metadata: - name: ${CLUSTER_NAME}-md-0 -spec: - template: - spec: - agentConfig: - version: ${KUBERNETES_VERSION}+rke2r1 - nodeAnnotations: - test: "true" - diff --git a/test/e2e/data/infrastructure/cluster-template-docker.yaml b/test/e2e/data/infrastructure/cluster-template-docker.yaml index f185e3a4..2545c916 100644 --- a/test/e2e/data/infrastructure/cluster-template-docker.yaml +++ b/test/e2e/data/infrastructure/cluster-template-docker.yaml @@ -100,7 +100,7 @@ metadata: spec: replicas: ${CONTROL_PLANE_MACHINE_COUNT} version: ${KUBERNETES_VERSION}+rke2r1 - registrationMethod: internal-first + registrationMethod: control-plane-endpoint rolloutStrategy: type: "RollingUpdate" rollingUpdate: diff --git a/test/e2e/e2e_suite_test.go b/test/e2e/e2e_suite_test.go index aea0c9b9..8da871c6 100644 --- a/test/e2e/e2e_suite_test.go +++ b/test/e2e/e2e_suite_test.go @@ -234,6 +234,7 @@ func setupBootstrapCluster(config *clusterctl.E2EConfig, scheme *runtime.Scheme, return clusterProvider, clusterProxy } +// initBootstrapCluster initializes a bootstrap cluster with the latest minor version. func initBootstrapCluster(bootstrapClusterProxy framework.ClusterProxy, config *clusterctl.E2EConfig, clusterctlConfig, artifactFolder string) { clusterctl.InitManagementClusterAndWatchControllerLogs(context.TODO(), clusterctl.InitManagementClusterAndWatchControllerLogsInput{ ClusterProxy: bootstrapClusterProxy, @@ -241,21 +242,23 @@ func initBootstrapCluster(bootstrapClusterProxy framework.ClusterProxy, config * InfrastructureProviders: config.InfrastructureProviders(), IPAMProviders: config.IPAMProviders(), RuntimeExtensionProviders: config.RuntimeExtensionProviders(), - BootstrapProviders: []string{"rke2-bootstrap:v0.5.0"}, - ControlPlaneProviders: []string{"rke2-control-plane:v0.5.0"}, + BootstrapProviders: []string{"rke2-bootstrap"}, + ControlPlaneProviders: []string{"rke2-control-plane"}, LogFolder: filepath.Join(artifactFolder, "clusters", bootstrapClusterProxy.GetName()), }, config.GetIntervals(bootstrapClusterProxy.GetName(), "wait-controllers")...) } -func initLegacyBootstrapCluster(bootstrapClusterProxy framework.ClusterProxy, config *clusterctl.E2EConfig, clusterctlConfig, artifactFolder string) { +// initUpgradableBootstrapCluster initializes a bootstrap cluster with the latest minor version N-1 and used to perform an upgrade to the latest version. +// Make sure to update the version in the providers list to the latest minor version N-1. +func initUpgradableBootstrapCluster(bootstrapClusterProxy framework.ClusterProxy, config *clusterctl.E2EConfig, clusterctlConfig, artifactFolder string) { clusterctl.InitManagementClusterAndWatchControllerLogs(context.TODO(), clusterctl.InitManagementClusterAndWatchControllerLogsInput{ ClusterProxy: bootstrapClusterProxy, ClusterctlConfigPath: clusterctlConfig, InfrastructureProviders: config.InfrastructureProviders(), IPAMProviders: config.IPAMProviders(), RuntimeExtensionProviders: config.RuntimeExtensionProviders(), - BootstrapProviders: []string{"rke2-bootstrap:v0.2.7"}, - ControlPlaneProviders: []string{"rke2-control-plane:v0.2.7"}, + BootstrapProviders: []string{"rke2-bootstrap:v0.4.0"}, + ControlPlaneProviders: []string{"rke2-control-plane:v0.4.0"}, LogFolder: filepath.Join(artifactFolder, "clusters", bootstrapClusterProxy.GetName()), }, config.GetIntervals(bootstrapClusterProxy.GetName(), "wait-controllers")...) } diff --git a/test/e2e/e2e_upgrade_test.go b/test/e2e/e2e_upgrade_test.go index 5a7bd22e..f6d38edc 100644 --- a/test/e2e/e2e_upgrade_test.go +++ b/test/e2e/e2e_upgrade_test.go @@ -85,20 +85,19 @@ var _ = Describe("Workload cluster creation", func() { }) Context("Creating a single control-plane cluster", func() { - It("Should create a cluster with legacy version and perform upgrade to the v0.3.0 version", func() { - By("Installing legacy version") - initLegacyBootstrapCluster(bootstrapClusterProxy, e2eConfig, clusterctlConfigPath, artifactFolder) + It("Should create a cluster with v0.4.0 and perform upgrade to latest version", func() { + By("Installing v0.4.0 boostrap/controlplane provider version") + initUpgradableBootstrapCluster(bootstrapClusterProxy, e2eConfig, clusterctlConfigPath, artifactFolder) By("Initializing the cluster") ApplyClusterTemplateAndWait(ctx, ApplyClusterTemplateAndWaitInput{ - Legacy: true, ClusterProxy: bootstrapClusterProxy, ConfigCluster: clusterctl.ConfigClusterInput{ LogFolder: clusterctlLogFolder, ClusterctlConfigPath: clusterctlConfigPath, KubeconfigPath: bootstrapClusterProxy.GetKubeconfigPath(), InfrastructureProvider: "docker", - Flavor: "docker-legacy", + Flavor: "docker", Namespace: namespace.Name, ClusterName: clusterName, KubernetesVersion: e2eConfig.GetVariable(KubernetesVersion), @@ -110,32 +109,34 @@ var _ = Describe("Workload cluster creation", func() { WaitForMachineDeployments: e2eConfig.GetIntervals(specName, "wait-worker-nodes"), }, result) - WaitForLegacyControlPlaneToBeReady(ctx, WaitForControlPlaneToBeReadyInput{ + WaitForControlPlaneToBeReady(ctx, WaitForControlPlaneToBeReadyInput{ Getter: bootstrapClusterProxy.GetClient(), - ControlPlane: client.ObjectKeyFromObject(result.LegacyControlPlane), + ControlPlane: client.ObjectKeyFromObject(result.ControlPlane), }, e2eConfig.GetIntervals(specName, "wait-control-plane")...) - By("Upgrading to v0.3.0 boostrap/controlplane provider version") + By("Upgrading to latest boostrap/controlplane provider version") clusterctl.UpgradeManagementClusterAndWait(ctx, clusterctl.UpgradeManagementClusterAndWaitInput{ ClusterProxy: bootstrapClusterProxy, ClusterctlConfigPath: clusterctlConfigPath, - BootstrapProviders: []string{"rke2-bootstrap:v0.3.0"}, - ControlPlaneProviders: []string{"rke2-control-plane:v0.3.0"}, + BootstrapProviders: []string{"rke2-bootstrap:v0.5.99"}, + ControlPlaneProviders: []string{"rke2-control-plane:v0.5.99"}, LogFolder: clusterctlLogFolder, }, e2eConfig.GetIntervals(specName, "wait-controllers")...) - // At this point provider does not have an etcd secret, as a new node was never rolled out - // and the cluster was created in the old version. Should still be possible to do. - By("Scaling down control plane to 2 and workers up to 2 using v1apha1") + WaitForControlPlaneToBeReady(ctx, WaitForControlPlaneToBeReadyInput{ + Getter: bootstrapClusterProxy.GetClient(), + ControlPlane: client.ObjectKeyFromObject(result.ControlPlane), + }, e2eConfig.GetIntervals(specName, "wait-control-plane")...) + + By("Scaling down control plane to 2 and workers up to 2") ApplyClusterTemplateAndWait(ctx, ApplyClusterTemplateAndWaitInput{ - Legacy: true, ClusterProxy: bootstrapClusterProxy, ConfigCluster: clusterctl.ConfigClusterInput{ LogFolder: clusterctlLogFolder, ClusterctlConfigPath: clusterctlConfigPath, KubeconfigPath: bootstrapClusterProxy.GetKubeconfigPath(), InfrastructureProvider: "docker", - Flavor: "docker-legacy", + Flavor: "docker", Namespace: namespace.Name, ClusterName: clusterName, KubernetesVersion: e2eConfig.GetVariable(KubernetesVersion), @@ -147,15 +148,12 @@ var _ = Describe("Workload cluster creation", func() { WaitForMachineDeployments: e2eConfig.GetIntervals(specName, "wait-worker-nodes"), }, result) - WaitForLegacyControlPlaneToBeReady(ctx, WaitForControlPlaneToBeReadyInput{ + WaitForControlPlaneToBeReady(ctx, WaitForControlPlaneToBeReadyInput{ Getter: bootstrapClusterProxy.GetClient(), - ControlPlane: client.ObjectKeyFromObject(result.LegacyControlPlane), + ControlPlane: client.ObjectKeyFromObject(result.ControlPlane), }, e2eConfig.GetIntervals(specName, "wait-control-plane")...) - // Possible only with valid etcd certificate in the secret - // Created machine is a scale up, so the secret will be populated for the - // remaning 2 machines to scale down to 1 later - By("Upgrading control plane and worker machines using v1beta1") + By("Scale down control plane and workers to 1 with kubernetes version upgrade") ApplyClusterTemplateAndWait(ctx, ApplyClusterTemplateAndWaitInput{ ClusterProxy: bootstrapClusterProxy, ConfigCluster: clusterctl.ConfigClusterInput{ @@ -167,7 +165,7 @@ var _ = Describe("Workload cluster creation", func() { Namespace: namespace.Name, ClusterName: clusterName, KubernetesVersion: e2eConfig.GetVariable(KubernetesVersionUpgradeTo), - ControlPlaneMachineCount: ptr.To(int64(2)), + ControlPlaneMachineCount: ptr.To(int64(1)), WorkerMachineCount: ptr.To(int64(1)), }, WaitForClusterIntervals: e2eConfig.GetIntervals(specName, "wait-cluster"), @@ -186,31 +184,6 @@ var _ = Describe("Workload cluster creation", func() { Getter: bootstrapClusterProxy.GetClient(), ControlPlane: client.ObjectKeyFromObject(result.ControlPlane), }, e2eConfig.GetIntervals(specName, "wait-control-plane")...) - - By("Scale down CP and workers to 1") - ApplyClusterTemplateAndWait(ctx, ApplyClusterTemplateAndWaitInput{ - ClusterProxy: bootstrapClusterProxy, - ConfigCluster: clusterctl.ConfigClusterInput{ - LogFolder: clusterctlLogFolder, - ClusterctlConfigPath: clusterctlConfigPath, - KubeconfigPath: bootstrapClusterProxy.GetKubeconfigPath(), - InfrastructureProvider: "docker", - Flavor: "docker", - Namespace: namespace.Name, - ClusterName: clusterName, - KubernetesVersion: e2eConfig.GetVariable(KubernetesVersionUpgradeTo), - ControlPlaneMachineCount: ptr.To(int64(1)), - WorkerMachineCount: ptr.To(int64(1)), - }, - WaitForClusterIntervals: e2eConfig.GetIntervals(specName, "wait-cluster"), - WaitForControlPlaneIntervals: e2eConfig.GetIntervals(specName, "wait-control-plane"), - WaitForMachineDeployments: e2eConfig.GetIntervals(specName, "wait-worker-nodes"), - }, result) - - WaitForControlPlaneToBeReady(ctx, WaitForControlPlaneToBeReadyInput{ - Getter: bootstrapClusterProxy.GetClient(), - ControlPlane: client.ObjectKeyFromObject(result.ControlPlane), - }, e2eConfig.GetIntervals(specName, "wait-control-plane")...) }) }) }) diff --git a/test/e2e/helpers.go b/test/e2e/helpers.go index 3f48e364..03b62d9f 100644 --- a/test/e2e/helpers.go +++ b/test/e2e/helpers.go @@ -29,11 +29,9 @@ import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" "github.com/pkg/errors" - v1 "k8s.io/api/apps/v1" "k8s.io/apimachinery/pkg/types" "k8s.io/klog/v2" - controlplanev1alpha1 "github.com/rancher/cluster-api-provider-rke2/controlplane/api/v1alpha1" controlplanev1 "github.com/rancher/cluster-api-provider-rke2/controlplane/api/v1beta1" bsutil "github.com/rancher/cluster-api-provider-rke2/pkg/util" clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" @@ -60,7 +58,6 @@ type ApplyClusterTemplateAndWaitInput struct { WaitForControlPlaneIntervals []interface{} WaitForMachineDeployments []interface{} Args []string // extra args to be used during `kubectl apply` - Legacy bool // using v1alpha1 crds version or not PreWaitForCluster func() PostMachinesProvisioned func() WaitForControlPlaneInitialized Waiter @@ -74,7 +71,6 @@ type ApplyClusterTemplateAndWaitResult struct { ClusterClass *clusterv1.ClusterClass Cluster *clusterv1.Cluster ControlPlane *controlplanev1.RKE2ControlPlane - LegacyControlPlane *controlplanev1alpha1.RKE2ControlPlane MachineDeployments []*clusterv1.MachineDeployment } @@ -182,38 +178,6 @@ func DiscoveryAndWaitForMachineDeployments(ctx context.Context, input framework. return machineDeployments } -func SetControllerVersionAndWait(ctx context.Context, proxy framework.ClusterProxy, version string) { - cp := &v1.Deployment{} - Expect(proxy.GetClient().Get(ctx, types.NamespacedName{ - Name: "rke2-control-plane-controller-manager", - Namespace: "rke2-control-plane-system", - }, cp)).ToNot(HaveOccurred()) - cpImage := strings.Split(cp.Spec.Template.Spec.Containers[0].Image, ":") - cp.Spec.Template.Spec.Containers[0].Image = cpImage[0] + ":" + version - Expect(proxy.GetClient().Update(ctx, cp)).ToNot(HaveOccurred()) - Eventually(func(g Gomega) { - g.Expect(proxy.GetClient().Get(ctx, client.ObjectKeyFromObject(cp), cp)).To(Succeed()) - g.Expect(cp.Status.ReadyReplicas).To(Equal(*cp.Spec.Replicas)) - g.Expect(cp.Status.ReadyReplicas).To(Equal(cp.Status.UpdatedReplicas)) - g.Expect(cp.Status.ReadyReplicas).To(Equal(cp.Status.AvailableReplicas)) - }).Should(Succeed()) - - bs := &v1.Deployment{} - Expect(proxy.GetClient().Get(ctx, types.NamespacedName{ - Name: "rke2-bootstrap-controller-manager", - Namespace: "rke2-bootstrap-system", - }, bs)).ToNot(HaveOccurred()) - bsImage := strings.Split(bs.Spec.Template.Spec.Containers[0].Image, ":") - bs.Spec.Template.Spec.Containers[0].Image = bsImage[0] + ":" + version - Expect(proxy.GetClient().Update(ctx, bs)).ToNot(HaveOccurred()) - Eventually(func(g Gomega) { - g.Expect(proxy.GetClient().Get(ctx, client.ObjectKeyFromObject(bs), bs)).To(Succeed()) - g.Expect(bs.Status.ReadyReplicas).To(Equal(*bs.Spec.Replicas)) - g.Expect(bs.Status.ReadyReplicas).To(Equal(bs.Status.UpdatedReplicas)) - g.Expect(bs.Status.ReadyReplicas).To(Equal(bs.Status.AvailableReplicas)) - }).Should(Succeed()) -} - // DiscoveryAndWaitForRKE2ControlPlaneInitializedInput is the input type for DiscoveryAndWaitForRKE2ControlPlaneInitialized. type DiscoveryAndWaitForRKE2ControlPlaneInitializedInput struct { Lister framework.Lister @@ -241,27 +205,6 @@ func DiscoveryAndWaitForRKE2ControlPlaneInitialized(ctx context.Context, input D return controlPlane } -// DiscoveryAndWaitForLegacyRKE2ControlPlaneInitialized discovers the RKE2 object attached to a cluster and waits for it to be initialized. -func DiscoveryAndWaitForLegacyRKE2ControlPlaneInitialized(ctx context.Context, input DiscoveryAndWaitForRKE2ControlPlaneInitializedInput, intervals ...interface{}) *controlplanev1alpha1.RKE2ControlPlane { - Expect(ctx).NotTo(BeNil(), "ctx is required for DiscoveryAndWaitForRKE2ControlPlaneInitialized") - Expect(input.Lister).ToNot(BeNil(), "Invalid argument. input.Lister can't be nil when calling DiscoveryAndWaitForRKE2ControlPlaneInitialized") - Expect(input.Cluster).ToNot(BeNil(), "Invalid argument. input.Cluster can't be nil when calling DiscoveryAndWaitForRKE2ControlPlaneInitialized") - - By("Getting legacy RKE2ControlPlane control plane") - - var controlPlane *controlplanev1alpha1.RKE2ControlPlane - Eventually(func(g Gomega) { - controlPlane = GetLegacyRKE2ControlPlaneByCluster(ctx, GetRKE2ControlPlaneByClusterInput{ - Lister: input.Lister, - ClusterName: input.Cluster.Name, - Namespace: input.Cluster.Namespace, - }) - g.Expect(controlPlane).ToNot(BeNil()) - }, "10s", "1s").Should(Succeed(), "Couldn't get the control plane for the cluster %s", klog.KObj(input.Cluster)) - - return controlPlane -} - // GetRKE2ControlPlaneByClusterInput is the input for GetRKE2ControlPlaneByCluster. type GetRKE2ControlPlaneByClusterInput struct { Lister framework.Lister @@ -289,31 +232,10 @@ func GetRKE2ControlPlaneByCluster(ctx context.Context, input GetRKE2ControlPlane return nil } -// GetLegacyRKE2ControlPlaneByCluster returns the RKE2ControlPlane objects for a cluster. -func GetLegacyRKE2ControlPlaneByCluster(ctx context.Context, input GetRKE2ControlPlaneByClusterInput) *controlplanev1alpha1.RKE2ControlPlane { - opts := []client.ListOption{ - client.InNamespace(input.Namespace), - client.MatchingLabels{ - clusterv1.ClusterNameLabel: input.ClusterName, - }, - } - - controlPlaneList := &controlplanev1alpha1.RKE2ControlPlaneList{} - Eventually(func() error { - return input.Lister.List(ctx, controlPlaneList, opts...) - }, retryableOperationTimeout, retryableOperationInterval).Should(Succeed(), "Failed to list RKE2ControlPlane object for Cluster %s", klog.KRef(input.Namespace, input.ClusterName)) - Expect(len(controlPlaneList.Items)).ToNot(BeNumerically(">", 1), "Cluster %s should not have more than 1 RKE2ControlPlane object", klog.KRef(input.Namespace, input.ClusterName)) - if len(controlPlaneList.Items) == 1 { - return &controlPlaneList.Items[0] - } - return nil -} - // WaitForControlPlaneToBeReadyInput is the input for WaitForControlPlaneToBeReady. type WaitForControlPlaneToBeReadyInput struct { - Getter framework.Getter - ControlPlane types.NamespacedName - LegacyControlPlane *controlplanev1alpha1.RKE2ControlPlane + Getter framework.Getter + ControlPlane types.NamespacedName } // WaitForControlPlaneToBeReady will wait for a control plane to be ready. @@ -350,40 +272,6 @@ func WaitForControlPlaneToBeReady(ctx context.Context, input WaitForControlPlane }, intervals...).Should(BeTrue(), framework.PrettyPrint(controlplane)+"\n") } -// WaitForLegacyControlPlaneToBeReady will wait for a control plane to be ready. -func WaitForLegacyControlPlaneToBeReady(ctx context.Context, input WaitForControlPlaneToBeReadyInput, intervals ...interface{}) { - By("Waiting for the control plane to be ready") - controlplane := &controlplanev1alpha1.RKE2ControlPlane{} - Eventually(func() (bool, error) { - key := client.ObjectKey{ - Namespace: input.ControlPlane.Namespace, - Name: input.ControlPlane.Name, - } - if err := input.Getter.Get(ctx, key, controlplane); err != nil { - return false, errors.Wrapf(err, "failed to get RKE2 control plane") - } - - desiredReplicas := controlplane.Spec.Replicas - statusReplicas := controlplane.Status.Replicas - updatedReplicas := controlplane.Status.UpdatedReplicas - readyReplicas := controlplane.Status.ReadyReplicas - unavailableReplicas := controlplane.Status.UnavailableReplicas - - // Control plane is still rolling out (and thus not ready) if: - // * .spec.replicas, .status.replicas, .status.updatedReplicas, - // .status.readyReplicas are not equal and - // * unavailableReplicas > 0 - if statusReplicas != *desiredReplicas || - updatedReplicas != *desiredReplicas || - readyReplicas != *desiredReplicas || - unavailableReplicas > 0 { - return false, nil - } - - return true, nil - }, intervals...).Should(BeTrue(), framework.PrettyPrint(controlplane)+"\n") -} - type WaitForMachineConditionsInput struct { Getter framework.Getter Machine *clusterv1.Machine @@ -405,7 +293,6 @@ func WaitForMachineConditions(ctx context.Context, input WaitForMachineCondition type WaitForClusterToUpgradeInput struct { Lister framework.Lister ControlPlane *controlplanev1.RKE2ControlPlane - LegacyControlPlane *controlplanev1alpha1.RKE2ControlPlane MachineDeployments []*clusterv1.MachineDeployment VersionAfterUpgrade string } @@ -415,11 +302,8 @@ func WaitForClusterToUpgrade(ctx context.Context, input WaitForClusterToUpgradeI By("Waiting for machines to update") var totalMachineCount int32 - if input.ControlPlane != nil { - totalMachineCount = *input.ControlPlane.Spec.Replicas - } else { - totalMachineCount = *input.LegacyControlPlane.Spec.Replicas - } + totalMachineCount = *input.ControlPlane.Spec.Replicas + for _, md := range input.MachineDeployments { totalMachineCount += *md.Spec.Replicas } @@ -451,20 +335,11 @@ func WaitForClusterToUpgrade(ctx context.Context, input WaitForClusterToUpgradeI func setDefaults(input *ApplyClusterTemplateAndWaitInput) { if input.WaitForControlPlaneInitialized == nil { - if !input.Legacy { - input.WaitForControlPlaneInitialized = func(ctx context.Context, input ApplyClusterTemplateAndWaitInput, result *ApplyClusterTemplateAndWaitResult) { - result.ControlPlane = DiscoveryAndWaitForRKE2ControlPlaneInitialized(ctx, DiscoveryAndWaitForRKE2ControlPlaneInitializedInput{ - Lister: input.ClusterProxy.GetClient(), - Cluster: result.Cluster, - }, input.WaitForControlPlaneIntervals...) - } - } else { - input.WaitForControlPlaneInitialized = func(ctx context.Context, input ApplyClusterTemplateAndWaitInput, result *ApplyClusterTemplateAndWaitResult) { - result.LegacyControlPlane = DiscoveryAndWaitForLegacyRKE2ControlPlaneInitialized(ctx, DiscoveryAndWaitForRKE2ControlPlaneInitializedInput{ - Lister: input.ClusterProxy.GetClient(), - Cluster: result.Cluster, - }, input.WaitForControlPlaneIntervals...) - } + input.WaitForControlPlaneInitialized = func(ctx context.Context, input ApplyClusterTemplateAndWaitInput, result *ApplyClusterTemplateAndWaitResult) { + result.ControlPlane = DiscoveryAndWaitForRKE2ControlPlaneInitialized(ctx, DiscoveryAndWaitForRKE2ControlPlaneInitializedInput{ + Lister: input.ClusterProxy.GetClient(), + Cluster: result.Cluster, + }, input.WaitForControlPlaneIntervals...) } } }