|
| 1 | +//go:build e2e |
| 2 | +// +build e2e |
| 3 | + |
| 4 | +/* |
| 5 | +Copyright 2025 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/onsi/ginkgo/v2" |
| 27 | + . "github.com/onsi/gomega" |
| 28 | + corev1 "k8s.io/api/core/v1" |
| 29 | + |
| 30 | + ekscontrolplanev1 "sigs.k8s.io/cluster-api-provider-aws/v2/controlplane/eks/api/v1beta2" |
| 31 | + "sigs.k8s.io/cluster-api-provider-aws/v2/test/e2e/shared" |
| 32 | + "sigs.k8s.io/cluster-api/test/framework" |
| 33 | + "sigs.k8s.io/cluster-api/util" |
| 34 | +) |
| 35 | + |
| 36 | +// Clusterclass EKS e2e test. |
| 37 | +var _ = ginkgo.Describe("[managed] [general] EKS clusterclass tests", func() { |
| 38 | + var ( |
| 39 | + namespace *corev1.Namespace |
| 40 | + ctx context.Context |
| 41 | + specName = "cluster" |
| 42 | + clusterName string |
| 43 | + cniAddonName = "vpc-cni" |
| 44 | + ) |
| 45 | + |
| 46 | + shared.ConditionalIt(runGeneralTests, "should create a cluster and add nodes", func() { |
| 47 | + ginkgo.By("should have a valid test configuration") |
| 48 | + Expect(e2eCtx.Environment.BootstrapClusterProxy).ToNot(BeNil(), "Invalid argument. BootstrapClusterProxy can't be nil") |
| 49 | + Expect(e2eCtx.E2EConfig).ToNot(BeNil(), "Invalid argument. e2eConfig can't be nil when calling %s spec", specName) |
| 50 | + Expect(e2eCtx.E2EConfig.Variables).To(HaveKey(shared.KubernetesVersion)) |
| 51 | + Expect(e2eCtx.E2EConfig.Variables).To(HaveKey(shared.CNIAddonVersion)) |
| 52 | + |
| 53 | + ctx = context.TODO() |
| 54 | + namespace = shared.SetupSpecNamespace(ctx, specName, e2eCtx) |
| 55 | + clusterName = fmt.Sprintf("%s-%s", specName, util.RandomString(6)) |
| 56 | + eksClusterName := getEKSClusterName(namespace.Name, clusterName) |
| 57 | + |
| 58 | + ginkgo.By("default iam role should exist") |
| 59 | + VerifyRoleExistsAndOwned(ekscontrolplanev1.DefaultEKSControlPlaneRole, eksClusterName, false, e2eCtx.BootstrapUserAWSSession) |
| 60 | + |
| 61 | + ginkgo.By("should create an EKS control plane") |
| 62 | + ManagedClusterSpec(ctx, func() ManagedClusterSpecInput { |
| 63 | + return ManagedClusterSpecInput{ |
| 64 | + E2EConfig: e2eCtx.E2EConfig, |
| 65 | + ConfigClusterFn: defaultConfigCluster, |
| 66 | + BootstrapClusterProxy: e2eCtx.Environment.BootstrapClusterProxy, |
| 67 | + AWSSession: e2eCtx.BootstrapUserAWSSession, |
| 68 | + Namespace: namespace, |
| 69 | + ClusterName: clusterName, |
| 70 | + Flavour: EKSClusterClassFlavor, |
| 71 | + ControlPlaneMachineCount: 1, // NOTE: this cannot be zero as clusterctl returns an error |
| 72 | + WorkerMachineCount: 0, |
| 73 | + } |
| 74 | + }) |
| 75 | + |
| 76 | + ginkgo.By("should set environment variables on the aws-node daemonset") |
| 77 | + CheckAwsNodeEnvVarsSet(ctx, func() UpdateAwsNodeVersionSpecInput { |
| 78 | + return UpdateAwsNodeVersionSpecInput{ |
| 79 | + E2EConfig: e2eCtx.E2EConfig, |
| 80 | + BootstrapClusterProxy: e2eCtx.Environment.BootstrapClusterProxy, |
| 81 | + AWSSession: e2eCtx.BootstrapUserAWSSession, |
| 82 | + Namespace: namespace, |
| 83 | + ClusterName: clusterName, |
| 84 | + } |
| 85 | + }) |
| 86 | + |
| 87 | + ginkgo.By("should have the VPC CNI installed") |
| 88 | + CheckAddonExistsSpec(ctx, func() CheckAddonExistsSpecInput { |
| 89 | + return CheckAddonExistsSpecInput{ |
| 90 | + E2EConfig: e2eCtx.E2EConfig, |
| 91 | + BootstrapClusterProxy: e2eCtx.Environment.BootstrapClusterProxy, |
| 92 | + AWSSession: e2eCtx.BootstrapUserAWSSession, |
| 93 | + Namespace: namespace, |
| 94 | + ClusterName: clusterName, |
| 95 | + AddonName: cniAddonName, |
| 96 | + AddonVersion: e2eCtx.E2EConfig.GetVariable(shared.CNIAddonVersion), |
| 97 | + } |
| 98 | + }) |
| 99 | + |
| 100 | + ginkgo.By("should create a MachineDeployment") |
| 101 | + MachineDeploymentSpec(ctx, func() MachineDeploymentSpecInput { |
| 102 | + return MachineDeploymentSpecInput{ |
| 103 | + E2EConfig: e2eCtx.E2EConfig, |
| 104 | + ConfigClusterFn: defaultConfigCluster, |
| 105 | + BootstrapClusterProxy: e2eCtx.Environment.BootstrapClusterProxy, |
| 106 | + AWSSession: e2eCtx.BootstrapUserAWSSession, |
| 107 | + Namespace: namespace, |
| 108 | + ClusterName: clusterName, |
| 109 | + Replicas: 1, |
| 110 | + Cleanup: true, |
| 111 | + } |
| 112 | + }) |
| 113 | + |
| 114 | + ginkgo.By(fmt.Sprintf("getting cluster with name %s", clusterName)) |
| 115 | + cluster := framework.GetClusterByName(ctx, framework.GetClusterByNameInput{ |
| 116 | + Getter: e2eCtx.Environment.BootstrapClusterProxy.GetClient(), |
| 117 | + Namespace: namespace.Name, |
| 118 | + Name: clusterName, |
| 119 | + }) |
| 120 | + Expect(cluster).NotTo(BeNil(), "couldn't find CAPI cluster") |
| 121 | + |
| 122 | + framework.DeleteCluster(ctx, framework.DeleteClusterInput{ |
| 123 | + Deleter: e2eCtx.Environment.BootstrapClusterProxy.GetClient(), |
| 124 | + Cluster: cluster, |
| 125 | + }) |
| 126 | + framework.WaitForClusterDeleted(ctx, framework.WaitForClusterDeletedInput{ |
| 127 | + Client: e2eCtx.Environment.BootstrapClusterProxy.GetClient(), |
| 128 | + Cluster: cluster, |
| 129 | + }, e2eCtx.E2EConfig.GetIntervals("", "wait-delete-cluster")...) |
| 130 | + }) |
| 131 | +}) |
0 commit comments