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