From 30bd1401863ca56e3bbce658e20f78ccf58f8960 Mon Sep 17 00:00:00 2001 From: Iamrushabhshahh Date: Thu, 15 Oct 2026 02:30:04 +0530 Subject: [PATCH 1/3] ci: bump Go to 1.26 and golangci-lint to v2 to unblock dependency updates Recent dependency updates need Go >= 1.25, but CI is pinned to Go 1.22 and golangci-lint v1.56.2. golangci-lint v1 cannot load a module that targets Go 1.25 and fails with "unsupported version: 2" typecheck errors. - Set up Go 1.26 in the test, e2e and release workflows, and build the Docker image with golang:1.26. - Move to golangci-lint v2.14.0 with golangci-lint-action@v9 and migrate .golangci.yml to the v2 format, keeping the v1 rule set. - Update actions/checkout, actions/setup-go and actions/setup-node to v7 (Node 24 runtime) and actions-goveralls to v1.11.2. - Fix the go vet findings that newer Go toolchains report: slog calls with a missing key, and non-constant format strings. Co-authored-by: Iamrushabhshahh Signed-off-by: Iamrushabhshahh --- .github/workflows/constraint.yaml | 2 +- .github/workflows/e2e-test.yml | 12 +- .github/workflows/release.yaml | 28 ++--- .github/workflows/test.yaml | 22 ++-- .golangci.yml | 105 ++++++++++++------ Dockerfile | 2 +- Makefile | 6 +- pkg/engine/operation/models/change.go | 2 +- pkg/engine/operation/watch.go | 2 +- .../runtime/terraform/tfops/tferrors.go | 2 +- pkg/server/handler/endpoint/endpoint.go | 2 +- pkg/server/route/route.go | 20 ++-- third_party/dyff/output_human.go | 22 ++-- 13 files changed, 129 insertions(+), 98 deletions(-) diff --git a/.github/workflows/constraint.yaml b/.github/workflows/constraint.yaml index 92ea44308..43af9d147 100644 --- a/.github/workflows/constraint.yaml +++ b/.github/workflows/constraint.yaml @@ -15,7 +15,7 @@ jobs: if: contains(fromJSON('["pull_request"]'), github.event_name) steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v7 with: fetch-depth: 0 - uses: wagoid/commitlint-github-action@v5 diff --git a/.github/workflows/e2e-test.yml b/.github/workflows/e2e-test.yml index a2c7d0556..86a5e7db4 100644 --- a/.github/workflows/e2e-test.yml +++ b/.github/workflows/e2e-test.yml @@ -16,13 +16,13 @@ jobs: runs-on: ubuntu-latest steps: - name: checkout code - uses: actions/checkout@v2 + uses: actions/checkout@v7 with: fetch-depth: 0 - name: install Go - uses: actions/setup-go@v2 + uses: actions/setup-go@v7 with: - go-version: 1.22 + go-version: '1.26' - name: Setup K3d uses: nolar/setup-k3d-k3s@v1.0.8 - name: run e2e @@ -33,13 +33,13 @@ jobs: runs-on: windows-latest steps: - name: checkout code - uses: actions/checkout@v2 + uses: actions/checkout@v7 with: fetch-depth: 0 - name: install Go - uses: actions/setup-go@v2 + uses: actions/setup-go@v7 with: - go-version: 1.22 + go-version: '1.26' - name: install K3d shell: powershell run: | diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 52596c8e4..f03f7cea7 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -13,13 +13,13 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v7 with: fetch-depth: 0 - - name: Set up Go 1.22 - uses: actions/setup-go@v2 + - name: Set up Go 1.26 + uses: actions/setup-go@v7 with: - go-version: 1.22 + go-version: '1.26' - name: Running go tests with coverage env: GO111MODULE: on @@ -33,32 +33,32 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v7 with: fetch-depth: 0 - - name: Set up Go 1.22 - uses: actions/setup-go@v2 + - name: Set up Go 1.26 + uses: actions/setup-go@v7 with: - go-version: 1.22 + go-version: '1.26' - name: golangci-lint - uses: golangci/golangci-lint-action@v3 + uses: golangci/golangci-lint-action@v9 with: # Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version - version: v1.56.2 + version: v2.14.0 Publish: # Pack and publish image to Docker Hub and GitHub Release runs-on: ubuntu-latest needs: [Test, Lint] steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v7 with: fetch-depth: 0 - name: Set up Go - uses: actions/setup-go@v2 + uses: actions/setup-go@v7 with: - go-version: 1.22 + go-version: '1.26' - name: Set up Node.js - uses: actions/setup-node@v2 + uses: actions/setup-node@v7 with: node-version: '18' - name: Install npm packages and build UI diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 1299963de..571092703 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -14,13 +14,13 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v7 with: fetch-depth: 0 - - name: Set up Go 1.22 - uses: actions/setup-go@v2 + - name: Set up Go 1.26 + uses: actions/setup-go@v7 with: - go-version: 1.22 + go-version: '1.26' - run: go build ./... - run: go vet ./... @@ -30,7 +30,7 @@ jobs: GO111MODULE: on run: make cover - name: Send coverage - uses: shogo82148/actions-goveralls@v1.8.0 + uses: shogo82148/actions-goveralls@v1.11.2 with: path-to-profile: coverage.out @@ -39,15 +39,15 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v7 with: fetch-depth: 0 - - name: Set up Go 1.22 - uses: actions/setup-go@v2 + - name: Set up Go 1.26 + uses: actions/setup-go@v7 with: - go-version: 1.22 + go-version: '1.26' - name: golangci-lint - uses: golangci/golangci-lint-action@v3 + uses: golangci/golangci-lint-action@v9 with: # Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version - version: v1.56.2 \ No newline at end of file + version: v2.14.0 \ No newline at end of file diff --git a/.golangci.yml b/.golangci.yml index e770009ca..b061d2682 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,40 +1,32 @@ -# This file contains all available configuration options -# with their default values. -# For complete .golangci.yml configuration, reference: https://golangci-lint.run/usage/configuration/#config-file +# golangci-lint v2 configuration. +# For the full reference, see: https://golangci-lint.run/usage/configuration/ +version: "2" -# options for analysis running run: timeout: 10m linters: - disable-all: true + default: none enable: # please keep this alphabetized - # Don't use soon to deprecated[1] linters that lead to false - # https://github.com/golangci/golangci-lint/issues/1841 - # - deadcode - # - structcheck - # - varcheck - - ineffassign - - staticcheck - - unused - - gosimple - - govet - - gofumpt + # gosimple and stylecheck are part of staticcheck since golangci-lint v2. + # exportloopref was removed: Go 1.22 loop variable semantics make it obsolete. + # typecheck is always on and can no longer be listed. - bodyclose - # - depguard - dogsled - dupl - - exportloopref - gocritic -# - misspell + - govet + - ineffassign + # - misspell - nolintlint - prealloc - predeclared - - stylecheck + - staticcheck - tparallel - - typecheck - unconvert + - unused - whitespace + # - depguard # - wsl # - revive # - unparam @@ -44,20 +36,59 @@ linters: # - thelper # - goconst # - errcheck + settings: + govet: + disable: + # New in recent Go releases; not enabled under golangci-lint v1. + - inline + staticcheck: + # Default checks, minus the QF* quick fixes that staticcheck gained when + # gosimple and stylecheck were merged into it in golangci-lint v2. + checks: + - all + - -ST1000 + - -ST1003 + - -ST1016 + - -ST1020 + - -ST1021 + - -ST1022 + - -QF* + exclusions: + generated: lax + # Keep the exclusions that golangci-lint v1 applied by default. + presets: + - comments + - common-false-positives + - legacy + - std-error-handling + rules: + - path: (.+)\.go$ + text: "G306: Expect WriteFile permissions to be 0600 or less" + - path: (.+)\.go$ + text: "ST1018: string literal contains Unicode control characters, consider using escape sequences instead" + - path: (.+)\.go$ + text: "ifElseChain: rewrite if-else to switch statement" + - path: (.+)\.go$ + text: "S1000: should use for range instead of for { select {} }" + - path: (.+)\.go$ + text: "SA4004: the surrounding loop is unconditionally terminated" + - path: (.+)\.go$ + text: "copylocks: call of c\\.Post copies lock value: kcl-lang\\.io/kcl-go/pkg/spec/gpyrpc\\.Ping_Args contains google\\.golang\\.org/protobuf/internal/impl\\.MessageState contains sync\\.Mutex" + paths: + - third_party$ + - builtin$ + - examples$ -linters-settings: - gofumpt: - # Select the Go version to target. The default is `1.15`. - lang-version: "1.22" - # Choose whether or not to use the extra rules that are disabled - # by default - extra-rules: false - -issues: - exclude: - - "G306: Expect WriteFile permissions to be 0600 or less" - - "ST1018: string literal contains Unicode control characters, consider using escape sequences instead" - - "ifElseChain: rewrite if-else to switch statement" - - "S1000: should use for range instead of for { select {} }" - - "SA4004: the surrounding loop is unconditionally terminated" - - "copylocks: call of c\\.Post copies lock value: kcl-lang\\.io/kcl-go/pkg/spec/gpyrpc\\.Ping_Args contains google\\.golang\\.org/protobuf/internal/impl\\.MessageState contains sync\\.Mutex" +formatters: + enable: + - gofumpt + settings: + gofumpt: + # The target Go version is read from go.mod. + extra-rules: false + exclusions: + generated: lax + paths: + - third_party$ + - builtin$ + - examples$ diff --git a/Dockerfile b/Dockerfile index 8ff6d90bc..d787bdd19 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,7 +5,7 @@ WORKDIR /src/ui RUN npm install RUN npm run build -FROM golang:1.22 AS build +FROM golang:1.26 AS build COPY / /src COPY --from=portal-builder /src/ui/build /src/ui/build WORKDIR /src diff --git a/Makefile b/Makefile index 7b507ac98..90ccefc00 100644 --- a/Makefile +++ b/Makefile @@ -13,7 +13,7 @@ RUN_IN_DOCKER+=-w /root/kusion ${KCLVM_BUILDER} GOFORMATER ?= gofumpt GOFORMATER_VERSION ?= v0.2.0 GOLINTER ?= golangci-lint -GOLINTER_VERSION ?= v1.56.2 +GOLINTER_VERSION ?= v2.14.0 COVER_FILE ?= coverage.out SOURCE_PATHS ?= ./pkg/... @@ -63,11 +63,11 @@ format: ## Format source code @for path in $(SOURCE_PATHS); do ${GOFORMATER} -l -w -e `echo $${path} | cut -b 3- | rev | cut -b 5- | rev`; done; lint: ## Lint, will not fix but sets exit code on error - @which $(GOLINTER) > /dev/null || (echo "Installing $(GOLINTER)@$(GOLINTER_VERSION) ..."; go install github.com/golangci/golangci-lint/cmd/golangci-lint@$(GOLINTER_VERSION) && echo -e "Installation complete!\n") + @which $(GOLINTER) > /dev/null || (echo "Installing $(GOLINTER)@$(GOLINTER_VERSION) ..."; go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@$(GOLINTER_VERSION) && echo -e "Installation complete!\n") $(GOLINTER) run --timeout=10m $(SOURCE_PATHS) lint-fix: ## Lint, will try to fix errors and modify code - @which $(GOLINTER) > /dev/null || (echo "Installing $(GOLINTER)@$(GOLINTER_VERSION) ..."; go install github.com/golangci/golangci-lint/cmd/golangci-lint@$(GOLINTER_VERSION) && echo -e "Installation complete!\n") + @which $(GOLINTER) > /dev/null || (echo "Installing $(GOLINTER)@$(GOLINTER_VERSION) ..."; go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@$(GOLINTER_VERSION) && echo -e "Installation complete!\n") $(GOLINTER) run --timeout=10m $(SOURCE_PATHS) --fix doc: ## Start the documentation server with godoc diff --git a/pkg/engine/operation/models/change.go b/pkg/engine/operation/models/change.go index 74526b1f0..23eabb4ae 100644 --- a/pkg/engine/operation/models/change.go +++ b/pkg/engine/operation/models/change.go @@ -267,7 +267,7 @@ func (o *ChangeOrder) PromptDetails(ui *terminal.UI) (string, error) { WithOnInterruptFunc(func() { hint := `Interruption during 'apply' or 'destroy' may result in a locked release file. Please use 'kusion release unlock' before executing the next operation.` - fmt.Printf("\n" + hint + "\n") + fmt.Print("\n" + hint + "\n") os.Exit(1) }). Show() diff --git a/pkg/engine/operation/watch.go b/pkg/engine/operation/watch.go index 8a7518a29..daab13c2c 100644 --- a/pkg/engine/operation/watch.go +++ b/pkg/engine/operation/watch.go @@ -68,7 +68,7 @@ func (wo *WatchOperation) Watch(req *WatchRequest) error { continue } if v1.IsErr(resp.Status) { - return fmt.Errorf(resp.Status.String()) + return errors.New(resp.Status.String()) } // Save watchers diff --git a/pkg/engine/runtime/terraform/tfops/tferrors.go b/pkg/engine/runtime/terraform/tfops/tferrors.go index 616cfea4d..a5f30a038 100644 --- a/pkg/engine/runtime/terraform/tfops/tferrors.go +++ b/pkg/engine/runtime/terraform/tfops/tferrors.go @@ -84,7 +84,7 @@ func parseTerraformInfo(infos []byte) ([]*TerraformInfo, error) { err := json.Unmarshal([]byte(v), terraformInfo) if err != nil { log.Debug("unmarshall TF output to TerraformInfo failed. Return the output directly.") - return nil, fmt.Errorf(string(infos)) + return nil, errors.New(string(infos)) } tfInfos = append(tfInfos, terraformInfo) } diff --git a/pkg/server/handler/endpoint/endpoint.go b/pkg/server/handler/endpoint/endpoint.go index 84d6bf908..e81567f10 100644 --- a/pkg/server/handler/endpoint/endpoint.go +++ b/pkg/server/handler/endpoint/endpoint.go @@ -49,7 +49,7 @@ func listEndpoints(ctx context.Context, r chi.Router) []string { // Populate the list of endpoints by walking through the router if err := chi.Walk(r, walkFunc); err != nil { - logger.Error(err.Error(), "Walking routes error", "error", err) + logger.Error("Walking routes error", "error", err) } // Sort the collected endpoints alphabetically diff --git a/pkg/server/route/route.go b/pkg/server/route/route.go index 32639b269..8271602dd 100644 --- a/pkg/server/route/route.go +++ b/pkg/server/route/route.go @@ -198,52 +198,52 @@ func setupRestAPIV1( // Set up the handlers for the resources. sourceHandler, err := source.NewHandler(sourceManager) if err != nil { - logger.Error(err.Error(), "Error creating source handler...", "error", err) + logger.Error("Error creating source handler...", "error", err) return } orgHandler, err := organization.NewHandler(organizationManager) if err != nil { - logger.Error(err.Error(), "Error creating org handler...", "error", err) + logger.Error("Error creating org handler...", "error", err) return } projectHandler, err := project.NewHandler(projectManager) if err != nil { - logger.Error(err.Error(), "Error creating project handler...", "error", err) + logger.Error("Error creating project handler...", "error", err) return } stackHandler, err := stack.NewHandler(stackManager, config.MaxAsyncConcurrent, config.MaxAsyncBuffer) if err != nil { - logger.Error(err.Error(), "Error creating stack handler...", "error", err) + logger.Error("Error creating stack handler...", "error", err) return } workspaceHandler, err := workspace.NewHandler(workspaceManager) if err != nil { - logger.Error(err.Error(), "Error creating workspace handler...", "error", err) + logger.Error("Error creating workspace handler...", "error", err) return } backendHandler, err := backend.NewHandler(backendManager) if err != nil { - logger.Error(err.Error(), "Error creating backend handler...", "error", err) + logger.Error("Error creating backend handler...", "error", err) return } resourceHandler, err := resource.NewHandler(resourceManager) if err != nil { - logger.Error(err.Error(), "Error creating resource handler...", "error", err) + logger.Error("Error creating resource handler...", "error", err) return } moduleHandler, err := module.NewHandler(moduleManager) if err != nil { - logger.Error(err.Error(), "Error creating module handler", "error", err) + logger.Error("Error creating module handler", "error", err) return } variableSetHandler, err := variableset.NewHandler(variableSetManager) if err != nil { - logger.Error(err.Error(), "Error creating variable set handler", "error", err) + logger.Error("Error creating variable set handler", "error", err) return } variableHandler, err := variable.NewHandler(variableManager) if err != nil { - logger.Error(err.Error(), "Error creating variable handler", "error", err) + logger.Error("Error creating variable handler", "error", err) return } diff --git a/third_party/dyff/output_human.go b/third_party/dyff/output_human.go index 573532bbe..a51919699 100644 --- a/third_party/dyff/output_human.go +++ b/third_party/dyff/output_human.go @@ -243,8 +243,8 @@ func (report *HumanReport) generateHumanDetailOutputModification(detail Detail) if fromType != toType { output.WriteString(yellow("%c type change from %s to %s\n", MODIFICATION, - italic(fromType), - italic(toType), + italic("%s", fromType), + italic("%s", toType), )) } else { output.WriteString(yellow("%c value change\n", @@ -272,7 +272,7 @@ func (report *HumanReport) generateHumanDetailOutputModification(detail Detail) func (report *HumanReport) generateHumanDetailOutputOrderchange(detail Detail) (string, error) { var output bytes.Buffer - output.WriteString(yellow(fmt.Sprintf("%c order changed\n", ORDERCHANGE))) + output.WriteString(yellow("%c order changed\n", ORDERCHANGE)) switch detail.From.Kind { case yamlv3.SequenceNode: asStringList := func(sequenceNode *yamlv3.Node) []string { @@ -297,8 +297,8 @@ func (report *HumanReport) generateHumanDetailOutputOrderchange(detail Detail) ( } else { output.WriteString(CreateTableStyleString(" ", 2, - red(strings.Join(from, "\n")), - green(strings.Join(to, "\n")))) + red("%s", strings.Join(from, "\n")), + green("%s", strings.Join(to, "\n")))) } } @@ -344,12 +344,12 @@ func (report *HumanReport) highlightByLine(from, to string) string { if len(fromLines) == len(toLines) { for i := range fromLines { if fromLines[i] != toLines[i] { - fromLines[i] = red(fromLines[i]) - toLines[i] = green(toLines[i]) + fromLines[i] = red("%s", fromLines[i]) + toLines[i] = green("%s", toLines[i]) } else { - fromLines[i] = lightred(fromLines[i]) - toLines[i] = lightgreen(toLines[i]) + fromLines[i] = lightred("%s", fromLines[i]) + toLines[i] = lightgreen("%s", toLines[i]) } } @@ -359,8 +359,8 @@ func (report *HumanReport) highlightByLine(from, to string) string { } else { report.writeTextBlocks(&buf, 0, - red(createStringWithPrefix(" - ", from)), - green(createStringWithPrefix(" + ", to)), + red("%s", createStringWithPrefix(" - ", from)), + green("%s", createStringWithPrefix(" + ", to)), ) } From 60f53c696e51ea5e9a52c905fe892874a69a945c Mon Sep 17 00:00:00 2001 From: Iamrushabhshahh Date: Thu, 15 Oct 2026 02:58:49 +0530 Subject: [PATCH 2/3] test: bump mockey to v1.4.6 so unit tests link with Go 1.23+ mockey v1.2.10 links to runtime.sysAllocOS through go:linkname. Go 1.23 and later reject that at link time, so every test binary that imports mockey fails with: link: github.com/bytedance/mockey/internal/monkey/common: invalid reference to runtime.sysAllocOS mockey v1.4.6 supports Go 1.26 and still declares go 1.18, so the go directive in go.mod is unchanged. Co-authored-by: Iamrushabhshahh Signed-off-by: Iamrushabhshahh --- go.mod | 8 ++++---- go.sum | 27 ++++++++++++++++++++------- 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/go.mod b/go.mod index 7199f5545..cbdc21555 100644 --- a/go.mod +++ b/go.mod @@ -16,7 +16,7 @@ require ( github.com/aws/aws-sdk-go-v2/config v1.25.8 github.com/aws/aws-sdk-go-v2/service/secretsmanager v1.24.2 github.com/blang/semver/v4 v4.0.0 - github.com/bytedance/mockey v1.2.10 + github.com/bytedance/mockey v1.4.6 github.com/chai2010/gettext-go v1.0.2 github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc github.com/djherbis/times v1.5.0 @@ -239,7 +239,7 @@ require ( github.com/googleapis/enterprise-certificate-proxy v0.3.4 // indirect github.com/googleapis/gax-go/v2 v2.13.0 // indirect github.com/gookit/color v1.5.4 // indirect - github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 // indirect + github.com/gopherjs/gopherjs v1.12.80 // indirect github.com/gorilla/mux v1.8.1 // indirect github.com/gorilla/websocket v1.5.0 // indirect github.com/gosuri/uilive v0.0.4 // indirect @@ -307,8 +307,8 @@ require ( github.com/satori/go.uuid v1.2.0 // indirect github.com/sirupsen/logrus v1.9.3 github.com/skeema/knownhosts v1.3.0 // indirect - github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d // indirect - github.com/smartystreets/goconvey v1.6.4 // indirect + github.com/smartystreets/assertions v1.2.0 // indirect + github.com/smartystreets/goconvey v1.7.2 // indirect github.com/spf13/pflag v1.0.5 github.com/swaggo/files v1.0.1 // indirect github.com/thoas/go-funk v0.9.3 // indirect diff --git a/go.sum b/go.sum index 6452564b6..830484cb6 100644 --- a/go.sum +++ b/go.sum @@ -369,8 +369,8 @@ github.com/bugsnag/osext v0.0.0-20130617224835-0dd3f918b21b h1:otBG+dV+YK+Soembj github.com/bugsnag/osext v0.0.0-20130617224835-0dd3f918b21b/go.mod h1:obH5gd0BsqsP2LwDJ9aOkm/6J86V6lyAXCoQWGw3K50= github.com/bugsnag/panicwrap v0.0.0-20151223152923-e2c28503fcd0 h1:nvj0OLI3YqYXer/kZD8Ri1aaunCxIEsOst1BVJswV0o= github.com/bugsnag/panicwrap v0.0.0-20151223152923-e2c28503fcd0/go.mod h1:D/8v3kj0zr8ZAKg1AQ6crr+5VwKN5eIywRkfhyM/+dE= -github.com/bytedance/mockey v1.2.10 h1:4JlMpkm7HMXmTUtItid+iCu2tm61wvq+ca1X2u7ymzE= -github.com/bytedance/mockey v1.2.10/go.mod h1:bNrUnI1u7+pAc0TYDgPATM+wF2yzHxmNH+iDXg4AOCU= +github.com/bytedance/mockey v1.4.6 h1:pPkAFB6yiaaybvgp7DP1Rj4Ztiew3nsaMizoNkzsvNA= +github.com/bytedance/mockey v1.4.6/go.mod h1:1BPHF9sol5R1ud/+0VEHGQq/+i2lN+GTsr3O2Q9IENY= github.com/cenkalti/backoff/v3 v3.0.0 h1:ske+9nBpD9qZsTBoF41nW5L+AIuFBKMeze18XQ3eG1c= github.com/cenkalti/backoff/v3 v3.0.0/go.mod h1:cIeZDE3IrqwwJl6VUwCN6trj1oXrTS4rc0ij+ULvLYs= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= @@ -725,8 +725,9 @@ github.com/gookit/color v1.4.2/go.mod h1:fqRyamkC1W8uxl+lxCQxOT09l/vYfZ+QeiX3rKQ github.com/gookit/color v1.5.0/go.mod h1:43aQb+Zerm/BWh2GnrgOQm7ffz7tvQXEKV6BFMl7wAo= github.com/gookit/color v1.5.4 h1:FZmqs7XOyGgCAxmWyPslpiok1k05wmY3SJTytgvYFs0= github.com/gookit/color v1.5.4/go.mod h1:pZJOeOS8DM43rXbp4AZo1n9zCU2qjpcRko0b6/QJi9w= -github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8= github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= +github.com/gopherjs/gopherjs v1.12.80 h1:aC68NT6VK715WeUapxcPSFq/a3gZdS32HdtghdOIgAo= +github.com/gopherjs/gopherjs v1.12.80/go.mod h1:d55Q4EjGQHeJVms+9LGtXul6ykz5Xzx1E1gaXQXdimY= github.com/gorilla/handlers v1.5.1 h1:9lRY6j8DEeeBT10CvO9hGW0gmky0BprnvDI5vfhUHH4= github.com/gorilla/handlers v1.5.1/go.mod h1:t8XrUpc4KVXb7HGyJ4/cEnwQiaxrX/hz1Zv/4g96P1Q= github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So= @@ -790,6 +791,7 @@ github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1: github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= github.com/imdario/mergo v0.3.16 h1:wwQJbIsHYGMUyLSPrEq1CT16AhnhNJQ51+4fdHUnCl4= github.com/imdario/mergo v0.3.16/go.mod h1:WBLT9ZmE3lPoWsEzCh9LPo3TiwVN+ZKEjmz+hD27ysY= +github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOlocH6Fxy8MmwDt+yVQYULKfN0RoTN8A= @@ -944,6 +946,8 @@ github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8m github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f h1:y5//uYreIhSUg3J1GEMiLbxo1LJaP8RfCpH6pymGZus= github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f/go.mod h1:ZdcZmHo+o7JKHSa8/e818NopupXU1YMK5fe1lsApnBw= +github.com/neelance/astrewrite v0.0.0-20160511093645-99348263ae86/go.mod h1:kHJEU3ofeGjhHklVoIGuVj85JJwZ6kWPaJwCIxgnFmo= +github.com/neelance/sourcemap v0.0.0-20151028013722-8c68805598ab/go.mod h1:Qr6/a/Q4r9LP1IltGz7tA7iOK1WonHEYhu1HRBA7ZiM= github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A= github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE= github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU= @@ -1033,6 +1037,7 @@ github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJ github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ= github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88= github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ= +github.com/rogpeppe/go-internal v1.0.1-alpha.1/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8= github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4= @@ -1048,21 +1053,26 @@ github.com/segmentio/asm v1.2.0/go.mod h1:BqMnlJP91P8d+4ibuonYZw9mfnzI9HfxselHZr github.com/sergi/go-diff v1.2.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM= github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 h1:n661drycOFuPLCN3Uc8sB6B/s6Z4t2xvBgU1htSHuq8= github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3/go.mod h1:A0bzQcvG0E7Rwjx0REVgAGH58e96+X0MeOfepqsbeW4= +github.com/shurcooL/go v0.0.0-20180423040247-9e1955d9fb6e/go.mod h1:TDJrrUr11Vxrven61rcy3hJMUqaf/CLWYhHNPmT14Lk= +github.com/shurcooL/httpfs v0.0.0-20181222201310-74dc9339e414/go.mod h1:ZY1cvUeJuFPAdZ/B6v7RHavJWZn2YPVFQ1OSXhCGOkg= +github.com/shurcooL/vfsgen v0.0.0-20180915214035-33ae1944be3f/go.mod h1:TrYk7fJVaAttu97ZZKrO9UbRa8izdowaMIZcxYMbVaw= github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0= github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ= github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= github.com/skeema/knownhosts v1.3.0 h1:AM+y0rI04VksttfwjkSTNQorvGqmwATnvnAHpSgc0LY= github.com/skeema/knownhosts v1.3.0/go.mod h1:sPINvnADmT/qYH1kfv+ePMmOBTH6Tbl7b5LvTDjFK7M= -github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM= -github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= -github.com/smartystreets/goconvey v1.6.4 h1:fv0U8FUIMPNf1L9lnHLvLhgicrIVChEkdzIKYqbNC9s= -github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA= +github.com/smartystreets/assertions v1.2.0 h1:42S6lae5dvLc7BrLu/0ugRtcFVjoJNMC/N3yZFZkDFs= +github.com/smartystreets/assertions v1.2.0/go.mod h1:tcbTF8ujkAEcZ8TElKY+i30BzYlVhC/LOxJk7iOWnoo= +github.com/smartystreets/goconvey v1.7.2 h1:9RBaZCeXEQ3UselpuwUQHltGVXvdwm6cv1hgR6gDIPg= +github.com/smartystreets/goconvey v1.7.2/go.mod h1:Vw0tHAZW6lzCRk3xgdin6fKYcG+G3Pg9vgXWeJpQFMM= github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= github.com/spf13/afero v1.6.0 h1:xoax2sJ2DT8S8xA2paPFjDCScCNeWsg75VG0DLRreiY= github.com/spf13/afero v1.6.0/go.mod h1:Ai8FlHk4v/PARR026UzYexafAt9roJ7LcLMAmO6Z93I= +github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ= github.com/spf13/cobra v1.8.1 h1:e5/vxKd/rZsfSJMUX1agtjeTDf+qv1/JdBF8gg5k9ZM= github.com/spf13/cobra v1.8.1/go.mod h1:wHxEcudfqmLYa8iTfL+OuZPbBZkmvliBWKIezN3kD9Y= +github.com/spf13/pflag v1.0.1/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= github.com/spkg/bom v0.0.0-20160624110644-59b7046e48ad/go.mod h1:qLr4V1qq6nMqFKkMo8ZTx3f+BZEkzsRUY10Xsm2mwU0= @@ -1170,6 +1180,7 @@ go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8= go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E= golang.org/x/arch v0.11.0 h1:KXV8WWKCXm6tRpLirl2szsO5j/oOODwZf4hATmGVNs4= golang.org/x/arch v0.11.0/go.mod h1:FEVrYAQjsQXMVJ1nsMoVVXPZg6p2JE2mx8psSWTDQys= +golang.org/x/crypto v0.0.0-20180807104621-f027049dab0a/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= @@ -1334,6 +1345,7 @@ golang.org/x/sync v0.0.0-20220929204114-8fcdb60fdcc0/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.10.0 h1:3NQrjDixjgGwUOCaF8w2+VYHv0Ve/vGYSbdkTa98gmQ= golang.org/x/sync v0.10.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sys v0.0.0-20180807162357-acbc56fc7007/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -1459,6 +1471,7 @@ golang.org/x/time v0.7.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= +golang.org/x/tools v0.0.0-20190308142131-b40df0fb21c3/go.mod h1:25r3+/G6/xytQM8iWZKq3Hn0kr0rgFKPUNVEL/dr3z4= golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= golang.org/x/tools v0.0.0-20190312151545-0bb0c0a6e846/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= golang.org/x/tools v0.0.0-20190312170243-e65039ee4138/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= From 16f6af369682ea228884339f5f449a6f31724b62 Mon Sep 17 00:00:00 2001 From: Iamrushabhshahh Date: Thu, 15 Oct 2026 02:58:49 +0530 Subject: [PATCH 3/3] style: fix findings reported by golangci-lint v2 golangci-lint v2 ships newer staticcheck, predeclared, prealloc and gofumpt versions. Fix what they now report: - staticcheck SA1006: use errors.New for constant messages in the secrets providers. - staticcheck S1009: drop nil checks that len() already covers. - predeclared: rename local "max" variables, which shadow the Go 1.21 builtin, to "maxItems". - prealloc: preallocate slices in non-test code, and skip prealloc in _test.go files. - gofumpt: reformat k8s_printer.go. - Match third_party, builtin and examples directories the way v1 did. Co-authored-by: Iamrushabhshahh Signed-off-by: Iamrushabhshahh --- .golangci.yml | 20 +++++++---- pkg/cmd/project/list/options.go | 2 +- pkg/cmd/resource/show.go | 2 +- pkg/engine/operation/models/change.go | 6 ++-- pkg/engine/printers/printer/k8s_printer.go | 36 +++++++++---------- pkg/oci/client/client.go | 5 ++- .../alicloud/secretsmanager/secretsmanager.go | 5 +-- .../aws/secretsmanager/secretsmanager.go | 4 +-- .../providers/azure/keyvault/keyvault.go | 9 ++--- pkg/secrets/providers/fake/fake.go | 5 +-- pkg/secrets/providers/hashivault/vault.go | 3 +- .../secretsmanager/secretsmanager.go | 5 +-- pkg/util/yaml/yaml.go | 2 +- 13 files changed, 58 insertions(+), 46 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index b061d2682..9a654eff7 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -55,13 +55,19 @@ linters: - -QF* exclusions: generated: lax - # Keep the exclusions that golangci-lint v1 applied by default. + # Keep the exclusions and skipped directories that golangci-lint v1 + # applied by default. presets: - comments - common-false-positives - legacy - std-error-handling rules: + # Newer prealloc versions also flag slices that start from a literal. + # Allocation hints are not worth the churn in table-driven tests. + - path: _test\.go$ + linters: + - prealloc - path: (.+)\.go$ text: "G306: Expect WriteFile permissions to be 0600 or less" - path: (.+)\.go$ @@ -75,9 +81,9 @@ linters: - path: (.+)\.go$ text: "copylocks: call of c\\.Post copies lock value: kcl-lang\\.io/kcl-go/pkg/spec/gpyrpc\\.Ping_Args contains google\\.golang\\.org/protobuf/internal/impl\\.MessageState contains sync\\.Mutex" paths: - - third_party$ - - builtin$ - - examples$ + - (^|/)third_party($|/) + - (^|/)builtin($|/) + - (^|/)examples($|/) formatters: enable: @@ -89,6 +95,6 @@ formatters: exclusions: generated: lax paths: - - third_party$ - - builtin$ - - examples$ + - (^|/)third_party($|/) + - (^|/)builtin($|/) + - (^|/)examples($|/) diff --git a/pkg/cmd/project/list/options.go b/pkg/cmd/project/list/options.go index 48dd14d85..ca4d2dac9 100644 --- a/pkg/cmd/project/list/options.go +++ b/pkg/cmd/project/list/options.go @@ -132,7 +132,7 @@ func (o *Options) Validate(cmd *cobra.Command, args []string) error { // Run executes the `list` command. func (o *Options) Run() error { - if o.Workspace == nil || len(o.Workspace) == 0 { + if len(o.Workspace) == 0 { return fmt.Errorf("workspace is empty") } diff --git a/pkg/cmd/resource/show.go b/pkg/cmd/resource/show.go index 12f43e979..2d1995b8a 100644 --- a/pkg/cmd/resource/show.go +++ b/pkg/cmd/resource/show.go @@ -201,7 +201,7 @@ func (o *ShowOptions) Run() (err error) { return fmt.Errorf("no release found for project: %s, workspace: %s", *o.Project, *o.Workspace) } - if rel.Spec.Resources == nil || len(rel.Spec.Resources) == 0 { + if len(rel.Spec.Resources) == 0 { return fmt.Errorf("no resources found for project: %s, workspace: %s", *o.Project, *o.Workspace) } resourceMap := make(map[string]apiv1.Resource) diff --git a/pkg/engine/operation/models/change.go b/pkg/engine/operation/models/change.go index 23eabb4ae..c209f5ecd 100644 --- a/pkg/engine/operation/models/change.go +++ b/pkg/engine/operation/models/change.go @@ -223,7 +223,8 @@ func (p *Changes) Summary(writer io.Writer, noStyle bool) { // Create a fork of the default table, fill it with data and print it. // Data can also be generated and inserted later. tableHeader := []string{fmt.Sprintf("Stack: %s\nID", p.stack.Name), "\nAction"} - tableData := pterm.TableData{tableHeader} + tableData := make(pterm.TableData, 0, 1+len(p.Values())) + tableData = append(tableData, tableHeader) if noStyle { pterm.DisableStyling() @@ -246,7 +247,8 @@ func (p *Changes) Summary(writer io.Writer, noStyle bool) { func (o *ChangeOrder) PromptDetails(ui *terminal.UI) (string, error) { // Prepare the selects - options := []string{"all"} + options := make([]string, 0, len(o.StepKeys)+2) + options = append(options, "all") optionMaps := map[string]string{"all": "all"} for _, key := range o.StepKeys { diff --git a/pkg/engine/printers/printer/k8s_printer.go b/pkg/engine/printers/printer/k8s_printer.go index 895789fcd..3dd5a2a86 100644 --- a/pkg/engine/printers/printer/k8s_printer.go +++ b/pkg/engine/printers/printer/k8s_printer.go @@ -189,7 +189,7 @@ func formatEndpoints(endpoints *corev1.Endpoints, ports sets.Set[string]) string return "" } list := []string{} - max := 3 + maxItems := 3 more := false count := 0 for i := range endpoints.Subsets { @@ -197,7 +197,7 @@ func formatEndpoints(endpoints *corev1.Endpoints, ports sets.Set[string]) string if len(ss.Ports) == 0 { // It's possible to have headless services with no ports. for i := range ss.Addresses { - if len(list) == max { + if len(list) == maxItems { more = true } if !more { @@ -211,7 +211,7 @@ func formatEndpoints(endpoints *corev1.Endpoints, ports sets.Set[string]) string port := &ss.Ports[i] if ports == nil || ports.Has(port.Name) { for i := range ss.Addresses { - if len(list) == max { + if len(list) == maxItems { more = true } addr := &ss.Addresses[i] @@ -227,7 +227,7 @@ func formatEndpoints(endpoints *corev1.Endpoints, ports sets.Set[string]) string } ret := strings.Join(list, ",") if more { - return fmt.Sprintf("%s + %d more...", ret, count-max) + return fmt.Sprintf("%s + %d more...", ret, count-maxItems) } return ret } @@ -687,7 +687,7 @@ func printServiceAccount(obj *corev1.ServiceAccount) (string, bool) { } func printDeployment(obj *appsv1.Deployment) (string, bool) { - desiredReplicas := *(obj.Spec.Replicas) + desiredReplicas := *obj.Spec.Replicas updatedReplicas := obj.Status.UpdatedReplicas readyReplicas := obj.Status.ReadyReplicas availableReplicas := obj.Status.AvailableReplicas @@ -706,11 +706,11 @@ func printEndpointSlice(obj *discoveryv1.EndpointSlice) (string, bool) { func formatDiscoveryPorts(ports []discoveryv1.EndpointPort) string { list := []string{} - max := 3 + maxItems := 3 more := false count := 0 for _, port := range ports { - if len(list) < max { + if len(list) < maxItems { portNum := "*" if port.Port != nil { portNum = strconv.Itoa(int(*port.Port)) @@ -718,36 +718,36 @@ func formatDiscoveryPorts(ports []discoveryv1.EndpointPort) string { portNum = *port.Name } list = append(list, portNum) - } else if len(list) == max { + } else if len(list) == maxItems { more = true } count++ } - return listWithMoreString(list, more, count, max) + return listWithMoreString(list, more, count, maxItems) } func formatDiscoveryEndpoints(endpoints []discoveryv1.Endpoint) string { list := []string{} - max := 3 + maxItems := 3 more := false count := 0 for _, endpoint := range endpoints { for _, address := range endpoint.Addresses { - if len(list) < max { + if len(list) < maxItems { list = append(list, address) - } else if len(list) == max { + } else if len(list) == maxItems { more = true } count++ } } - return listWithMoreString(list, more, count, max) + return listWithMoreString(list, more, count, maxItems) } -func listWithMoreString(list []string, more bool, count, max int) string { +func listWithMoreString(list []string, more bool, count, maxItems int) string { ret := strings.Join(list, ",") if more { - return fmt.Sprintf("%s + %d more...", ret, count-max) + return fmt.Sprintf("%s + %d more...", ret, count-maxItems) } if ret == "" { ret = "" @@ -756,7 +756,7 @@ func listWithMoreString(list []string, more bool, count, max int) string { } func printReplicaSet(obj *appsv1.ReplicaSet) (string, bool) { - desiredReplicas := *(obj.Spec.Replicas) + desiredReplicas := *obj.Spec.Replicas currentReplicas := obj.Status.Replicas readyReplicas := obj.Status.ReadyReplicas return fmt.Sprintf("Desired: %d, Current: %d, Ready: %d", @@ -776,7 +776,7 @@ func printDaemonSet(obj *appsv1.DaemonSet) (string, bool) { } func printStatefulSet(obj *appsv1.StatefulSet) (string, bool) { - desiredReplicas := *(obj.Spec.Replicas) + desiredReplicas := *obj.Spec.Replicas readyReplicas := obj.Status.ReadyReplicas createTime := translateTimestampSince(obj.CreationTimestamp) return fmt.Sprintf("Ready: %d/%d, Age: %s", desiredReplicas, readyReplicas, createTime), @@ -880,7 +880,7 @@ func printIngress(obj *networkingv1.Ingress) (string, bool) { } func getIngressHosts(obj *networkingv1.Ingress) string { - results := []string{} + results := make([]string, 0, len(obj.Spec.Rules)) for _, rule := range obj.Spec.Rules { host := "*" if rule.Host != "" { diff --git a/pkg/oci/client/client.go b/pkg/oci/client/client.go index 72ef23036..9729ae740 100644 --- a/pkg/oci/client/client.go +++ b/pkg/oci/client/client.go @@ -93,8 +93,7 @@ func NewClient(options ...ClientOption) *Client { // optionsWithContext returns the crane options for the given context. func (c *Client) optionsWithContext(ctx context.Context) []crane.Option { - options := []crane.Option{ - crane.WithContext(ctx), - } + options := make([]crane.Option, 0, 1+len(c.opts.craneOptions)) + options = append(options, crane.WithContext(ctx)) return append(options, c.opts.craneOptions...) } diff --git a/pkg/secrets/providers/alicloud/secretsmanager/secretsmanager.go b/pkg/secrets/providers/alicloud/secretsmanager/secretsmanager.go index bb584eb50..05fbeb8f2 100644 --- a/pkg/secrets/providers/alicloud/secretsmanager/secretsmanager.go +++ b/pkg/secrets/providers/alicloud/secretsmanager/secretsmanager.go @@ -2,6 +2,7 @@ package secretsmanager import ( "context" + "errors" "fmt" "os" "strings" @@ -45,10 +46,10 @@ type smSecretStore struct { func (p *DefaultSecretStoreProvider) NewSecretStore(spec *v1.SecretStore) (secrets.SecretStore, error) { providerSpec := spec.Provider if providerSpec == nil { - return nil, fmt.Errorf(errMissingProviderSpec) + return nil, errors.New(errMissingProviderSpec) } if providerSpec.Alicloud == nil { - return nil, fmt.Errorf(errMissingAlicloudProvider) + return nil, errors.New(errMissingAlicloudProvider) } client, err := getAlicloudClient(providerSpec.Alicloud.Region) diff --git a/pkg/secrets/providers/aws/secretsmanager/secretsmanager.go b/pkg/secrets/providers/aws/secretsmanager/secretsmanager.go index 5cb9ba3de..556deea85 100644 --- a/pkg/secrets/providers/aws/secretsmanager/secretsmanager.go +++ b/pkg/secrets/providers/aws/secretsmanager/secretsmanager.go @@ -34,10 +34,10 @@ type DefaultSecretStoreProvider struct{} func (p *DefaultSecretStoreProvider) NewSecretStore(spec *v1.SecretStore) (secrets.SecretStore, error) { providerSpec := spec.Provider if providerSpec == nil { - return nil, fmt.Errorf(errMissingProviderSpec) + return nil, errors.New(errMissingProviderSpec) } if providerSpec.AWS == nil { - return nil, fmt.Errorf(errMissingAWSProvider) + return nil, errors.New(errMissingAWSProvider) } config, err := auth.NewV2Config(context.TODO(), providerSpec.AWS.Region, providerSpec.AWS.Profile) diff --git a/pkg/secrets/providers/azure/keyvault/keyvault.go b/pkg/secrets/providers/azure/keyvault/keyvault.go index 8c8f19752..2a4f19e24 100644 --- a/pkg/secrets/providers/azure/keyvault/keyvault.go +++ b/pkg/secrets/providers/azure/keyvault/keyvault.go @@ -3,6 +3,7 @@ package keyvault import ( "context" "encoding/json" + "errors" "fmt" "os" "strings" @@ -42,10 +43,10 @@ type DefaultSecretStoreProvider struct{} func (p *DefaultSecretStoreProvider) NewSecretStore(spec *v1.SecretStore) (secrets.SecretStore, error) { providerSpec := spec.Provider if providerSpec == nil { - return nil, fmt.Errorf(errMissingProviderSpec) + return nil, errors.New(errMissingProviderSpec) } if providerSpec.Azure == nil { - return nil, fmt.Errorf(errMissingAzureProvider) + return nil, errors.New(errMissingAzureProvider) } secretClient, err := getSecretClient(providerSpec.Azure) @@ -70,13 +71,13 @@ func getSecretClient(spec *v1.AzureKVProvider) (SecretClient, error) { // See https://docs.microsoft.com/en-us/go/azure/azure-sdk-go-authorization#use-environment-based-authentication. func authorizerForServicePrincipal(spec *v1.AzureKVProvider) (autorest.Authorizer, error) { if spec.TenantID == nil { - return nil, fmt.Errorf(errMissingTenant) + return nil, errors.New(errMissingTenant) } clientID := os.Getenv("AZURE_CLIENT_ID") clientSecret := os.Getenv("AZURE_CLIENT_SECRET") if clientID == "" || clientSecret == "" { - return nil, fmt.Errorf(errMissingClientIDSecret) + return nil, errors.New(errMissingClientIDSecret) } clientCredentialsConfig := auth.NewClientCredentialsConfig(clientID, clientSecret, *spec.TenantID) diff --git a/pkg/secrets/providers/fake/fake.go b/pkg/secrets/providers/fake/fake.go index 2bdfc6913..a1cb1f836 100644 --- a/pkg/secrets/providers/fake/fake.go +++ b/pkg/secrets/providers/fake/fake.go @@ -2,6 +2,7 @@ package fake import ( "context" + "errors" "fmt" "github.com/tidwall/gjson" @@ -34,10 +35,10 @@ type DefaultSecretStoreProvider struct{} func (p *DefaultSecretStoreProvider) NewSecretStore(spec *v1.SecretStore) (secrets.SecretStore, error) { providerSpec := spec.Provider if providerSpec == nil { - return nil, fmt.Errorf(errMissingProviderSpec) + return nil, errors.New(errMissingProviderSpec) } if providerSpec.Fake == nil { - return nil, fmt.Errorf(errMissingFakeProvider) + return nil, errors.New(errMissingFakeProvider) } dataMap := make(map[string]*SecretData) diff --git a/pkg/secrets/providers/hashivault/vault.go b/pkg/secrets/providers/hashivault/vault.go index 5432a129b..2e081d398 100644 --- a/pkg/secrets/providers/hashivault/vault.go +++ b/pkg/secrets/providers/hashivault/vault.go @@ -189,7 +189,8 @@ func (v *vaultSecretStore) buildPath(path string) string { } if !strings.Contains(out, "/data/") && v.provider.Version == v1.VaultKVStoreV2 { buildPath := strings.Split(out, "/") - buildMount := []string{buildPath[0], "data"} + buildMount := make([]string, 0, len(buildPath)+1) + buildMount = append(buildMount, buildPath[0], "data") buildMount = append(buildMount, buildPath[1:]...) out = strings.Join(buildMount, "/") return out diff --git a/pkg/secrets/providers/viettelcloud/secretsmanager/secretsmanager.go b/pkg/secrets/providers/viettelcloud/secretsmanager/secretsmanager.go index ba43a4b89..c8f2ec4e7 100644 --- a/pkg/secrets/providers/viettelcloud/secretsmanager/secretsmanager.go +++ b/pkg/secrets/providers/viettelcloud/secretsmanager/secretsmanager.go @@ -3,6 +3,7 @@ package secretsmanager import ( "context" "encoding/json" + "errors" "fmt" "os" "strings" @@ -49,10 +50,10 @@ type smSecretStore struct { func (p *DefaultSecretStoreProvider) NewSecretStore(spec *v1.SecretStore) (secrets.SecretStore, error) { providerSpec := spec.Provider if providerSpec == nil { - return nil, fmt.Errorf(errMissingProviderSpec) + return nil, errors.New(errMissingProviderSpec) } if providerSpec.ViettelCloud == nil { - return nil, fmt.Errorf(errMissingViettelCloudProvider) + return nil, errors.New(errMissingViettelCloudProvider) } var project string if providerSpec.ViettelCloud.ProjectID != "" { diff --git a/pkg/util/yaml/yaml.go b/pkg/util/yaml/yaml.go index 5c75ec6f8..c4b035bd1 100644 --- a/pkg/util/yaml/yaml.go +++ b/pkg/util/yaml/yaml.go @@ -141,7 +141,7 @@ func MergeToOneYAML(yamlList ...interface{}) string { // Merge multiple yaml string into a single string, // separate yaml documents with '---' func MergeStringsToOneYAML(yamlList []string) string { - documents := []interface{}{} + documents := make([]interface{}, 0, len(yamlList)) for _, y := range yamlList { document := map[string]interface{}{} yamlv3.Unmarshal([]byte(y), document)