From 1784ee196766375aee3cf16025c8efced8b71a1d Mon Sep 17 00:00:00 2001 From: Arnab Baishnab Nipun <53988882+arnab-baishnab@users.noreply.github.com> Date: Fri, 12 Dec 2025 14:33:49 +0600 Subject: [PATCH] Use golangci-lint 2.x (#130) /cherry-pick Signed-off-by: Arnab Baishnab Nipun --- .golangci.yml | 28 ++++++++++++++++++++++++++++ Makefile | 2 +- go.mod | 4 +--- lintconf.yaml | 43 ------------------------------------------- pkg/util.go | 10 +++++----- 5 files changed, 35 insertions(+), 52 deletions(-) create mode 100644 .golangci.yml delete mode 100644 lintconf.yaml diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 00000000..cdd2defc --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,28 @@ +version: "2" +linters: + default: standard + enable: + - unparam + +formatters: + enable: + - gofmt + - goimports + settings: + gofmt: + rewrite-rules: + - pattern: 'interface{}' + replacement: 'any' + +issues: + max-same-issues: 100 + + exclude-files: + - generated.*\\.go + + exclude-dirs: + - client + - vendor + +run: + timeout: 10m diff --git a/Makefile b/Makefile index 5edde1ce..696177d7 100644 --- a/Makefile +++ b/Makefile @@ -281,7 +281,7 @@ lint: $(BUILD_DIRS) --env GO111MODULE=on \ --env GOFLAGS="-mod=vendor" \ $(BUILD_IMAGE) \ - golangci-lint run --enable $(ADDTL_LINTERS) --timeout=30m --exclude-files="generated.*\.go$\" --exclude-dirs-use-default --exclude-dirs=client,vendor + golangci-lint run $(BUILD_DIRS): @mkdir -p $@ diff --git a/go.mod b/go.mod index 2f76a6f7..38805257 100644 --- a/go.mod +++ b/go.mod @@ -1,8 +1,6 @@ module stash.appscode.dev/etcd -go 1.23.0 - -toolchain go1.24.4 +go 1.24.0 require ( github.com/spf13/cobra v1.8.0 diff --git a/lintconf.yaml b/lintconf.yaml deleted file mode 100644 index 860d7cb9..00000000 --- a/lintconf.yaml +++ /dev/null @@ -1,43 +0,0 @@ -# adapted from: https://github.com/helm/chart-testing/raw/master/etc/lintconf.yaml ---- -rules: - braces: - min-spaces-inside: 0 - max-spaces-inside: 0 - min-spaces-inside-empty: -1 - max-spaces-inside-empty: -1 - brackets: - min-spaces-inside: 0 - max-spaces-inside: 0 - min-spaces-inside-empty: -1 - max-spaces-inside-empty: -1 - colons: - max-spaces-before: 0 - max-spaces-after: 1 - commas: - max-spaces-before: 0 - min-spaces-after: 1 - max-spaces-after: 1 - comments: - require-starting-space: true - min-spaces-from-content: 1 - document-end: disable - document-start: disable # No --- to start a file - empty-lines: - max: 2 - max-start: 0 - max-end: 0 - hyphens: - max-spaces-after: 1 - indentation: - spaces: consistent - indent-sequences: whatever # - list indentation will handle both indentation and without - check-multi-line-strings: false - key-duplicates: enable - line-length: disable # Lines can be any length - new-line-at-end-of-file: enable - new-lines: - type: unix - trailing-spaces: enable - truthy: - level: warning diff --git a/pkg/util.go b/pkg/util.go index 00ad3add..29ecd05d 100644 --- a/pkg/util.go +++ b/pkg/util.go @@ -194,7 +194,7 @@ func (opt *options) createRestorePods(memberPod corev1.Pod, args []string) (*cor for _, vol := range memberPod.Spec.Volumes { if vol.Name == dataVolume { - pvcName = vol.VolumeSource.PersistentVolumeClaim.ClaimName + pvcName = vol.PersistentVolumeClaim.ClaimName break } } @@ -285,7 +285,7 @@ func (opt *options) replaceOldDataWithRestoredData(restorePods []corev1.Pod) err command := []string{StashEtcd, "replace"} command = append(command, "--data-dir="+opt.etcd.dataDir) - execOut, err := opt.execCommandOnPod(&pod, pod.ObjectMeta.Name, command) + execOut, err := opt.execCommandOnPod(&pod, pod.Name, command) if err != nil { return err } @@ -388,7 +388,7 @@ func (opt *options) getEtcdMemberPods() ([]corev1.Pod, error) { } return []corev1.Pod{*pod}, nil default: - return nil, errors.New("Could not find any member for etcd server") + return nil, errors.New("could not find any member for etcd server") } } @@ -422,7 +422,7 @@ func (opt *options) execCommandOnPod(pod *corev1.Pod, containerName string, comm Tty: true, }) if err != nil { - return nil, fmt.Errorf("Could not execute: %v, reason: %s", err, execErr.String()) + return nil, fmt.Errorf("could not execute: %v, reason: %s", err, execErr.String()) } return execOut.Bytes(), nil @@ -545,7 +545,7 @@ func (opt *options) getCredential(appBinding *appcatalog.AppBinding) ([]string, tlsArgs = fmt.Sprintf("--key=%v", filepath.Join(opt.setupOptions.ScratchDir, EtcdClientKeyFile)) args = append(args, tlsArgs) } else { - return nil, errors.New("Client cert and client key needed for TLS secured operation") + return nil, errors.New("client cert and client key needed for TLS secured operation") } return args, nil