Skip to content

Commit 7f3c5f0

Browse files
authored
Merge pull request #6014 from sbueringer/pr-upgrade-golangci-lint-to-1.44
🌱 Upgrade to golangci-lint v1.44 and fix findings
2 parents 05e5c5b + dece5b1 commit 7f3c5f0

File tree

25 files changed

+120
-88
lines changed

25 files changed

+120
-88
lines changed

.github/workflows/golangci-lint.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@ jobs:
1717
- name: golangci-lint
1818
uses: golangci/golangci-lint-action@v2
1919
with:
20-
version: v1.43.0
20+
version: v1.44.0
2121
working-directory: ${{matrix.working-directory}}

.golangci.yml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ linters:
33
enable:
44
- asciicheck
55
- bodyclose
6+
- containedctx
67
- deadcode
78
- depguard
89
- dogsled
@@ -236,12 +237,20 @@ issues:
236237
- typecheck
237238
text: import (".+") is a program, not an importable package
238239
path: ^tools\.go$
239-
# Ignore ifshort false positive
240-
# TODO(sbueringer) false positive: https://github.com/esimonov/ifshort/issues/23
240+
# TODO(sbueringer) Ignore ifshort false positive: https://github.com/esimonov/ifshort/issues/23
241241
- linters:
242242
- ifshort
243243
text: "variable 'isDeleteNodeAllowed' is only used in the if-statement.*"
244244
path: ^internal/controllers/machine/machine_controller\.go$
245+
- linters:
246+
- ifshort
247+
text: "variable 'kcpMachinesWithErrors' is only used in the if-statement.*"
248+
path: ^controlplane/kubeadm/internal/workload_cluster_conditions\.go$
249+
# We don't care about defer in for loops in test files.
250+
- linters:
251+
- gocritic
252+
text: "deferInLoop: Possible resource leak, 'defer' is called in the 'for' loop"
253+
path: _test\.go
245254

246255
run:
247256
timeout: 10m

cmd/clusterctl/client/alpha/rollout_pauser.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func (r *rollout) ObjectPauser(proxy cluster.Proxy, ref corev1.ObjectReference)
3636
return errors.Wrapf(err, "failed to fetch %v/%v", ref.Kind, ref.Name)
3737
}
3838
if deployment.Spec.Paused {
39-
return errors.Errorf("MachineDeploymet is already paused: %v/%v\n", ref.Kind, ref.Name)
39+
return errors.Errorf("MachineDeploymet is already paused: %v/%v\n", ref.Kind, ref.Name) //nolint:revive // MachineDeployment is intentionally capitalized.
4040
}
4141
if err := pauseMachineDeployment(proxy, ref.Name, ref.Namespace); err != nil {
4242
return err

cmd/clusterctl/client/alpha/rollout_restarter.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func (r *rollout) ObjectRestarter(proxy cluster.Proxy, ref corev1.ObjectReferenc
3737
return errors.Wrapf(err, "failed to fetch %v/%v", ref.Kind, ref.Name)
3838
}
3939
if deployment.Spec.Paused {
40-
return errors.Errorf("can't restart paused machinedeployment (run rollout resume first): %v/%v\n", ref.Kind, ref.Name)
40+
return errors.Errorf("can't restart paused MachineDeployment (run rollout resume first): %v/%v", ref.Kind, ref.Name)
4141
}
4242
if err := setRestartedAtAnnotation(proxy, ref.Name, ref.Namespace); err != nil {
4343
return err

cmd/clusterctl/client/alpha/rollout_resumer.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@ func (r *rollout) ObjectResumer(proxy cluster.Proxy, ref corev1.ObjectReference)
3636
return errors.Wrapf(err, "failed to fetch %v/%v", ref.Kind, ref.Name)
3737
}
3838
if !deployment.Spec.Paused {
39-
return errors.Errorf("MachineDeployment is not currently paused: %v/%v\n", ref.Kind, ref.Name)
39+
return errors.Errorf("MachineDeployment is not currently paused: %v/%v\n", ref.Kind, ref.Name) //nolint:revive // MachineDeployment is intentionally capitalized.
4040
}
4141
if err := resumeMachineDeployment(proxy, ref.Name, ref.Namespace); err != nil {
4242
return err
4343
}
4444
default:
45-
return errors.Errorf("Invalid resource type %q, valid values are %v", ref.Kind, validResourceTypes)
45+
return errors.Errorf("invalid resource type %q, valid values are %v", ref.Kind, validResourceTypes)
4646
}
4747
return nil
4848
}

cmd/clusterctl/client/client_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ func newFakeClient(configClient config.Client) *fakeClient {
169169
// converting the client.Kubeconfig to cluster.Kubeconfig alias
170170
k := cluster.Kubeconfig(i.Kubeconfig)
171171
if _, ok := fake.clusters[k]; !ok {
172-
return nil, errors.Errorf("Cluster for kubeconfig %q and/or context %q does not exist.", i.Kubeconfig.Path, i.Kubeconfig.Context)
172+
return nil, errors.Errorf("Cluster for kubeconfig %q and/or context %q does not exist", i.Kubeconfig.Path, i.Kubeconfig.Context)
173173
}
174174
return fake.clusters[k], nil
175175
}
@@ -179,7 +179,7 @@ func newFakeClient(configClient config.Client) *fakeClient {
179179
InjectClusterClientFactory(clusterClientFactory),
180180
InjectRepositoryFactory(func(input RepositoryClientFactoryInput) (repository.Client, error) {
181181
if _, ok := fake.repositories[input.Provider.ManifestLabel()]; !ok {
182-
return nil, errors.Errorf("Repository for kubeconfig %q does not exist.", input.Provider.ManifestLabel())
182+
return nil, errors.Errorf("repository for kubeconfig %q does not exist", input.Provider.ManifestLabel())
183183
}
184184
return fake.repositories[input.Provider.ManifestLabel()], nil
185185
}),
@@ -222,7 +222,7 @@ func newFakeCluster(kubeconfig cluster.Kubeconfig, configClient config.Client) *
222222
cluster.InjectPollImmediateWaiter(pollImmediateWaiter),
223223
cluster.InjectRepositoryFactory(func(provider config.Provider, configClient config.Client, options ...repository.Option) (repository.Client, error) {
224224
if _, ok := fake.repositories[provider.Name()]; !ok {
225-
return nil, errors.Errorf("Repository for kubeconfig %q does not exists.", provider.Name())
225+
return nil, errors.Errorf("repository for kubeconfig %q does not exist", provider.Name())
226226
}
227227
return fake.repositories[provider.Name()], nil
228228
}),

cmd/clusterctl/client/cluster/mover_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -929,7 +929,7 @@ func Test_objectMover_filesToObjs(t *testing.T) {
929929

930930
for _, fileName := range tt.files {
931931
path := filepath.Join(dir, fileName)
932-
file, err := os.Create(path)
932+
file, err := os.Create(path) //nolint:gosec // No security issue: unit test.
933933
if err != nil {
934934
return
935935
}

cmd/clusterctl/client/common.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,16 +87,14 @@ func parseProviderName(provider string) (name string, version string, err error)
8787
}
8888

8989
func validateDNS1123Label(label string) error {
90-
errs := validation.IsDNS1123Label(label)
91-
if len(errs) != 0 {
90+
if errs := validation.IsDNS1123Label(label); len(errs) != 0 {
9291
return errors.New(strings.Join(errs, "; "))
9392
}
9493
return nil
9594
}
9695

9796
func validateDNS1123Domanin(subdomain string) error {
98-
errs := validation.IsDNS1123Subdomain(subdomain)
99-
if len(errs) != 0 {
97+
if errs := validation.IsDNS1123Subdomain(subdomain); len(errs) != 0 {
10098
return errors.New(strings.Join(errs, "; "))
10199
}
102100
return nil

cmd/clusterctl/client/config/providers_client.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -298,8 +298,7 @@ func validateProvider(r Provider) error {
298298
return errors.Errorf("name %s must be used with the %s type (name: %s, type: %s)", ClusterAPIProviderName, clusterctlv1.CoreProviderType, r.Name(), r.Type())
299299
}
300300

301-
errMsgs := validation.IsDNS1123Subdomain(r.Name())
302-
if len(errMsgs) != 0 {
301+
if errMsgs := validation.IsDNS1123Subdomain(r.Name()); len(errMsgs) != 0 {
303302
return errors.Errorf("invalid provider name: %s", strings.Join(errMsgs, "; "))
304303
}
305304
if r.URL() == "" {

cmd/clusterctl/client/config/reader_viper.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ func downloadFile(url string, filepath string) error {
137137
ctx := context.TODO()
138138

139139
// Create the file
140-
out, err := os.Create(filepath)
140+
out, err := os.Create(filepath) //nolint:gosec // No security issue: filepath is safe.
141141
if err != nil {
142142
return errors.Wrapf(err, "failed to create the clusterctl config file %s", filepath)
143143
}

0 commit comments

Comments
 (0)