From 885df70b98df13b38ac7c33243c7955cb9771056 Mon Sep 17 00:00:00 2001 From: Weston Steimel Date: Wed, 12 Feb 2025 11:00:35 +0000 Subject: [PATCH 1/3] feat: update to go 1.24.x Update to building with go 1.24.x so that the main module version gets set during go build Signed-off-by: Weston Steimel --- .github/workflows/release.yaml | 6 +++--- .github/workflows/static-unit-integration.yaml | 4 ++-- go.mod | 2 +- scripts/install-go.sh | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 034511d..343be2b 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -9,7 +9,7 @@ on: - 'v*' env: - GO_VERSION: "1.22.x" + GO_VERSION: "1.24.x" jobs: wait-for-checks: @@ -31,7 +31,7 @@ jobs: with: token: ${{ secrets.GITHUB_TOKEN }} # This check name is defined as the github actions job name (in .github/workflows/static-analysis-integration.yaml) - checkName: "Static-Analysis (1.22.x, ubuntu-latest)" + checkName: "Static-Analysis (1.24.x, ubuntu-latest)" ref: ${{ github.event.pull_request.head.sha || github.sha }} - name: Check unit, and integration test results @@ -40,7 +40,7 @@ jobs: with: token: ${{ secrets.GITHUB_TOKEN }} # This check name is defined as the github actions job name (in .github/workflows/static-analysis-integration.yaml) - checkName: "Tests (1.22.x, ubuntu-latest)" + checkName: "Tests (1.24.x, ubuntu-latest)" ref: ${{ github.event.pull_request.head.sha || github.sha }} - name: Quality gate diff --git a/.github/workflows/static-unit-integration.yaml b/.github/workflows/static-unit-integration.yaml index a892be4..6a9e55c 100644 --- a/.github/workflows/static-unit-integration.yaml +++ b/.github/workflows/static-unit-integration.yaml @@ -7,7 +7,7 @@ jobs: Static-Analysis: strategy: matrix: - go-version: ["1.22.x"] + go-version: ["1.24.x"] platform: [ubuntu-latest] runs-on: ${{ matrix.platform }} steps: @@ -43,7 +43,7 @@ jobs: strategy: matrix: # test the lower bounds of support, and the latest available - go-version: ["1.22.x"] + go-version: ["1.24.x"] platform: [ubuntu-latest] runs-on: ${{ matrix.platform }} steps: diff --git a/go.mod b/go.mod index 2b32ba0..8860379 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/anchore/k8s-inventory -go 1.22.5 +go 1.24.0 require ( github.com/adrg/xdg v0.5.3 diff --git a/scripts/install-go.sh b/scripts/install-go.sh index adc939b..7a92ede 100755 --- a/scripts/install-go.sh +++ b/scripts/install-go.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -GO_VERSION="1.22.5" +GO_VERSION="1.24.0" ARCH=$(uname | tr '[:upper:]' '[:lower:]') GO_ARTIFACT="go$GO_VERSION.$ARCH-amd64.tar.gz" wget "https://dl.google.com/go/$GO_ARTIFACT" From 3ba32cc71361e9c1b511fd2e41409f007609df40 Mon Sep 17 00:00:00 2001 From: Weston Steimel Date: Wed, 12 Feb 2025 11:02:36 +0000 Subject: [PATCH 2/3] chore: bump golangci-lint for go 1.24.x support Signed-off-by: Weston Steimel --- .golangci.yaml | 50 +++++++++++++++----------------------------------- Makefile | 2 +- 2 files changed, 16 insertions(+), 36 deletions(-) diff --git a/.golangci.yaml b/.golangci.yaml index a48de89..1ee3af4 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -1,9 +1,20 @@ -run: - timeout: 5m - skip-dirs: +issues: + max-same-issues: 25 + uniq-by-line: false + exclude-dirs: - .circleci - .github - scripts + exclude-rules: + - path: (.+)_test.go + linters: + - funlen + - dupl + - goconst + +run: + timeout: 5m + linters: # inverted configuration with `enable-all` and `disable` is not scalable during updates of golangci-lint disable-all: true @@ -13,7 +24,7 @@ linters: - dupl - errcheck - errorlint - - exportloopref + - copyloopvar - funlen - gocognit - goconst @@ -46,34 +57,3 @@ linters-settings: # If lower than 0, disable the check. # Default: 40 statements: 50 -output: - uniq-by-line: false -issues: - exclude-rules: - - path: (.+)_test.go - linters: - - funlen - - dupl - - goconst - -# do not enable... -# - dogsled # found to be to niche and ineffective -# - goprintffuncname # does not catch all cases and there are exceptions -# - nakedret # does not catch all cases and should not fail a build -# - gochecknoglobals -# - gochecknoinits # this is too aggressive -# - rowserrcheck disabled per generics https://github.com/golangci/golangci-lint/issues/2649 -# - godot -# - godox -# - goerr113 -# - goimports # we're using gosimports now instead to account for extra whitespaces (see https://github.com/golang/go/issues/20818) -# - golint # deprecated -# - gomnd # this is too aggressive -# - interfacer # this is a good idea, but is no longer supported and is prone to false positives -# - lll # without a way to specify per-line exception cases, this is not usable -# - maligned # this is an excellent linter, but tricky to optimize and we are not sensitive to memory layout optimizations -# - nestif -# - prealloc # following this rule isn't consistently a good idea, as it sometimes forces unnecessary allocations that result in less idiomatic code -# - scopelint # deprecated -# - testpackage -# - wsl # this doens't have an auto-fixer yet and is pretty noisy (https://github.com/bombsimon/wsl/issues/90) diff --git a/Makefile b/Makefile index a312dd5..5a32fc6 100644 --- a/Makefile +++ b/Makefile @@ -18,7 +18,7 @@ COVERAGE_THRESHOLD := 45 CLUSTER_NAME=anchore-k8s-inventory-testing -GOLANG_CI_VERSION=v1.55.2 +GOLANG_CI_VERSION=v1.64.2 GOBOUNCER_VERSION=v0.4.0 GORELEASER_VERSION=v1.18.2 From 0934cdae99c51c0c319d830cb608898917cdbc31 Mon Sep 17 00:00:00 2001 From: Weston Steimel Date: Wed, 12 Feb 2025 12:25:59 +0000 Subject: [PATCH 3/3] chore: appease the updated linter Signed-off-by: Weston Steimel --- cmd/root.go | 7 ++++--- pkg/inventory/containers.go | 1 - pkg/lib.go | 7 ++++--- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/cmd/root.go b/cmd/root.go index bc61d7b..5416d8a 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -3,12 +3,13 @@ package cmd import ( "errors" "fmt" + "os" + "runtime/pprof" + "github.com/anchore/k8s-inventory/pkg/healthreporter" "github.com/anchore/k8s-inventory/pkg/integration" "github.com/anchore/k8s-inventory/pkg/mode" "github.com/anchore/k8s-inventory/pkg/reporter" - "os" - "runtime/pprof" "github.com/spf13/cobra" "github.com/spf13/viper" @@ -40,7 +41,7 @@ var rootCmd = &cobra.Command{ if len(args) > 0 { err := cmd.Help() if err != nil { - log.Errorf(err.Error()) + log.Error(err.Error()) os.Exit(1) } os.Exit(1) diff --git a/pkg/inventory/containers.go b/pkg/inventory/containers.go index 40020ce..b4253b8 100644 --- a/pkg/inventory/containers.go +++ b/pkg/inventory/containers.go @@ -29,7 +29,6 @@ func getRegistryOverrideNormalisedImageTag(imageTag, missingRegistryOverride str return imageTag } -//nolint:funlen func getContainersInPod(pod v1.Pod, missingRegistryOverride, missingTagPolicy, dummyTag string) []Container { // Look at both status/spec for init and regular containers // Must use status when looking at containers in order to obtain the container ID diff --git a/pkg/lib.go b/pkg/lib.go index 32dc467..b5d3649 100644 --- a/pkg/lib.go +++ b/pkg/lib.go @@ -7,12 +7,13 @@ import ( "encoding/json" "errors" "fmt" - jstime "github.com/anchore/k8s-inventory/internal/time" - "github.com/anchore/k8s-inventory/pkg/integration" "os" "regexp" "time" + jstime "github.com/anchore/k8s-inventory/internal/time" + "github.com/anchore/k8s-inventory/pkg/integration" + "k8s.io/client-go/kubernetes" "k8s.io/client-go/rest" @@ -95,7 +96,7 @@ func HandleReport(report inventory.Report, reportInfo *healthreporter.InventoryR // PeriodicallyGetInventoryReport periodically retrieve image results and report/output them according to the configuration. // Note: Errors do not cause the function to exit, since this is periodically running // -//nolint:funlen, gocognit +//nolint:gocognit func PeriodicallyGetInventoryReport(cfg *config.Application, ch integration.Channels, gatedReportInfo *healthreporter.GatedReportInfo) { // Wait for registration with Enterprise to be disabled or completed <-ch.InventoryReportingEnabled