sigs.k8s.io/cluster-api-provider-aws@v1.5.5/test/e2e/suites/conformance/conformance_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 conformance 21 22 import ( 23 "context" 24 "fmt" 25 "path/filepath" 26 "strconv" 27 28 "github.com/onsi/ginkgo" 29 . "github.com/onsi/gomega" 30 corev1 "k8s.io/api/core/v1" 31 "k8s.io/utils/pointer" 32 33 "sigs.k8s.io/cluster-api-provider-aws/test/e2e/shared" 34 "sigs.k8s.io/cluster-api/test/framework/clusterctl" 35 "sigs.k8s.io/cluster-api/test/framework/kubernetesversions" 36 "sigs.k8s.io/cluster-api/test/framework/kubetest" 37 "sigs.k8s.io/cluster-api/util" 38 ) 39 40 // TODO @randomvariable: Replace with CAPI e2e framework ClusterUpgradeConformanceSpec. 41 var _ = ginkgo.Describe("[unmanaged] [conformance] tests", func() { 42 var ( 43 namespace *corev1.Namespace 44 ctx context.Context 45 specName = "conformance" 46 result *clusterctl.ApplyClusterTemplateAndWaitResult 47 ) 48 49 ginkgo.BeforeEach(func() { 50 Expect(e2eCtx.Environment.BootstrapClusterProxy).ToNot(BeNil(), "Invalid argument. BootstrapClusterProxy can't be nil") 51 Expect(e2eCtx.E2EConfig).ToNot(BeNil(), "Invalid argument. e2eConfig can't be nil when calling %s spec", specName) 52 Expect(e2eCtx.E2EConfig.Variables).To(HaveKey(shared.KubernetesVersion)) 53 ctx = context.TODO() 54 // Setup a Namespace where to host objects for this spec and create a watcher for the namespace events. 55 namespace = shared.SetupSpecNamespace(ctx, specName, e2eCtx) 56 result = new(clusterctl.ApplyClusterTemplateAndWaitResult) 57 }) 58 ginkgo.Measure(specName, func(b ginkgo.Benchmarker) { 59 60 name := fmt.Sprintf("%s-%s", specName, util.RandomString(6)) 61 shared.SetEnvVar("USE_CI_ARTIFACTS", "true", false) 62 kubernetesVersion := e2eCtx.E2EConfig.GetVariable(shared.KubernetesVersion) 63 flavor := clusterctl.DefaultFlavor 64 if e2eCtx.Settings.UseCIArtifacts { 65 flavor = "conformance-ci-artifacts" 66 var err error 67 kubernetesVersion, err = kubernetesversions.LatestCIRelease() 68 Expect(err).NotTo(HaveOccurred()) 69 } 70 workerMachineCount, err := strconv.ParseInt(e2eCtx.E2EConfig.GetVariable("CONFORMANCE_WORKER_MACHINE_COUNT"), 10, 64) 71 Expect(err).NotTo(HaveOccurred()) 72 controlPlaneMachineCount, err := strconv.ParseInt(e2eCtx.E2EConfig.GetVariable("CONFORMANCE_CONTROL_PLANE_MACHINE_COUNT"), 10, 64) 73 Expect(err).NotTo(HaveOccurred()) 74 75 runtime := b.Time("cluster creation", func() { 76 clusterctl.ApplyClusterTemplateAndWait(ctx, clusterctl.ApplyClusterTemplateAndWaitInput{ 77 ClusterProxy: e2eCtx.Environment.BootstrapClusterProxy, 78 ConfigCluster: clusterctl.ConfigClusterInput{ 79 LogFolder: filepath.Join(e2eCtx.Settings.ArtifactFolder, "clusters", e2eCtx.Environment.BootstrapClusterProxy.GetName()), 80 ClusterctlConfigPath: e2eCtx.Environment.ClusterctlConfigPath, 81 KubeconfigPath: e2eCtx.Environment.BootstrapClusterProxy.GetKubeconfigPath(), 82 InfrastructureProvider: clusterctl.DefaultInfrastructureProvider, 83 Flavor: flavor, 84 Namespace: namespace.Name, 85 ClusterName: name, 86 KubernetesVersion: kubernetesVersion, 87 ControlPlaneMachineCount: pointer.Int64Ptr(controlPlaneMachineCount), 88 WorkerMachineCount: pointer.Int64Ptr(workerMachineCount), 89 }, 90 WaitForClusterIntervals: e2eCtx.E2EConfig.GetIntervals(specName, "wait-cluster"), 91 WaitForControlPlaneIntervals: e2eCtx.E2EConfig.GetIntervals(specName, "wait-control-plane"), 92 WaitForMachineDeployments: e2eCtx.E2EConfig.GetIntervals(specName, "wait-worker-nodes"), 93 }, result) 94 }) 95 b.RecordValue("cluster creation", runtime.Seconds()) 96 workloadProxy := e2eCtx.Environment.BootstrapClusterProxy.GetWorkloadCluster(ctx, namespace.Name, name) 97 runtime = b.Time("conformance suite", func() { 98 kubetest.Run(ctx, 99 kubetest.RunInput{ 100 ClusterProxy: workloadProxy, 101 NumberOfNodes: int(workerMachineCount), 102 ConfigFilePath: e2eCtx.Settings.KubetestConfigFilePath, 103 }, 104 ) 105 }) 106 b.RecordValue("conformance suite run time", runtime.Seconds()) 107 }, 1) 108 109 ginkgo.AfterEach(func() { 110 shared.SetEnvVar("USE_CI_ARTIFACTS", "false", false) 111 // Dumps all the resources in the spec namespace, then cleanups the cluster object and the spec namespace itself. 112 shared.DumpSpecResourcesAndCleanup(ctx, "", namespace, e2eCtx) 113 }) 114 115 })