Skip to content

Commit 46144ca

Browse files
committed
🌱 Fix linter for e2e test packages
1 parent 8647abf commit 46144ca

15 files changed

+85
-55
lines changed

.github/workflows/golangci-lint.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,5 @@ jobs:
2323
- name: golangci-lint
2424
uses: golangci/golangci-lint-action@971e284b6050e8a5849b72094c50ab08da042db8 # tag=v6.1.1
2525
with:
26-
version: v1.60.2
26+
version: v1.63.3
2727
args: --timeout 15m

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ cmd/clusterctl/clusterctl
77
bin
88
hack/tools/bin
99
hack/tools/_out
10+
/vendor
1011

1112
# go.work files
1213
go.work

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ CONTROLLER_GEN_VER := v0.16.1
7070
CONTROLLER_GEN_BIN := controller-gen
7171
CONTROLLER_GEN := $(TOOLS_BIN_DIR)/$(CONTROLLER_GEN_BIN)-$(CONTROLLER_GEN_VER)
7272

73-
GOLANGCI_LINT_VER := v1.60.2
73+
GOLANGCI_LINT_VER := v1.63.3
7474
GOLANGCI_LINT_BIN := golangci-lint
7575
GOLANGCI_LINT := $(TOOLS_BIN_DIR)/$(GOLANGCI_LINT_BIN)-$(GOLANGCI_LINT_VER)
7676

@@ -290,7 +290,7 @@ plugin: ## Build plugin binary
290290
.PHONY: lint
291291
lint: $(GOLANGCI_LINT) ## Lint the codebase
292292
$(GOLANGCI_LINT) run -v $(GOLANGCI_LINT_EXTRA_ARGS) --timeout=10m
293-
cd $(TEST_DIR); $(GOLANGCI_LINT) run --path-prefix $(TEST_DIR) -v $(GOLANGCI_LINT_EXTRA_ARGS) --timeout=10m
293+
cd $(TEST_DIR); $(GOLANGCI_LINT) run --path-prefix $(TEST_DIR) --build-tags e2e -v $(GOLANGCI_LINT_EXTRA_ARGS) --timeout=10m
294294

295295
.PHONY: lint-fix
296296
lint-fix: $(GOLANGCI_LINT) ## Lint the codebase and run auto-fixers if supported by the linter

cmd/plugin/cmd/init.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ func init() {
128128
"Context to be used within the kubeconfig file. If empty, current context will be used.")
129129
initCmd.PersistentFlags().StringVar(&initOpts.operatorVersion, "operator-version", latestVersion,
130130
"CAPI Operator version (e.g. v0.7.0) to install on the management cluster. If unspecified, the latest release is used.")
131-
initCmd.PersistentFlags().StringVar(&initOpts.coreProvider, "core", "cluster-api",
131+
initCmd.PersistentFlags().StringVar(&initOpts.coreProvider, "core", configclient.ClusterAPIProviderName,
132132
"Core provider version (e.g. cluster-api:v1.1.5) to add to the management cluster. If unspecified, Cluster API's latest release is used.")
133133
initCmd.PersistentFlags().StringSliceVarP(&initOpts.infrastructureProviders, "infrastructure", "i", []string{},
134134
"Infrastructure providers and versions (e.g. aws:v0.5.0) to add to the management cluster.")

cmd/plugin/cmd/utils.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ const (
5151
)
5252

5353
var capiOperatorLabels = map[string]string{
54-
"clusterctl.cluster.x-k8s.io/core": "capi-operator",
55-
"control-plane": "controller-manager",
54+
clusterctlv1.ClusterctlCoreLabel: capiOperatorProviderName,
55+
"control-plane": "controller-manager",
5656
}
5757

5858
var (

test/e2e/air_gapped_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
//go:build e2e
2-
// +build e2e
32

43
/*
54
Copyright 2023 The Kubernetes Authors.
@@ -85,7 +84,7 @@ var _ = Describe("Install Core Provider in an air-gapped environment", func() {
8584
},
8685
},
8786
},
88-
Version: "v1.7.7",
87+
Version: previousCAPIVersion,
8988
},
9089
},
9190
}

test/e2e/compressed_manifests_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
//go:build e2e
2-
// +build e2e
32

43
/*
54
Copyright 2023 The Kubernetes Authors.
@@ -45,7 +44,7 @@ const (
4544
)
4645

4746
var _ = Describe("Create and delete a provider with manifests that don't fit the configmap", func() {
48-
var ociInfrastructureConfigMap = &corev1.ConfigMap{}
47+
ociInfrastructureConfigMap := &corev1.ConfigMap{}
4948

5049
It("should successfully create a CoreProvider", func() {
5150
bootstrapCluster := bootstrapClusterProxy.GetClient()
@@ -152,7 +151,8 @@ var _ = Describe("Create and delete a provider with manifests that don't fit the
152151
},
153152
},
154153
},
155-
}}
154+
},
155+
}
156156

157157
// Re-use configmap created on the previous step.
158158
ociInfrastructureConfigMap.ObjectMeta.UID = ""

test/e2e/doc.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
//go:build e2e
2-
// +build e2e
32

43
/*
54
Copyright 2023 The Kubernetes Authors.

test/e2e/e2e_suite_test.go

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
//go:build e2e
2-
// +build e2e
32

43
/*
54
Copyright 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

244246
func 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
264268
func 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

296301
func 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

303309
func 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

341349
func 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
}

test/e2e/helm_test.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
//go:build e2e
2-
// +build e2e
32

43
/*
54
Copyright 2023 The Kubernetes Authors.
@@ -31,6 +30,7 @@ import (
3130
"k8s.io/utils/ptr"
3231
operatorv1 "sigs.k8s.io/cluster-api-operator/api/v1alpha2"
3332
. "sigs.k8s.io/cluster-api-operator/test/framework"
33+
clusterctlv1 "sigs.k8s.io/cluster-api/cmd/clusterctl/api/v1alpha3"
3434
"sigs.k8s.io/cluster-api/test/framework"
3535
"sigs.k8s.io/controller-runtime/pkg/client"
3636
)
@@ -42,7 +42,7 @@ var _ = Describe("Create a proper set of manifests when using helm charts", func
4242
fullHelmChart := &HelmChart{
4343
BinaryPath: helmBinaryPath,
4444
Path: chartPath,
45-
Name: "capi-operator",
45+
Name: capiOperatorRelease,
4646
Kubeconfig: helmClusterProxy.GetKubeconfigPath(),
4747
Wait: true,
4848
Output: Full,
@@ -52,10 +52,11 @@ var _ = Describe("Create a proper set of manifests when using helm charts", func
5252
defer func() {
5353
fullHelmChart.Commands = Commands(Uninstall)
5454
fullHelmChart.AdditionalFlags = Flags("--namespace", operatorNamespace)
55-
fullHelmChart.Run(nil)
55+
_, err := fullHelmChart.Run(nil)
56+
Expect(err).ToNot(HaveOccurred())
5657

57-
err := clusterProxy.DeleteAllOf(ctx, &apiextensionsv1.CustomResourceDefinition{}, client.MatchingLabels{
58-
"clusterctl.cluster.x-k8s.io/core": "capi-operator",
58+
err = clusterProxy.DeleteAllOf(ctx, &apiextensionsv1.CustomResourceDefinition{}, client.MatchingLabels{
59+
clusterctlv1.ClusterctlCoreLabel: capiOperatorRelease,
5960
})
6061
Expect(err).ToNot(HaveOccurred())
6162
}()
@@ -82,7 +83,7 @@ var _ = Describe("Create a proper set of manifests when using helm charts", func
8283
HaveStatusCondition(&coreProvider.Status.Conditions, operatorv1.ProviderInstalledCondition),
8384
), e2eConfig.GetIntervals(helmClusterProxy.GetName(), "wait-controllers")...)
8485

85-
By("Waiting for status.IntalledVersion to be set")
86+
By("Waiting for status.InstalledVersion to be set")
8687
WaitFor(ctx, For(coreProvider).In(clusterProxy).ToSatisfy(func() bool {
8788
return ptr.Equal(coreProvider.Status.InstalledVersion, ptr.To(coreProvider.Spec.Version))
8889
}), e2eConfig.GetIntervals(helmClusterProxy.GetName(), "wait-controllers")...)
@@ -109,7 +110,7 @@ var _ = Describe("Create a proper set of manifests when using helm charts", func
109110
HaveStatusCondition(&bootstrapProvider.Status.Conditions, operatorv1.ProviderInstalledCondition)),
110111
e2eConfig.GetIntervals(helmClusterProxy.GetName(), "wait-controllers")...)
111112

112-
By("Waiting for status.IntalledVersion to be set")
113+
By("Waiting for status.InstalledVersion to be set")
113114
WaitFor(ctx, For(bootstrapProvider).In(clusterProxy).ToSatisfy(func() bool {
114115
return ptr.Equal(bootstrapProvider.Status.InstalledVersion, &bootstrapProvider.Spec.Version)
115116
}), e2eConfig.GetIntervals(helmClusterProxy.GetName(), "wait-controllers")...)
@@ -135,6 +136,7 @@ var _ = Describe("Create a proper set of manifests when using helm charts", func
135136
manifests, err := fullRun.Run(nil)
136137
Expect(err).ToNot(HaveOccurred())
137138
fullChartInstall, err := os.ReadFile(filepath.Join(customManifestsFolder, "full-chart-install.yaml"))
139+
Expect(err).ToNot(HaveOccurred())
138140
Expect(manifests).To(Equal(string(fullChartInstall)))
139141
})
140142

test/e2e/helpers_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
//go:build e2e
2-
// +build e2e
32

43
/*
54
Copyright 2022 The Kubernetes Authors.
@@ -21,19 +20,20 @@ package e2e
2120

2221
import (
2322
"context"
24-
)
2523

26-
var (
27-
ctx = context.Background()
24+
configclient "sigs.k8s.io/cluster-api/cmd/clusterctl/client/config"
2825
)
2926

27+
var ctx = context.Background()
28+
3029
const (
3130
operatorNamespace = "capi-operator-system"
3231
capiSystemNamespace = "capi-system"
32+
capiOperatorRelease = "capi-operator"
3333

3434
previousCAPIVersion = "v1.7.7"
3535

36-
coreProviderName = "cluster-api"
36+
coreProviderName = configclient.ClusterAPIProviderName
3737
coreProviderDeploymentName = "capi-controller-manager"
3838

3939
bootstrapProviderName = "kubeadm"

test/e2e/minimal_configuration_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
//go:build e2e
2-
// +build e2e
32

43
/*
54
Copyright 2022 The Kubernetes Authors.
@@ -38,6 +37,11 @@ import (
3837
"sigs.k8s.io/controller-runtime/pkg/client"
3938
)
4039

40+
const (
41+
mediaType = "application/vnd.test.file"
42+
artifactType = "application/vnd.acme.config"
43+
)
44+
4145
var _ = Describe("Create, upgrade, downgrade and delete providers with minimal specified configuration", func() {
4246
It("should successfully create a CoreProvider", func() {
4347
bootstrapCluster := bootstrapClusterProxy.GetClient()
@@ -99,6 +103,7 @@ metadata:
99103
if v, ok := deployment.Labels["test-label"]; ok {
100104
return v == "test-value"
101105
}
106+
102107
return false
103108
}), e2eConfig.GetIntervals(bootstrapClusterProxy.GetName(), "wait-controllers")...)
104109

@@ -117,7 +122,8 @@ metadata:
117122
ObjectMeta: metav1.ObjectMeta{
118123
Name: "test-config-map",
119124
Namespace: operatorNamespace,
120-
}}
125+
},
126+
}
121127
WaitFor(ctx, For(cm).In(bootstrapCluster).ToSatisfy(func() bool {
122128
value, ok := cm.Data["test"]
123129
return ok && value == "test"
@@ -353,7 +359,6 @@ metadata:
353359
Expect(fs.Close()).To(Succeed())
354360
}()
355361

356-
mediaType := "application/vnd.test.file"
357362
fds := []v1.Descriptor{}
358363

359364
fileDescriptor, err := fs.Add(ctx, "infrastructure-custom-v0.0.1-metadata.yaml", mediaType, "")
@@ -372,7 +377,6 @@ metadata:
372377
Expect(err).ToNot(HaveOccurred())
373378
fds = append(fds, fileDescriptor)
374379

375-
artifactType := "application/vnd.acme.config"
376380
opts := oras.PackManifestOptions{
377381
Layers: fds,
378382
}
@@ -442,7 +446,6 @@ metadata:
442446
Expect(fs.Close()).To(Succeed())
443447
}()
444448

445-
mediaType := "application/vnd.test.file"
446449
fds := []v1.Descriptor{}
447450

448451
fileDescriptor, err := fs.Add(ctx, "infrastructure-custom-v0.0.1-metadata.yaml", mediaType, "")
@@ -461,7 +464,6 @@ metadata:
461464
Expect(err).ToNot(HaveOccurred())
462465
fds = append(fds, fileDescriptor)
463466

464-
artifactType := "application/vnd.acme.config"
465467
opts := oras.PackManifestOptions{
466468
Layers: fds,
467469
}
@@ -531,7 +533,6 @@ metadata:
531533
Expect(fs.Close()).To(Succeed())
532534
}()
533535

534-
mediaType := "application/vnd.test.file"
535536
fds := []v1.Descriptor{}
536537

537538
fileDescriptor, err := fs.Add(ctx, "infrastructure-docker-v0.0.1-metadata.yaml", mediaType, "")
@@ -550,7 +551,6 @@ metadata:
550551
Expect(err).ToNot(HaveOccurred())
551552
fds = append(fds, fileDescriptor)
552553

553-
artifactType := "application/vnd.acme.config"
554554
opts := oras.PackManifestOptions{
555555
Layers: fds,
556556
}

0 commit comments

Comments
 (0)