From 7e2d4f5ad31dd85f5b49de1257714eeca8602d96 Mon Sep 17 00:00:00 2001 From: Aarti Date: Mon, 7 Feb 2022 15:20:52 -0800 Subject: [PATCH] allow provider specific infra machine template for upgrade tests --- test/e2e/cluster_upgrade.go | 36 ++++++++++++--------- test/e2e/common.go | 1 + test/framework/controlplane_helpers.go | 25 +++++++------- test/framework/machinedeployment_helpers.go | 14 +++++--- 4 files changed, 45 insertions(+), 31 deletions(-) diff --git a/test/e2e/cluster_upgrade.go b/test/e2e/cluster_upgrade.go index c13383d76374..d81044383566 100644 --- a/test/e2e/cluster_upgrade.go +++ b/test/e2e/cluster_upgrade.go @@ -154,27 +154,33 @@ func ClusterUpgradeConformanceSpec(ctx context.Context, inputGetter func() Clust } else { // Cluster is not using ClusterClass, upgrade via individual resources. By("Upgrading the Kubernetes control-plane") + var upgradeMachineTemplateTo *string + if input.E2EConfig.HasVariable(MachineTemplateUpgradeTo) { + upgradeMachineTemplateTo = pointer.StringPtr(input.E2EConfig.GetVariable(MachineTemplateUpgradeTo)) + } framework.UpgradeControlPlaneAndWaitForUpgrade(ctx, framework.UpgradeControlPlaneAndWaitForUpgradeInput{ - ClusterProxy: input.BootstrapClusterProxy, - Cluster: clusterResources.Cluster, - ControlPlane: clusterResources.ControlPlane, - EtcdImageTag: input.E2EConfig.GetVariable(EtcdVersionUpgradeTo), - DNSImageTag: input.E2EConfig.GetVariable(CoreDNSVersionUpgradeTo), - KubernetesUpgradeVersion: input.E2EConfig.GetVariable(KubernetesVersionUpgradeTo), - WaitForMachinesToBeUpgraded: input.E2EConfig.GetIntervals(specName, "wait-machine-upgrade"), - WaitForKubeProxyUpgrade: input.E2EConfig.GetIntervals(specName, "wait-machine-upgrade"), - WaitForDNSUpgrade: input.E2EConfig.GetIntervals(specName, "wait-machine-upgrade"), - WaitForEtcdUpgrade: input.E2EConfig.GetIntervals(specName, "wait-machine-upgrade"), + ClusterProxy: input.BootstrapClusterProxy, + Cluster: clusterResources.Cluster, + ControlPlane: clusterResources.ControlPlane, + EtcdImageTag: input.E2EConfig.GetVariable(EtcdVersionUpgradeTo), + DNSImageTag: input.E2EConfig.GetVariable(CoreDNSVersionUpgradeTo), + KubernetesUpgradeVersion: input.E2EConfig.GetVariable(KubernetesVersionUpgradeTo), + KubernetesUpgradeMachineTemplate: upgradeMachineTemplateTo, + WaitForMachinesToBeUpgraded: input.E2EConfig.GetIntervals(specName, "wait-machine-upgrade"), + WaitForKubeProxyUpgrade: input.E2EConfig.GetIntervals(specName, "wait-machine-upgrade"), + WaitForDNSUpgrade: input.E2EConfig.GetIntervals(specName, "wait-machine-upgrade"), + WaitForEtcdUpgrade: input.E2EConfig.GetIntervals(specName, "wait-machine-upgrade"), }) if workerMachineCount > 0 { By("Upgrading the machine deployment") framework.UpgradeMachineDeploymentsAndWait(ctx, framework.UpgradeMachineDeploymentsAndWaitInput{ - ClusterProxy: input.BootstrapClusterProxy, - Cluster: clusterResources.Cluster, - UpgradeVersion: input.E2EConfig.GetVariable(KubernetesVersionUpgradeTo), - MachineDeployments: clusterResources.MachineDeployments, - WaitForMachinesToBeUpgraded: input.E2EConfig.GetIntervals(specName, "wait-worker-nodes"), + ClusterProxy: input.BootstrapClusterProxy, + Cluster: clusterResources.Cluster, + UpgradeVersion: input.E2EConfig.GetVariable(KubernetesVersionUpgradeTo), + KubernetesUpgradeMachineTemplate: upgradeMachineTemplateTo, + MachineDeployments: clusterResources.MachineDeployments, + WaitForMachinesToBeUpgraded: input.E2EConfig.GetIntervals(specName, "wait-worker-nodes"), }) } } diff --git a/test/e2e/common.go b/test/e2e/common.go index ca37c6d8ad1c..99fc830f7650 100644 --- a/test/e2e/common.go +++ b/test/e2e/common.go @@ -39,6 +39,7 @@ const ( CNIResources = "CNI_RESOURCES" KubernetesVersionUpgradeFrom = "KUBERNETES_VERSION_UPGRADE_FROM" KubernetesVersionUpgradeTo = "KUBERNETES_VERSION_UPGRADE_TO" + MachineTemplateUpgradeTo = "MACHINE_TEMPLATE_UPGRADE_TO" EtcdVersionUpgradeTo = "ETCD_VERSION_UPGRADE_TO" CoreDNSVersionUpgradeTo = "COREDNS_VERSION_UPGRADE_TO" IPFamily = "IP_FAMILY" diff --git a/test/framework/controlplane_helpers.go b/test/framework/controlplane_helpers.go index a129cc1e0846..ceaba2d4c44f 100644 --- a/test/framework/controlplane_helpers.go +++ b/test/framework/controlplane_helpers.go @@ -281,16 +281,17 @@ func WaitForControlPlaneAndMachinesReady(ctx context.Context, input WaitForContr // UpgradeControlPlaneAndWaitForUpgradeInput is the input type for UpgradeControlPlaneAndWaitForUpgrade. type UpgradeControlPlaneAndWaitForUpgradeInput struct { - ClusterProxy ClusterProxy - Cluster *clusterv1.Cluster - ControlPlane *controlplanev1.KubeadmControlPlane - KubernetesUpgradeVersion string - EtcdImageTag string - DNSImageTag string - WaitForMachinesToBeUpgraded []interface{} - WaitForDNSUpgrade []interface{} - WaitForKubeProxyUpgrade []interface{} - WaitForEtcdUpgrade []interface{} + ClusterProxy ClusterProxy + Cluster *clusterv1.Cluster + ControlPlane *controlplanev1.KubeadmControlPlane + KubernetesUpgradeVersion string + KubernetesUpgradeMachineTemplate *string + EtcdImageTag string + DNSImageTag string + WaitForMachinesToBeUpgraded []interface{} + WaitForDNSUpgrade []interface{} + WaitForKubeProxyUpgrade []interface{} + WaitForEtcdUpgrade []interface{} } // UpgradeControlPlaneAndWaitForUpgrade upgrades a KubeadmControlPlane and waits for it to be upgraded. @@ -310,7 +311,9 @@ func UpgradeControlPlaneAndWaitForUpgrade(ctx context.Context, input UpgradeCont Expect(err).ToNot(HaveOccurred()) input.ControlPlane.Spec.Version = input.KubernetesUpgradeVersion - + if input.KubernetesUpgradeMachineTemplate != nil { + input.ControlPlane.Spec.MachineTemplate.InfrastructureRef.Name = *input.KubernetesUpgradeMachineTemplate + } // If the ClusterConfiguration is not specified, create an empty one. if input.ControlPlane.Spec.KubeadmConfigSpec.ClusterConfiguration == nil { input.ControlPlane.Spec.KubeadmConfigSpec.ClusterConfiguration = new(bootstrapv1.ClusterConfiguration) diff --git a/test/framework/machinedeployment_helpers.go b/test/framework/machinedeployment_helpers.go index b7a6e24135fa..7636d17dc5d3 100644 --- a/test/framework/machinedeployment_helpers.go +++ b/test/framework/machinedeployment_helpers.go @@ -150,11 +150,12 @@ func DiscoveryAndWaitForMachineDeployments(ctx context.Context, input DiscoveryA // UpgradeMachineDeploymentsAndWaitInput is the input type for UpgradeMachineDeploymentsAndWait. type UpgradeMachineDeploymentsAndWaitInput struct { - ClusterProxy ClusterProxy - Cluster *clusterv1.Cluster - UpgradeVersion string - MachineDeployments []*clusterv1.MachineDeployment - WaitForMachinesToBeUpgraded []interface{} + ClusterProxy ClusterProxy + Cluster *clusterv1.Cluster + UpgradeVersion string + KubernetesUpgradeMachineTemplate *string + MachineDeployments []*clusterv1.MachineDeployment + WaitForMachinesToBeUpgraded []interface{} } // UpgradeMachineDeploymentsAndWait upgrades a machine deployment and waits for its machines to be upgraded. @@ -174,6 +175,9 @@ func UpgradeMachineDeploymentsAndWait(ctx context.Context, input UpgradeMachineD oldVersion := deployment.Spec.Template.Spec.Version deployment.Spec.Template.Spec.Version = &input.UpgradeVersion + if input.KubernetesUpgradeMachineTemplate != nil { + deployment.Spec.Template.Spec.InfrastructureRef.Name = *input.KubernetesUpgradeMachineTemplate + } Expect(patchHelper.Patch(ctx, deployment)).To(Succeed()) log.Logf("Waiting for Kubernetes versions of machines in MachineDeployment %s/%s to be upgraded from %s to %s",