1
1
//go:build e2e
2
- // +build e2e
3
2
4
3
/*
5
4
Copyright 2022 The Kubernetes Authors.
@@ -32,6 +31,7 @@ import (
32
31
appsv1 "k8s.io/api/apps/v1"
33
32
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
34
33
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
34
+ configclient "sigs.k8s.io/cluster-api/cmd/clusterctl/client/config"
35
35
36
36
"k8s.io/apimachinery/pkg/labels"
37
37
"k8s.io/apimachinery/pkg/runtime"
@@ -147,7 +147,7 @@ var _ = SynchronizedBeforeSuite(func() []byte {
147
147
148
148
Expect (componentsPath ).To (BeAnExistingFile (), "Invalid test suite argument. e2e.components should be an existing file." )
149
149
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 )
151
151
Expect (helmBinaryPath ).To (BeAnExistingFile (), "Invalid test suite argument. helm-binary-path should be an existing file." )
152
152
Expect (chartPath ).To (BeAnExistingFile (), "Invalid test suite argument. chart-path should be an existing file." )
153
153
@@ -212,6 +212,7 @@ func initScheme() *runtime.Scheme {
212
212
framework .TryAddDefaultSchemes (scheme )
213
213
Expect (operatorv1 .AddToScheme (scheme )).To (Succeed ())
214
214
Expect (operatorv1alpha1 .AddToScheme (scheme )).To (Succeed ())
215
+
215
216
return scheme
216
217
}
217
218
@@ -238,12 +239,15 @@ func createClusterctlLocalRepository(config *clusterctl.E2EConfig, repositoryFol
238
239
239
240
clusterctlConfig := clusterctl .CreateRepository (ctx , createRepositoryInput )
240
241
Expect (clusterctlConfig ).To (BeAnExistingFile (), "The clusterctl config file does not exists in the local repository %s" , repositoryFolder )
242
+
241
243
return clusterctlConfig
242
244
}
243
245
244
246
func setupCluster (config * clusterctl.E2EConfig , scheme * runtime.Scheme , useExistingCluster bool , clusterProxyName string ) (bootstrap.ClusterProvider , framework.ClusterProxy ) {
245
247
var clusterProvider bootstrap.ClusterProvider
248
+
246
249
kubeconfigPath := ""
250
+
247
251
if ! useExistingCluster {
248
252
clusterProvider = bootstrap .CreateKindBootstrapClusterAndLoadImages (ctx , bootstrap.CreateKindBootstrapClusterAndLoadImagesInput {
249
253
Name : config .ManagementClusterName ,
@@ -264,8 +268,9 @@ func setupCluster(config *clusterctl.E2EConfig, scheme *runtime.Scheme, useExist
264
268
func initBootstrapCluster (bootstrapClusterProxy framework.ClusterProxy , config * clusterctl.E2EConfig , clusterctlConfigPath , artifactFolder string ) {
265
269
Expect (bootstrapClusterProxy ).ToNot (BeNil (), "Invalid argument. bootstrapClusterProxy can't be nil when calling initBootstrapCluster" )
266
270
Expect (clusterctlConfigPath ).To (BeAnExistingFile (), "Invalid argument. clusterctlConfigPath must be an existing file when calling initBootstrapCluster" )
271
+
267
272
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" )
269
274
270
275
ensureCertManager (bootstrapClusterProxy , config )
271
276
@@ -295,13 +300,15 @@ func initBootstrapCluster(bootstrapClusterProxy framework.ClusterProxy, config *
295
300
296
301
func initHelmCluster (clusterProxy framework.ClusterProxy , config * clusterctl.E2EConfig ) {
297
302
Expect (clusterProxy ).ToNot (BeNil (), "Invalid argument. bootstrapClusterProxy can't be nil when calling initHelmCluster" )
303
+
298
304
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" )
300
306
ensureCertManager (clusterProxy , config )
301
307
}
302
308
303
309
func ensureCertManager (clusterProxy framework.ClusterProxy , config * clusterctl.E2EConfig ) {
304
310
By ("Deploying cert-manager" )
311
+
305
312
addCertChart := & HelmChart {
306
313
BinaryPath : helmBinaryPath ,
307
314
Name : "jetstack" ,
@@ -336,6 +343,7 @@ func ensureCertManager(clusterProxy framework.ClusterProxy, config *clusterctl.E
336
343
_ , err = certChart .Run (map [string ]string {
337
344
"installCRDs" : "true" ,
338
345
})
346
+ Expect (err ).ToNot (HaveOccurred ())
339
347
}
340
348
341
349
func deleteClusterAPICRDs (clusterProxy framework.ClusterProxy ) {
@@ -346,7 +354,7 @@ func deleteClusterAPICRDs(clusterProxy framework.ClusterProxy) {
346
354
Expect (clusterProxy .GetClient ().List (ctx , crds , & client.ListOptions {
347
355
LabelSelector : labels .SelectorFromSet (
348
356
map [string ]string {
349
- "cluster.x-k8s.io/provider" : "cluster-api" ,
357
+ clusterv1 . ProviderNameLabel : configclient . ClusterAPIProviderName ,
350
358
"clusterctl.cluster.x-k8s.io" : "" ,
351
359
},
352
360
),
@@ -361,7 +369,7 @@ func initHelmChart() {
361
369
helmChart = & HelmChart {
362
370
BinaryPath : helmBinaryPath ,
363
371
Path : chartPath ,
364
- Name : "capi-operator" ,
372
+ Name : capiOperatorRelease ,
365
373
Kubeconfig : helmClusterProxy .GetKubeconfigPath (),
366
374
DryRun : true ,
367
375
Output : Hooks ,
@@ -389,6 +397,7 @@ func tearDown(clusterProvider bootstrap.ClusterProvider, clusterProxy framework.
389
397
if clusterProxy != nil {
390
398
clusterProxy .Dispose (ctx )
391
399
}
400
+
392
401
if clusterProvider != nil {
393
402
clusterProvider .Dispose (ctx )
394
403
}
@@ -412,7 +421,7 @@ func dumpClusterLogs(clusterProxy framework.ClusterProxy) {
412
421
413
422
for i := range nodes .Items {
414
423
nodeName := nodes .Items [i ].GetName ()
415
- err = clusterLogCollector .CollectMachineLog (
424
+ if err = clusterLogCollector .CollectMachineLog (
416
425
ctx ,
417
426
clusterProxy .GetClient (),
418
427
// 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) {
424
433
ObjectMeta : metav1.ObjectMeta {Name : nodeName },
425
434
},
426
435
filepath .Join (artifactFolder , "clusters" , bootstrapClusterProxy .GetName (), "machines" , nodeName ),
427
- )
428
- if err != nil {
436
+ ); err != nil {
429
437
fmt .Printf ("Failed to get logs for the bootstrap cluster node %s: %v\n " , nodeName , err )
430
438
}
431
439
}
0 commit comments