Skip to content

Commit 475e797

Browse files
Upgrade golang-ci from v1 to latest v2 (#2045)
1 parent 5690d4b commit 475e797

File tree

22 files changed

+234
-877
lines changed

22 files changed

+234
-877
lines changed

.bingo/Variables.mk

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@ $(CRD_REF_DOCS): $(BINGO_DIR)/crd-ref-docs.mod
4141
@echo "(re)installing $(GOBIN)/crd-ref-docs-v0.1.0"
4242
@cd $(BINGO_DIR) && GOWORK=off $(GO) build -mod=mod -modfile=crd-ref-docs.mod -o=$(GOBIN)/crd-ref-docs-v0.1.0 "github.com/elastic/crd-ref-docs"
4343

44-
GOLANGCI_LINT := $(GOBIN)/golangci-lint-v1.64.8
44+
GOLANGCI_LINT := $(GOBIN)/golangci-lint-v2.1.6
4545
$(GOLANGCI_LINT): $(BINGO_DIR)/golangci-lint.mod
4646
@# Install binary/ries using Go 1.14+ build command. This is using bwplotka/bingo-controlled, separate go module with pinned dependencies.
47-
@echo "(re)installing $(GOBIN)/golangci-lint-v1.64.8"
48-
@cd $(BINGO_DIR) && GOWORK=off $(GO) build -mod=mod -modfile=golangci-lint.mod -o=$(GOBIN)/golangci-lint-v1.64.8 "github.com/golangci/golangci-lint/cmd/golangci-lint"
47+
@echo "(re)installing $(GOBIN)/golangci-lint-v2.1.6"
48+
@cd $(BINGO_DIR) && GOWORK=off $(GO) build -mod=mod -modfile=golangci-lint.mod -o=$(GOBIN)/golangci-lint-v2.1.6 "github.com/golangci/golangci-lint/v2/cmd/golangci-lint"
4949

5050
GORELEASER := $(GOBIN)/goreleaser-v1.26.2
5151
$(GORELEASER): $(BINGO_DIR)/goreleaser.mod

.bingo/golangci-lint.mod

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
module _ // Auto generated by https://github.com/bwplotka/bingo. DO NOT EDIT
22

3-
go 1.23.0
3+
go 1.24.2
44

5-
require github.com/golangci/golangci-lint v1.64.8 // cmd/golangci-lint
5+
toolchain go1.24.3
6+
7+
require github.com/golangci/golangci-lint/v2 v2.1.6 // cmd/golangci-lint

.bingo/golangci-lint.sum

Lines changed: 121 additions & 765 deletions
Large diffs are not rendered by default.

.bingo/variables.env

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ CRD_DIFF="${GOBIN}/crd-diff-v0.2.0"
1616

1717
CRD_REF_DOCS="${GOBIN}/crd-ref-docs-v0.1.0"
1818

19-
GOLANGCI_LINT="${GOBIN}/golangci-lint-v1.64.8"
19+
GOLANGCI_LINT="${GOBIN}/golangci-lint-v2.1.6"
2020

2121
GORELEASER="${GOBIN}/goreleaser-v1.26.2"
2222

.github/workflows/sanity.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,4 @@ jobs:
2929
go-version-file: "go.mod"
3030

3131
- name: Run golangci linting checks
32-
run: make lint GOLANGCI_LINT_ARGS="--out-format colored-line-number"
32+
run: make lint

.golangci.yaml

Lines changed: 72 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,74 @@
1-
########
2-
# NOTE
3-
#
4-
# This file is duplicated in the following repos:
5-
# - operator-framework/kubectl-operator
6-
# - operator-framework/catalogd
7-
# - operator-framework/operator-controller
8-
#
9-
# If you are making a change, please make it in ALL
10-
# of the above repositories!
11-
#
12-
# TODO: Find a way to have a shared golangci config.
13-
########
14-
15-
run:
16-
# Default timeout is 1m, up to give more room
17-
timeout: 4m
18-
19-
linters:
20-
enable:
21-
- asciicheck
22-
- bodyclose
23-
- errorlint
24-
- gci
25-
- gofmt
26-
- govet
27-
- gosec
28-
- importas
29-
- misspell
30-
- nestif
31-
- nonamedreturns
32-
- prealloc
33-
- stylecheck
34-
- testifylint
35-
- tparallel
36-
- unconvert
37-
- unparam
38-
- unused
39-
- whitespace
40-
41-
linters-settings:
42-
gci:
43-
sections:
44-
- standard
45-
- dot
46-
- default
47-
- prefix(github.com/operator-framework)
48-
- localmodule
49-
custom-order: true
50-
51-
errorlint:
52-
errorf: false
53-
54-
importas:
55-
alias:
56-
- pkg: k8s.io/apimachinery/pkg/apis/meta/v1
57-
alias: metav1
58-
- pkg: k8s.io/apimachinery/pkg/api/errors
59-
alias: apierrors
60-
- pkg: k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1
61-
alias: apiextensionsv1
62-
- pkg: k8s.io/apimachinery/pkg/util/runtime
63-
alias: utilruntime
64-
- pkg: "^k8s\\.io/api/([^/]+)/(v[^/]+)$"
65-
alias: $1$2
66-
- pkg: sigs.k8s.io/controller-runtime
67-
alias: ctrl
68-
- pkg: github.com/blang/semver/v4
69-
alias: bsemver
70-
- pkg: "^github.com/operator-framework/operator-controller/internal/util/([^/]+)$"
71-
alias: "${1}util"
72-
1+
version: "2"
732
output:
743
formats:
75-
- format: tab
4+
tab:
5+
path: stdout
6+
colors: false
7+
linters:
8+
enable:
9+
- asciicheck
10+
- bodyclose
11+
- errorlint
12+
- gosec
13+
- importas
14+
- misspell
15+
- nestif
16+
- nonamedreturns
17+
- prealloc
18+
- staticcheck
19+
- testifylint
20+
- tparallel
21+
- unconvert
22+
- unparam
23+
- whitespace
24+
settings:
25+
errorlint:
26+
errorf: false
27+
importas:
28+
alias:
29+
- pkg: k8s.io/apimachinery/pkg/apis/meta/v1
30+
alias: metav1
31+
- pkg: k8s.io/apimachinery/pkg/api/errors
32+
alias: apierrors
33+
- pkg: k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1
34+
alias: apiextensionsv1
35+
- pkg: k8s.io/apimachinery/pkg/util/runtime
36+
alias: utilruntime
37+
- pkg: ^k8s\.io/api/([^/]+)/(v[^/]+)$
38+
alias: $1$2
39+
- pkg: sigs.k8s.io/controller-runtime
40+
alias: ctrl
41+
- pkg: github.com/blang/semver/v4
42+
alias: bsemver
43+
- pkg: ^github.com/operator-framework/operator-controller/internal/util/([^/]+)$
44+
alias: ${1}util
45+
exclusions:
46+
generated: lax
47+
presets:
48+
- comments
49+
- common-false-positives
50+
- legacy
51+
- std-error-handling
52+
paths:
53+
- third_party$
54+
- builtin$
55+
- examples$
56+
formatters:
57+
enable:
58+
- gci
59+
- gofmt
60+
settings:
61+
gci:
62+
sections:
63+
- standard
64+
- dot
65+
- default
66+
- prefix(github.com/operator-framework)
67+
- localmodule
68+
custom-order: true
69+
exclusions:
70+
generated: lax
71+
paths:
72+
- third_party$
73+
- builtin$
74+
- examples$

api/v1/clustercatalog_types_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ func TestImageSourceCELValidationRules(t *testing.T) {
149149
obj, err := runtime.DefaultUnstructuredConverter.ToUnstructured(&tc.spec) //nolint:gosec
150150
require.NoError(t, err)
151151
errs := validator(obj, nil)
152-
require.Equal(t, len(tc.wantErrs), len(errs), "want", tc.wantErrs, "got", errs)
152+
require.Len(t, errs, len(tc.wantErrs), "want", tc.wantErrs, "got", errs)
153153
for i := range tc.wantErrs {
154154
got := errs[i].Error()
155155
assert.Equal(t, tc.wantErrs[i], got)
@@ -242,7 +242,7 @@ func TestResolvedImageSourceCELValidation(t *testing.T) {
242242
} {
243243
t.Run(name, func(t *testing.T) {
244244
errs := validator(tc.spec.Ref, nil)
245-
require.Equal(t, len(tc.wantErrs), len(errs), "want", tc.wantErrs, "got", errs)
245+
require.Len(t, errs, len(tc.wantErrs), "want", tc.wantErrs, "got", errs)
246246
for i := range tc.wantErrs {
247247
got := errs[i].Error()
248248
assert.Equal(t, tc.wantErrs[i], got)
@@ -286,7 +286,7 @@ func TestClusterCatalogURLsCELValidation(t *testing.T) {
286286
t.Run(name, func(t *testing.T) {
287287
errs := validator(tc.urls.Base, nil)
288288
fmt.Println(errs)
289-
require.Equal(t, len(tc.wantErrs), len(errs))
289+
require.Len(t, errs, len(tc.wantErrs))
290290
for i := range tc.wantErrs {
291291
got := errs[i].Error()
292292
assert.Equal(t, tc.wantErrs[i], got)
@@ -327,7 +327,7 @@ func TestSourceCELValidation(t *testing.T) {
327327
require.NoError(t, err)
328328
errs := validator(obj, nil)
329329
fmt.Println(errs)
330-
require.Equal(t, len(tc.wantErrs), len(errs))
330+
require.Len(t, errs, len(tc.wantErrs))
331331
for i := range tc.wantErrs {
332332
got := errs[i].Error()
333333
assert.Equal(t, tc.wantErrs[i], got)
@@ -368,7 +368,7 @@ func TestResolvedSourceCELValidation(t *testing.T) {
368368
obj, err := runtime.DefaultUnstructuredConverter.ToUnstructured(&tc.source) //nolint:gosec
369369
require.NoError(t, err)
370370
errs := validator(obj, nil)
371-
require.Equal(t, len(tc.wantErrs), len(errs))
371+
require.Len(t, errs, len(tc.wantErrs))
372372
for i := range tc.wantErrs {
373373
got := errs[i].Error()
374374
assert.Equal(t, tc.wantErrs[i], got)

hack/tools/crd-generator/main.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,12 +120,12 @@ func runGenerator(args ...string) {
120120
crdRaw := parser.CustomResourceDefinitions[groupKind]
121121

122122
// Inline version of "addAttribution(&crdRaw)" ...
123-
if crdRaw.ObjectMeta.Annotations == nil {
124-
crdRaw.ObjectMeta.Annotations = map[string]string{}
123+
if crdRaw.Annotations == nil {
124+
crdRaw.Annotations = map[string]string{}
125125
}
126-
crdRaw.ObjectMeta.Annotations[FeatureSetAnnotation] = channel
126+
crdRaw.Annotations[FeatureSetAnnotation] = channel
127127
if ctVer != "" {
128-
crdRaw.ObjectMeta.Annotations[VersionAnnotation] = ctVer
128+
crdRaw.Annotations[VersionAnnotation] = ctVer
129129
}
130130

131131
// Prevent the top level metadata for the CRD to be generated regardless of the intention in the arguments

internal/catalogd/controllers/core/clustercatalog_controller.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ func (r *ClusterCatalogReconciler) Reconcile(ctx context.Context, req ctrl.Reque
9595
defer l.Info("reconcile ending")
9696

9797
existingCatsrc := ocv1.ClusterCatalog{}
98-
if err := r.Client.Get(ctx, req.NamespacedName, &existingCatsrc); err != nil {
98+
if err := r.Get(ctx, req.NamespacedName, &existingCatsrc); err != nil {
9999
return ctrl.Result{}, client.IgnoreNotFound(err)
100100
}
101101

@@ -134,7 +134,7 @@ func (r *ClusterCatalogReconciler) Reconcile(ctx context.Context, req ctrl.Reque
134134
reconciledCatsrc.Finalizers = finalizers
135135

136136
if updateFinalizers {
137-
if err := r.Client.Update(ctx, reconciledCatsrc); err != nil {
137+
if err := r.Update(ctx, reconciledCatsrc); err != nil {
138138
reconcileErr = errors.Join(reconcileErr, fmt.Errorf("error updating finalizers: %v", err))
139139
}
140140
}

internal/catalogd/storage/localdir_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ func TestMetasEndpoint(t *testing.T) {
401401
require.Equal(t, tc.expectedStatusCode, resp.StatusCode)
402402
actualContent, err = io.ReadAll(resp.Body)
403403
require.NoError(t, err)
404-
require.Equal(t, "", string(actualContent)) // HEAD should not return a body
404+
require.Empty(t, string(actualContent)) // HEAD should not return a body
405405
resp.Body.Close()
406406

407407
// And make sure any other method is not allowed

0 commit comments

Comments
 (0)