11//go:build e2e
2- // +build e2e
32
43/*
54Copyright 2022 The Kubernetes Authors.
@@ -32,6 +31,7 @@ import (
3231 appsv1 "k8s.io/api/apps/v1"
3332 apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
3433 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
34+ configclient "sigs.k8s.io/cluster-api/cmd/clusterctl/client/config"
3535
3636 "k8s.io/apimachinery/pkg/labels"
3737 "k8s.io/apimachinery/pkg/runtime"
@@ -147,7 +147,7 @@ var _ = SynchronizedBeforeSuite(func() []byte {
147147
148148 Expect (componentsPath ).To (BeAnExistingFile (), "Invalid test suite argument. e2e.components should be an existing file." )
149149 Expect (configPath ).To (BeAnExistingFile (), "Invalid test suite argument. e2e.config should be an existing file." )
150- Expect (os .MkdirAll (artifactFolder , 0755 )).To (Succeed (), "Invalid test suite argument. Can't create e2e.artifacts-folder %q" , artifactFolder )
150+ Expect (os .MkdirAll (artifactFolder , 0o755 )).To (Succeed (), "Invalid test suite argument. Can't create e2e.artifacts-folder %q" , artifactFolder )
151151 Expect (helmBinaryPath ).To (BeAnExistingFile (), "Invalid test suite argument. helm-binary-path should be an existing file." )
152152 Expect (chartPath ).To (BeAnExistingFile (), "Invalid test suite argument. chart-path should be an existing file." )
153153
@@ -212,6 +212,7 @@ func initScheme() *runtime.Scheme {
212212 framework .TryAddDefaultSchemes (scheme )
213213 Expect (operatorv1 .AddToScheme (scheme )).To (Succeed ())
214214 Expect (operatorv1alpha1 .AddToScheme (scheme )).To (Succeed ())
215+
215216 return scheme
216217}
217218
@@ -238,12 +239,15 @@ func createClusterctlLocalRepository(config *clusterctl.E2EConfig, repositoryFol
238239
239240 clusterctlConfig := clusterctl .CreateRepository (ctx , createRepositoryInput )
240241 Expect (clusterctlConfig ).To (BeAnExistingFile (), "The clusterctl config file does not exists in the local repository %s" , repositoryFolder )
242+
241243 return clusterctlConfig
242244}
243245
244246func setupCluster (config * clusterctl.E2EConfig , scheme * runtime.Scheme , useExistingCluster bool , clusterProxyName string ) (bootstrap.ClusterProvider , framework.ClusterProxy ) {
245247 var clusterProvider bootstrap.ClusterProvider
248+
246249 kubeconfigPath := ""
250+
247251 if ! useExistingCluster {
248252 clusterProvider = bootstrap .CreateKindBootstrapClusterAndLoadImages (ctx , bootstrap.CreateKindBootstrapClusterAndLoadImagesInput {
249253 Name : config .ManagementClusterName ,
@@ -264,8 +268,9 @@ func setupCluster(config *clusterctl.E2EConfig, scheme *runtime.Scheme, useExist
264268func initBootstrapCluster (bootstrapClusterProxy framework.ClusterProxy , config * clusterctl.E2EConfig , clusterctlConfigPath , artifactFolder string ) {
265269 Expect (bootstrapClusterProxy ).ToNot (BeNil (), "Invalid argument. bootstrapClusterProxy can't be nil when calling initBootstrapCluster" )
266270 Expect (clusterctlConfigPath ).To (BeAnExistingFile (), "Invalid argument. clusterctlConfigPath must be an existing file when calling initBootstrapCluster" )
271+
267272 logFolder := filepath .Join (artifactFolder , "clusters" , bootstrapClusterProxy .GetName ())
268- Expect (os .MkdirAll (logFolder , 0750 )).To (Succeed (), "Invalid argument. Log folder can't be created for initBootstrapCluster" )
273+ Expect (os .MkdirAll (logFolder , 0o750 )).To (Succeed (), "Invalid argument. Log folder can't be created for initBootstrapCluster" )
269274
270275 ensureCertManager (bootstrapClusterProxy , config )
271276
@@ -295,13 +300,15 @@ func initBootstrapCluster(bootstrapClusterProxy framework.ClusterProxy, config *
295300
296301func initHelmCluster (clusterProxy framework.ClusterProxy , config * clusterctl.E2EConfig ) {
297302 Expect (clusterProxy ).ToNot (BeNil (), "Invalid argument. bootstrapClusterProxy can't be nil when calling initHelmCluster" )
303+
298304 logFolder := filepath .Join (artifactFolder , "clusters" , helmClusterProxy .GetName ())
299- Expect (os .MkdirAll (logFolder , 0750 )).To (Succeed (), "Invalid argument. Log folder can't be created for initHelmCluster" )
305+ Expect (os .MkdirAll (logFolder , 0o750 )).To (Succeed (), "Invalid argument. Log folder can't be created for initHelmCluster" )
300306 ensureCertManager (clusterProxy , config )
301307}
302308
303309func ensureCertManager (clusterProxy framework.ClusterProxy , config * clusterctl.E2EConfig ) {
304310 By ("Deploying cert-manager" )
311+
305312 addCertChart := & HelmChart {
306313 BinaryPath : helmBinaryPath ,
307314 Name : "jetstack" ,
@@ -336,6 +343,7 @@ func ensureCertManager(clusterProxy framework.ClusterProxy, config *clusterctl.E
336343 _ , err = certChart .Run (map [string ]string {
337344 "installCRDs" : "true" ,
338345 })
346+ Expect (err ).ToNot (HaveOccurred ())
339347}
340348
341349func deleteClusterAPICRDs (clusterProxy framework.ClusterProxy ) {
@@ -346,7 +354,7 @@ func deleteClusterAPICRDs(clusterProxy framework.ClusterProxy) {
346354 Expect (clusterProxy .GetClient ().List (ctx , crds , & client.ListOptions {
347355 LabelSelector : labels .SelectorFromSet (
348356 map [string ]string {
349- "cluster.x-k8s.io/provider" : "cluster-api" ,
357+ clusterv1 . ProviderNameLabel : configclient . ClusterAPIProviderName ,
350358 "clusterctl.cluster.x-k8s.io" : "" ,
351359 },
352360 ),
@@ -361,7 +369,7 @@ func initHelmChart() {
361369 helmChart = & HelmChart {
362370 BinaryPath : helmBinaryPath ,
363371 Path : chartPath ,
364- Name : "capi-operator" ,
372+ Name : capiOperatorRelease ,
365373 Kubeconfig : helmClusterProxy .GetKubeconfigPath (),
366374 DryRun : true ,
367375 Output : Hooks ,
@@ -389,6 +397,7 @@ func tearDown(clusterProvider bootstrap.ClusterProvider, clusterProxy framework.
389397 if clusterProxy != nil {
390398 clusterProxy .Dispose (ctx )
391399 }
400+
392401 if clusterProvider != nil {
393402 clusterProvider .Dispose (ctx )
394403 }
@@ -412,7 +421,7 @@ func dumpClusterLogs(clusterProxy framework.ClusterProxy) {
412421
413422 for i := range nodes .Items {
414423 nodeName := nodes .Items [i ].GetName ()
415- err = clusterLogCollector .CollectMachineLog (
424+ if err = clusterLogCollector .CollectMachineLog (
416425 ctx ,
417426 clusterProxy .GetClient (),
418427 // The bootstrap cluster is not expected to be a CAPI cluster, so in order to re-use the logCollector,
@@ -424,8 +433,7 @@ func dumpClusterLogs(clusterProxy framework.ClusterProxy) {
424433 ObjectMeta : metav1.ObjectMeta {Name : nodeName },
425434 },
426435 filepath .Join (artifactFolder , "clusters" , bootstrapClusterProxy .GetName (), "machines" , nodeName ),
427- )
428- if err != nil {
436+ ); err != nil {
429437 fmt .Printf ("Failed to get logs for the bootstrap cluster node %s: %v\n " , nodeName , err )
430438 }
431439 }
0 commit comments