Skip to content

Conversation

@jmckulk
Copy link
Collaborator

@jmckulk jmckulk commented Sep 22, 2021

The following changes fix linter errors and warnings that appear for golangci-lint version v1.42.0.

Other information:
[sc-11398]

@jmckulk jmckulk force-pushed the chore_golang_ci_lint branch from 2d74bab to ec69dd3 Compare September 22, 2021 19:48
"gotest.tools/v3/assert"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯 corev1 What a doozie! 👏🏻

❓ We can enforce it with importas. What do you think of adding these rules?

diff --git .golangci.yaml .golangci.yaml index fca0785dc..09a82f418 100644 --- .golangci.yaml +++ .golangci.yaml @@ -7,6 +7,7 @@ linters: enable: - gomodguard - gosimple + - importas - misspell presets: - bugs @@ -28,6 +29,14 @@ linters-settings: reason: > k8s.io/kubernetes is for managing dependencies of the Kubernetes project, i.e. building kubelet and kubeadm. + importas: + alias: + - pkg: k8s.io/api/(\w+)/(v[\w\d]+) + alias: $1$2 + - pkg: k8s.io/apimachinery/pkg/apis/(\w+)/(v[\w\d]+) + alias: $1$2 + - pkg: k8s.io/apimachinery/pkg/api/errors + alias: apierrors run: build-tags:

I think we already comply with the first two rules. The last one requires a couple of changes in internal/controller/postgrescluster/controller_ref_manager.go and internal/controller/postgrescluster/pgbackrest_test.go.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah figured it would be good to go ahead and get that out of the way!

I like importas 👍 i'll add that in. Are there any other rules we can add?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

None that I know of right off. Very open to adding more later.

@jmckulk jmckulk force-pushed the chore_golang_ci_lint branch 2 times, most recently from df3d5a8 to 6d41f5a Compare September 24, 2021 16:35
@jmckulk jmckulk marked this pull request as ready for review September 24, 2021 16:41
@jmckulk jmckulk force-pushed the chore_golang_ci_lint branch from 4ff7f04 to 9887d2f Compare September 24, 2021 18:01
Makezero checks to prevent bugs caused by initializing a slice with non-constant length and later appending to it. internal/patroni/config.go:257:11: append to slice `hba` with non-zero initialized length (makezero) hba = append(hba, value) ^ internal/patroni/config.go:264:10: append to slice `hba` with non-zero initialized length (makezero) hba = append(hba, pgHBAs.Default[i].String())
internal/controller/postgrescluster/pki_test.go:303:21: ineffectual assignment to err (ineffassign)	intent, existing, err := createInstanceSecrets(ctx, tClient, instance, initialRoot) internal/controller/postgrescluster/patroni_test.go:363:2: ineffectual assignment to ctx (ineffassign) ctx := context.Background()
internal/controller/postgrescluster/patroni.go:274:4: error is nil but it returns error (nilerr) return custom, err ^ internal/controller/postgrescluster/patroni.go:334:3: error is nil but it returns error (nilerr) return intent, err
Runs `golangci-lint run --fix` to re-order package imports. Fix is wrongly removing some packages so they had to be manually fixed. Link: golangci/golangci-lint#2161
@jmckulk jmckulk force-pushed the chore_golang_ci_lint branch from 9887d2f to 985ff42 Compare September 24, 2021 19:14
@jmckulk jmckulk merged commit 4ed0000 into CrunchyData:master Sep 24, 2021
jmckulk added a commit to jmckulk/postgres-operator that referenced this pull request Oct 12, 2021
The linter was pinned to 1.42.0 until we update to go1.17 Issue: [sc12565] See: CrunchyData#2717
jmckulk added a commit that referenced this pull request Oct 14, 2021
The linter was pinned to 1.42.0 until we update to go1.17 Issue: [sc12565] See: #2717
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants