sigs.k8s.io/cluster-api-provider-aws@v1.5.5/test/e2e/suites/unmanaged/unmanaged_functional_clusterclass_test.go (about) 1 //go:build e2e 2 // +build e2e 3 4 /* 5 Copyright 2022 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 unmanaged 21 22 import ( 23 "context" 24 "fmt" 25 "path/filepath" 26 27 "github.com/gofrs/flock" 28 "github.com/onsi/ginkgo" 29 "github.com/onsi/ginkgo/config" 30 . "github.com/onsi/gomega" 31 corev1 "k8s.io/api/core/v1" 32 "k8s.io/utils/pointer" 33 34 infrav1 "sigs.k8s.io/cluster-api-provider-aws/api/v1beta1" 35 "sigs.k8s.io/cluster-api-provider-aws/test/e2e/shared" 36 "sigs.k8s.io/cluster-api/test/framework" 37 "sigs.k8s.io/cluster-api/test/framework/clusterctl" 38 "sigs.k8s.io/cluster-api/util" 39 ) 40 41 var _ = ginkgo.Context("[unmanaged] [functional] [ClusterClass]", func() { 42 var ( 43 ctx context.Context 44 result *clusterctl.ApplyClusterTemplateAndWaitResult 45 requiredResources *shared.TestResource 46 ) 47 48 ginkgo.BeforeEach(func() { 49 ctx = context.TODO() 50 result = &clusterctl.ApplyClusterTemplateAndWaitResult{} 51 }) 52 53 ginkgo.Describe("Multitenancy test [ClusterClass]", func() { 54 ginkgo.It("should create cluster with nested assumed role", func() { 55 // Setup a Namespace where to host objects for this spec and create a watcher for the namespace events. 56 specName := "functional-multitenancy-nested-clusterclass" 57 requiredResources = &shared.TestResource{EC2Normal: 1 * e2eCtx.Settings.InstanceVCPU, IGW: 1, NGW: 1, VPC: 1, ClassicLB: 1, EIP: 1} 58 requiredResources.WriteRequestedResources(e2eCtx, specName) 59 Expect(shared.AcquireResources(requiredResources, config.GinkgoConfig.ParallelNode, flock.New(shared.ResourceQuotaFilePath))).To(Succeed()) 60 defer shared.ReleaseResources(requiredResources, config.GinkgoConfig.ParallelNode, flock.New(shared.ResourceQuotaFilePath)) 61 namespace := shared.SetupSpecNamespace(ctx, specName, e2eCtx) 62 defer shared.DumpSpecResourcesAndCleanup(ctx, "", namespace, e2eCtx) 63 Expect(shared.SetMultitenancyEnvVars(e2eCtx.AWSSession)).To(Succeed()) 64 65 ginkgo.By("Creating cluster") 66 clusterName := fmt.Sprintf("cluster-%s", util.RandomString(6)) 67 clusterctl.ApplyClusterTemplateAndWait(ctx, clusterctl.ApplyClusterTemplateAndWaitInput{ 68 ClusterProxy: e2eCtx.Environment.BootstrapClusterProxy, 69 ConfigCluster: clusterctl.ConfigClusterInput{ 70 LogFolder: filepath.Join(e2eCtx.Settings.ArtifactFolder, "clusters", e2eCtx.Environment.BootstrapClusterProxy.GetName()), 71 ClusterctlConfigPath: e2eCtx.Environment.ClusterctlConfigPath, 72 KubeconfigPath: e2eCtx.Environment.BootstrapClusterProxy.GetKubeconfigPath(), 73 InfrastructureProvider: clusterctl.DefaultInfrastructureProvider, 74 Flavor: shared.NestedMultitenancyClusterClassFlavor, 75 Namespace: namespace.Name, 76 ClusterName: clusterName, 77 KubernetesVersion: e2eCtx.E2EConfig.GetVariable(shared.KubernetesVersion), 78 ControlPlaneMachineCount: pointer.Int64Ptr(1), 79 WorkerMachineCount: pointer.Int64Ptr(0), 80 }, 81 WaitForClusterIntervals: e2eCtx.E2EConfig.GetIntervals(specName, "wait-cluster"), 82 WaitForControlPlaneIntervals: e2eCtx.E2EConfig.GetIntervals(specName, "wait-control-plane"), 83 }, result) 84 85 ginkgo.By("Checking if bastion host is running") 86 awsCluster, err := GetAWSClusterByName(ctx, namespace.Name, clusterName) 87 Expect(err).To(BeNil()) 88 Expect(awsCluster.Status.Bastion.State).To(Equal(infrav1.InstanceStateRunning)) 89 expectAWSClusterConditions(awsCluster, []conditionAssertion{{infrav1.BastionHostReadyCondition, corev1.ConditionTrue, "", ""}}) 90 91 ginkgo.By("PASSED!") 92 }) 93 }) 94 95 ginkgo.Describe("Workload cluster with AWS SSM Parameter as the Secret Backend [ClusterClass]", func() { 96 ginkgo.It("should be creatable and deletable", func() { 97 specName := "functional-test-ssm-parameter-store-clusterclass" 98 requiredResources = &shared.TestResource{EC2Normal: 2 * e2eCtx.Settings.InstanceVCPU, IGW: 1, NGW: 1, VPC: 1, ClassicLB: 1, EIP: 3} 99 requiredResources.WriteRequestedResources(e2eCtx, specName) 100 Expect(shared.AcquireResources(requiredResources, config.GinkgoConfig.ParallelNode, flock.New(shared.ResourceQuotaFilePath))).To(Succeed()) 101 defer shared.ReleaseResources(requiredResources, config.GinkgoConfig.ParallelNode, flock.New(shared.ResourceQuotaFilePath)) 102 namespace := shared.SetupSpecNamespace(ctx, specName, e2eCtx) 103 defer shared.DumpSpecResourcesAndCleanup(ctx, "", namespace, e2eCtx) 104 105 ginkgo.By("Creating a cluster") 106 clusterName := fmt.Sprintf("cluster-%s", util.RandomString(6)) 107 configCluster := defaultConfigCluster(clusterName, namespace.Name) 108 configCluster.ControlPlaneMachineCount = pointer.Int64Ptr(1) 109 configCluster.WorkerMachineCount = pointer.Int64Ptr(1) 110 configCluster.Flavor = shared.TopologyFlavor 111 _, md, _ := createCluster(ctx, configCluster, result) 112 113 workerMachines := framework.GetMachinesByMachineDeployments(ctx, framework.GetMachinesByMachineDeploymentsInput{ 114 Lister: e2eCtx.Environment.BootstrapClusterProxy.GetClient(), 115 ClusterName: clusterName, 116 Namespace: namespace.Name, 117 MachineDeployment: *md[0], 118 }) 119 controlPlaneMachines := framework.GetControlPlaneMachinesByCluster(ctx, framework.GetControlPlaneMachinesByClusterInput{ 120 Lister: e2eCtx.Environment.BootstrapClusterProxy.GetClient(), 121 ClusterName: clusterName, 122 Namespace: namespace.Name, 123 }) 124 Expect(len(workerMachines)).To(Equal(1)) 125 Expect(len(controlPlaneMachines)).To(Equal(1)) 126 }) 127 }) 128 })