|
| 1 | +//go:build e2e |
| 2 | +// +build e2e |
| 3 | + |
| 4 | +/* |
| 5 | +Copyright 2020 The Kubernetes Authors. |
| 6 | +
|
| 7 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | +you may not use this file except in compliance with the License. |
| 9 | +You may obtain a copy of the License at |
| 10 | +
|
| 11 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | +
|
| 13 | +Unless required by applicable law or agreed to in writing, software |
| 14 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | +See the License for the specific language governing permissions and |
| 17 | +limitations under the License. |
| 18 | +*/ |
| 19 | + |
| 20 | +package managed |
| 21 | + |
| 22 | +import ( |
| 23 | + "context" |
| 24 | + "fmt" |
| 25 | + |
| 26 | + "github.com/blang/semver" |
| 27 | + "github.com/onsi/ginkgo/v2" |
| 28 | + . "github.com/onsi/gomega" |
| 29 | + corev1 "k8s.io/api/core/v1" |
| 30 | + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
| 31 | + ref "k8s.io/client-go/tools/reference" |
| 32 | + |
| 33 | + eksbootstrapv1 "sigs.k8s.io/cluster-api-provider-aws/v2/bootstrap/eks/api/v1beta2" |
| 34 | + ekscontrolplanev1 "sigs.k8s.io/cluster-api-provider-aws/v2/controlplane/eks/api/v1beta2" |
| 35 | + "sigs.k8s.io/cluster-api-provider-aws/v2/test/e2e/shared" |
| 36 | + "sigs.k8s.io/cluster-api/test/framework" |
| 37 | + "sigs.k8s.io/cluster-api/util" |
| 38 | +) |
| 39 | + |
| 40 | +// EKS cluster upgrade tests. |
| 41 | +var _ = ginkgo.Describe("EKS Cluster upgrade test", func() { |
| 42 | + var ( |
| 43 | + namespace *corev1.Namespace |
| 44 | + ctx context.Context |
| 45 | + specName = "eks-upgrade" |
| 46 | + clusterName string |
| 47 | + initialVersion string |
| 48 | + upgradeToVersion string |
| 49 | + ) |
| 50 | + |
| 51 | + shared.ConditionalIt(runUpgradeTests, "[managed] [upgrade] [nodeadm] should create a cluster and upgrade the kubernetes version", func() { |
| 52 | + ginkgo.By("should have a valid test configuration") |
| 53 | + Expect(e2eCtx.Environment.BootstrapClusterProxy).ToNot(BeNil(), "Invalid argument. BootstrapClusterProxy can't be nil") |
| 54 | + Expect(e2eCtx.E2EConfig).ToNot(BeNil(), "Invalid argument. e2eConfig can't be nil when calling %s spec", specName) |
| 55 | + Expect(e2eCtx.E2EConfig.Variables).To(HaveKey(shared.EksUpgradeFromVersion)) |
| 56 | + Expect(e2eCtx.E2EConfig.Variables).To(HaveKey(shared.EksUpgradeToVersion)) |
| 57 | + ctx = context.TODO() |
| 58 | + namespace = shared.SetupSpecNamespace(ctx, specName, e2eCtx) |
| 59 | + clusterName = fmt.Sprintf("%s-%s", specName, util.RandomString(6)) |
| 60 | + |
| 61 | + initialVersion = e2eCtx.E2EConfig.MustGetVariable(shared.EksUpgradeFromVersion) |
| 62 | + upgradeToVersion = e2eCtx.E2EConfig.MustGetVariable(shared.EksUpgradeToVersion) |
| 63 | + |
| 64 | + ginkgo.By("default iam role should exist") |
| 65 | + VerifyRoleExistsAndOwned(ctx, ekscontrolplanev1.DefaultEKSControlPlaneRole, clusterName, false, e2eCtx.AWSSession) |
| 66 | + |
| 67 | + ginkgo.By("should create an EKS control plane") |
| 68 | + ManagedClusterSpec(ctx, func() ManagedClusterSpecInput { |
| 69 | + return ManagedClusterSpecInput{ |
| 70 | + E2EConfig: e2eCtx.E2EConfig, |
| 71 | + ConfigClusterFn: defaultConfigCluster, |
| 72 | + BootstrapClusterProxy: e2eCtx.Environment.BootstrapClusterProxy, |
| 73 | + AWSSession: e2eCtx.BootstrapUserAWSSession, |
| 74 | + Namespace: namespace, |
| 75 | + ClusterName: clusterName, |
| 76 | + Flavour: EKSControlPlaneOnlyFlavor, // TODO (richardcase) - change in the future when upgrades to machinepools work |
| 77 | + ControlPlaneMachineCount: 1, // NOTE: this cannot be zero as clusterctl returns an error |
| 78 | + WorkerMachineCount: 0, |
| 79 | + KubernetesVersion: initialVersion, |
| 80 | + } |
| 81 | + }) |
| 82 | + |
| 83 | + ginkgo.By(fmt.Sprintf("getting cluster with name %s", clusterName)) |
| 84 | + cluster := framework.GetClusterByName(ctx, framework.GetClusterByNameInput{ |
| 85 | + Getter: e2eCtx.Environment.BootstrapClusterProxy.GetClient(), |
| 86 | + Namespace: namespace.Name, |
| 87 | + Name: clusterName, |
| 88 | + }) |
| 89 | + Expect(cluster).NotTo(BeNil(), "couldn't find cluster") |
| 90 | + |
| 91 | + ginkgo.By("should create a MachineDeployment") |
| 92 | + MachineDeploymentSpec(ctx, func() MachineDeploymentSpecInput { |
| 93 | + return MachineDeploymentSpecInput{ |
| 94 | + E2EConfig: e2eCtx.E2EConfig, |
| 95 | + ConfigClusterFn: defaultConfigCluster, |
| 96 | + BootstrapClusterProxy: e2eCtx.Environment.BootstrapClusterProxy, |
| 97 | + AWSSession: e2eCtx.BootstrapUserAWSSession, |
| 98 | + Namespace: namespace, |
| 99 | + ClusterName: clusterName, |
| 100 | + Replicas: 1, |
| 101 | + Cleanup: false, |
| 102 | + } |
| 103 | + }) |
| 104 | + |
| 105 | + ginkgo.By(fmt.Sprintf("should upgrade control plane to version %s", upgradeToVersion)) |
| 106 | + UpgradeControlPlaneVersionSpec(ctx, func() UpgradeControlPlaneVersionSpecInput { |
| 107 | + return UpgradeControlPlaneVersionSpecInput{ |
| 108 | + E2EConfig: e2eCtx.E2EConfig, |
| 109 | + AWSSession: e2eCtx.BootstrapUserAWSSession, |
| 110 | + BootstrapClusterProxy: e2eCtx.Environment.BootstrapClusterProxy, |
| 111 | + ClusterName: clusterName, |
| 112 | + Namespace: namespace, |
| 113 | + UpgradeVersion: upgradeToVersion, |
| 114 | + } |
| 115 | + }) |
| 116 | + |
| 117 | + ginkgo.By(fmt.Sprintf("should upgrade mahchine deployments to version %s", upgradeToVersion)) |
| 118 | + kube133, err := semver.ParseTolerant("1.33.0") |
| 119 | + Expect(err).To(BeNil(), "semver should pass") |
| 120 | + upgradeToVersionParse, err := semver.ParseTolerant(upgradeToVersion) |
| 121 | + Expect(err).To(BeNil(), "semver should pass") |
| 122 | + |
| 123 | + md := framework.DiscoveryAndWaitForMachineDeployments(ctx, framework.DiscoveryAndWaitForMachineDeploymentsInput{ |
| 124 | + Lister: e2eCtx.Environment.BootstrapClusterProxy.GetClient(), |
| 125 | + Cluster: cluster, |
| 126 | + }, e2eCtx.E2EConfig.GetIntervals("", "wait-worker-nodes")...) |
| 127 | + var nodeadmConfigTemplate *eksbootstrapv1.NodeadmConfigTemplate |
| 128 | + if upgradeToVersionParse.GTE(kube133) { |
| 129 | + ginkgo.By("creating a nodeadmconfigtemplate object") |
| 130 | + nodeadmConfigTemplate = &eksbootstrapv1.NodeadmConfigTemplate{ |
| 131 | + ObjectMeta: metav1.ObjectMeta{ |
| 132 | + Name: fmt.Sprintf("%s-nodeadm-config", clusterName), |
| 133 | + Namespace: namespace.Name, |
| 134 | + }, |
| 135 | + Spec: eksbootstrapv1.NodeadmConfigTemplateSpec{ |
| 136 | + Template: eksbootstrapv1.NodeadmConfigTemplateResource{ |
| 137 | + Spec: eksbootstrapv1.NodeadmConfigSpec{ |
| 138 | + PreBootstrapCommands: []string{ |
| 139 | + "echo \"hello world\"", |
| 140 | + }, |
| 141 | + }, |
| 142 | + }, |
| 143 | + }, |
| 144 | + } |
| 145 | + ginkgo.By("creating the nodeadm config template in the cluster") |
| 146 | + Expect(e2eCtx.Environment.BootstrapClusterProxy.GetClient().Create(ctx, nodeadmConfigTemplate)).To(Succeed()) |
| 147 | + } |
| 148 | + ginkgo.By("upgrading machine deployments") |
| 149 | + input := UpgradeMachineDeploymentsAndWaitInput{ |
| 150 | + BootstrapClusterProxy: e2eCtx.Environment.BootstrapClusterProxy, |
| 151 | + Cluster: cluster, |
| 152 | + UpgradeVersion: upgradeToVersion, |
| 153 | + MachineDeployments: md, |
| 154 | + WaitForMachinesToBeUpgraded: e2eCtx.E2EConfig.GetIntervals("", "wait-worker-nodes"), |
| 155 | + } |
| 156 | + if nodeadmConfigTemplate != nil { |
| 157 | + nodeadmRef, err := ref.GetReference(initScheme(), nodeadmConfigTemplate) |
| 158 | + Expect(err).To(BeNil(), "object should have ref") |
| 159 | + input.UpgradeBootstrapTemplate = nodeadmRef |
| 160 | + } |
| 161 | + UpgradeMachineDeploymentsAndWait(ctx, input) |
| 162 | + |
| 163 | + framework.DeleteCluster(ctx, framework.DeleteClusterInput{ |
| 164 | + Deleter: e2eCtx.Environment.BootstrapClusterProxy.GetClient(), |
| 165 | + Cluster: cluster, |
| 166 | + }) |
| 167 | + framework.WaitForClusterDeleted(ctx, framework.WaitForClusterDeletedInput{ |
| 168 | + ClusterProxy: e2eCtx.Environment.BootstrapClusterProxy, |
| 169 | + Cluster: cluster, |
| 170 | + ClusterctlConfigPath: e2eCtx.Environment.ClusterctlConfigPath, |
| 171 | + ArtifactFolder: e2eCtx.Settings.ArtifactFolder, |
| 172 | + }, e2eCtx.E2EConfig.GetIntervals("", "wait-delete-cluster")...) |
| 173 | + }) |
| 174 | +}) |
0 commit comments