|  | 
|  | 1 | +// +build e2e | 
|  | 2 | + | 
|  | 3 | +/* | 
|  | 4 | +Copyright 2020 The Kubernetes Authors. | 
|  | 5 | +
 | 
|  | 6 | +Licensed under the Apache License, Version 2.0 (the "License"); | 
|  | 7 | +you may not use this file except in compliance with the License. | 
|  | 8 | +You may obtain a copy of the License at | 
|  | 9 | +
 | 
|  | 10 | +    http://www.apache.org/licenses/LICENSE-2.0 | 
|  | 11 | +
 | 
|  | 12 | +Unless required by applicable law or agreed to in writing, software | 
|  | 13 | +distributed under the License is distributed on an "AS IS" BASIS, | 
|  | 14 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
|  | 15 | +See the License for the specific language governing permissions and | 
|  | 16 | +limitations under the License. | 
|  | 17 | +*/ | 
|  | 18 | + | 
|  | 19 | +package e2e | 
|  | 20 | + | 
|  | 21 | +import ( | 
|  | 22 | +	"context" | 
|  | 23 | +	"fmt" | 
|  | 24 | +	"os" | 
|  | 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 | +	clusterv1 "sigs.k8s.io/cluster-api/api/v1alpha3" | 
|  | 33 | +	capi_e2e "sigs.k8s.io/cluster-api/test/e2e" | 
|  | 34 | +	"sigs.k8s.io/cluster-api/test/framework/clusterctl" | 
|  | 35 | +	"sigs.k8s.io/cluster-api/test/framework/kubetest" | 
|  | 36 | +	"sigs.k8s.io/cluster-api/util" | 
|  | 37 | +) | 
|  | 38 | + | 
|  | 39 | +var _ = Describe("Conformance Tests", func() { | 
|  | 40 | +	var ( | 
|  | 41 | +		ctx                 = context.TODO() | 
|  | 42 | +		specName            = "conformance-tests" | 
|  | 43 | +		namespace           *corev1.Namespace | 
|  | 44 | +		cancelWatches       context.CancelFunc | 
|  | 45 | +		cluster             *clusterv1.Cluster | 
|  | 46 | +		clusterName         string | 
|  | 47 | +		clusterctlLogFolder string | 
|  | 48 | +	) | 
|  | 49 | + | 
|  | 50 | +	BeforeEach(func() { | 
|  | 51 | +		Expect(e2eConfig).ToNot(BeNil(), "Invalid argument. e2eConfig can't be nil when calling %s spec", specName) | 
|  | 52 | +		Expect(clusterctlConfigPath).To(BeAnExistingFile(), "Invalid argument. clusterctlConfigPath must be an existing file when calling %s spec", specName) | 
|  | 53 | +		Expect(bootstrapClusterProxy).ToNot(BeNil(), "Invalid argument. bootstrapClusterProxy can't be nil when calling %s spec", specName) | 
|  | 54 | +		Expect(os.MkdirAll(artifactFolder, 0755)).To(Succeed(), "Invalid argument. artifactFolder can't be created for %s spec", specName) | 
|  | 55 | +		Expect(kubetestConfigFilePath).ToNot(BeNil(), "Invalid argument. kubetestConfigFilePath can't be nil") | 
|  | 56 | + | 
|  | 57 | +		Expect(e2eConfig.Variables).To(HaveKey(capi_e2e.KubernetesVersion)) | 
|  | 58 | +		Expect(e2eConfig.Variables).To(HaveKey(capi_e2e.CNIPath)) | 
|  | 59 | + | 
|  | 60 | +		clusterName = fmt.Sprintf("capp-conf-%s", util.RandomString(6)) | 
|  | 61 | + | 
|  | 62 | +		// Setup a Namespace where to host objects for this spec and create a watcher for the namespace events. | 
|  | 63 | +		namespace, cancelWatches = setupSpecNamespace(ctx, specName, bootstrapClusterProxy, artifactFolder) | 
|  | 64 | + | 
|  | 65 | +		// We need to override clusterctl apply log folder to avoid getting our credentials exposed. | 
|  | 66 | +		clusterctlLogFolder = filepath.Join(os.TempDir(), "clusters", bootstrapClusterProxy.GetName()) | 
|  | 67 | +	}) | 
|  | 68 | + | 
|  | 69 | +	Measure(specName, func(b Benchmarker) { | 
|  | 70 | +		var err error | 
|  | 71 | + | 
|  | 72 | +		workerMachineCount, err := strconv.ParseInt(e2eConfig.GetVariable("CONFORMANCE_WORKER_MACHINE_COUNT"), 10, 64) | 
|  | 73 | +		Expect(err).NotTo(HaveOccurred()) | 
|  | 74 | +		controlPlaneMachineCount, err := strconv.ParseInt(e2eConfig.GetVariable("CONFORMANCE_CONTROL_PLANE_MACHINE_COUNT"), 10, 64) | 
|  | 75 | +		Expect(err).NotTo(HaveOccurred()) | 
|  | 76 | + | 
|  | 77 | +		runtime := b.Time("cluster creation", func() { | 
|  | 78 | +			result := clusterctl.ApplyClusterTemplateAndWait(ctx, clusterctl.ApplyClusterTemplateAndWaitInput{ | 
|  | 79 | +				ClusterProxy: bootstrapClusterProxy, | 
|  | 80 | +				ConfigCluster: clusterctl.ConfigClusterInput{ | 
|  | 81 | +					LogFolder:                clusterctlLogFolder, | 
|  | 82 | +					ClusterctlConfigPath:     clusterctlConfigPath, | 
|  | 83 | +					KubeconfigPath:           bootstrapClusterProxy.GetKubeconfigPath(), | 
|  | 84 | +					InfrastructureProvider:   clusterctl.DefaultInfrastructureProvider, | 
|  | 85 | +					Flavor:                   clusterctl.DefaultFlavor, | 
|  | 86 | +					Namespace:                namespace.Name, | 
|  | 87 | +					ClusterName:              clusterName, | 
|  | 88 | +					KubernetesVersion:        e2eConfig.GetVariable(capi_e2e.KubernetesVersion), | 
|  | 89 | +					ControlPlaneMachineCount: pointer.Int64Ptr(controlPlaneMachineCount), | 
|  | 90 | +					WorkerMachineCount:       pointer.Int64Ptr(workerMachineCount), | 
|  | 91 | +				}, | 
|  | 92 | +				WaitForClusterIntervals:      e2eConfig.GetIntervals(specName, "wait-cluster"), | 
|  | 93 | +				WaitForControlPlaneIntervals: e2eConfig.GetIntervals(specName, "wait-control-plane"), | 
|  | 94 | +				WaitForMachineDeployments:    e2eConfig.GetIntervals(specName, "wait-worker-nodes"), | 
|  | 95 | +			}) | 
|  | 96 | + | 
|  | 97 | +			cluster = result.Cluster | 
|  | 98 | +		}) | 
|  | 99 | + | 
|  | 100 | +		b.RecordValue("cluster creation", runtime.Seconds()) | 
|  | 101 | +		workloadProxy := bootstrapClusterProxy.GetWorkloadCluster(ctx, namespace.Name, clusterName) | 
|  | 102 | +		runtime = b.Time("conformance suite", func() { | 
|  | 103 | +			kubetest.Run( | 
|  | 104 | +				kubetest.RunInput{ | 
|  | 105 | +					ClusterProxy:   workloadProxy, | 
|  | 106 | +					NumberOfNodes:  int(workerMachineCount), | 
|  | 107 | +					ConfigFilePath: kubetestConfigFilePath, | 
|  | 108 | +				}, | 
|  | 109 | +			) | 
|  | 110 | +		}) | 
|  | 111 | +		b.RecordValue("conformance suite run time", runtime.Seconds()) | 
|  | 112 | +	}, 1) | 
|  | 113 | + | 
|  | 114 | +	AfterEach(func() { | 
|  | 115 | +		dumpSpecResourcesAndCleanup(ctx, specName, bootstrapClusterProxy, artifactFolder, namespace, cancelWatches, cluster, e2eConfig.GetIntervals, clusterName, clusterctlLogFolder, skipCleanup) | 
|  | 116 | +	}) | 
|  | 117 | +}) | 
0 commit comments