diff --git a/.golangci.yml b/.golangci.yml index 2f44aba6..663df927 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -7,36 +7,54 @@ run: linters: disable-all: true enable: + - asciicheck + - bidichk + - bodyclose - containedctx - contextcheck + - copyloopvar + - decorder - depguard + - dogsled + - durationcheck - errcheck - errchkjson - errname - - gocheckcompilerdirectives - - gochecknoinits + - errorlint + - exhaustive - gci - ginkgolinter + - gocheckcompilerdirectives + - gochecknoinits + - gochecksumtype - goconst - gocritic - gocyclo - godot - gofumpt + - gomoddirectives - gosec - gosimple - govet - ineffassign + - interfacebloat + - intrange - lll - loggercheck - mirror - misspell + - musttag + - nestif + - nilerr - nolintlint + - nosprintfhostport - prealloc - reassign - staticcheck - stylecheck - tenv - testableexamples + - testifylint - thelper - tparallel - typecheck diff --git a/archive/archive_test.go b/archive/archive_test.go index c3a5d058..1643fdf4 100644 --- a/archive/archive_test.go +++ b/archive/archive_test.go @@ -7,6 +7,7 @@ import ( "archive/tar" "bytes" "compress/gzip" + "errors" "io" "os" "path/filepath" @@ -40,7 +41,7 @@ func TestArchiveDirectorySuccess(t *testing.T) { tr := tar.NewReader(gzr) for { hdr, err := tr.Next() - if err == io.EOF { + if errors.Is(err, io.EOF) { break // End of archive } require.NoError(t, err, "error reading listing from tarball") @@ -51,7 +52,7 @@ func TestArchiveDirectorySuccess(t *testing.T) { _, err = io.CopyN(&buf, tr, 1024) require.Condition( t, - func() (success bool) { return err == nil || err == io.EOF }, + func() (success bool) { return err == nil || errors.Is(err, io.EOF) }, "error reading content from tarball", ) archivedContents[hdr.Name] = buf.String() @@ -81,7 +82,7 @@ func TestArchiveDirectoryToTarSuccess(t *testing.T) { tr := tar.NewReader(f) for { hdr, err := tr.Next() - if err == io.EOF { + if errors.Is(err, io.EOF) { break // End of archive } require.NoError(t, err, "error reading listing from tarball") @@ -92,7 +93,7 @@ func TestArchiveDirectoryToTarSuccess(t *testing.T) { _, err = io.CopyN(&buf, tr, 1024) require.Condition( t, - func() (success bool) { return err == nil || err == io.EOF }, + func() (success bool) { return err == nil || errors.Is(err, io.EOF) }, "error reading content from tarball", ) archivedContents[hdr.Name] = buf.String() diff --git a/cmd/mindthegap/create/helmbundle/helm_bundle.go b/cmd/mindthegap/create/helmbundle/helm_bundle.go index 1378ffd6..24d7b701 100644 --- a/cmd/mindthegap/create/helmbundle/helm_bundle.go +++ b/cmd/mindthegap/create/helmbundle/helm_bundle.go @@ -170,7 +170,7 @@ func NewCommand(out output.Output) *cobra.Command { ) if err != nil { out.EndOperationWithStatus(output.Failure()) - return fmt.Errorf("failed to create Helm chart bundle: %v", err) + return fmt.Errorf("failed to create Helm chart bundle: %w", err) } if err := helmClient.PushHelmChartToOCIRegistry( @@ -199,7 +199,7 @@ func NewCommand(out output.Output) *cobra.Command { ) if err != nil { out.EndOperationWithStatus(output.Failure()) - return fmt.Errorf("failed to create Helm chart bundle: %v", err) + return fmt.Errorf("failed to create Helm chart bundle: %w", err) } chrt, err := helm.LoadChart(downloaded) diff --git a/cmd/mindthegap/flags/custom_flags_test.go b/cmd/mindthegap/flags/custom_flags_test.go index c45aa480..5ee39507 100644 --- a/cmd/mindthegap/flags/custom_flags_test.go +++ b/cmd/mindthegap/flags/custom_flags_test.go @@ -64,8 +64,7 @@ func Test_parsePossibleURI(t *testing.T) { expectedPath: "/dkp", }, } - for ti := range tests { - tt := tests[ti] + for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { t.Parallel() scheme, address, host, path, _ := parsePossibleURI(tt.in) diff --git a/cmd/mindthegap/push/bundle/bundle.go b/cmd/mindthegap/push/bundle/bundle.go index 0843583a..26ee7f9c 100644 --- a/cmd/mindthegap/push/bundle/bundle.go +++ b/cmd/mindthegap/push/bundle/bundle.go @@ -305,7 +305,7 @@ func pushImages( ) error { puller, err := remote.NewPuller(destRemoteOpts...) if err != nil { - return nil + return err } // Sort registries for deterministic ordering. diff --git a/cmd/mindthegap/serve/bundle/bundle.go b/cmd/mindthegap/serve/bundle/bundle.go index 933555de..7afcbd27 100644 --- a/cmd/mindthegap/serve/bundle/bundle.go +++ b/cmd/mindthegap/serve/bundle/bundle.go @@ -4,6 +4,7 @@ package bundle import ( + "errors" "fmt" "net/http" "os" @@ -102,7 +103,8 @@ func NewCommand( out.Infof("Listening on %s\n", reg.Address()) go func() { - if err := reg.ListenAndServe(); err != nil && err != http.ErrServerClosed { + if err := reg.ListenAndServe(); err != nil && + !errors.Is(err, http.ErrServerClosed) { out.Error(err, "error serving Docker registry") os.Exit(2) } diff --git a/cmd/mindthegap/utils/glob_test.go b/cmd/mindthegap/utils/glob_test.go index 6926e3b1..f7571db5 100644 --- a/cmd/mindthegap/utils/glob_test.go +++ b/cmd/mindthegap/utils/glob_test.go @@ -51,8 +51,7 @@ func TestFilesWithGlobs(t *testing.T) { expectedOutput: combinedCreatedFiles, }, } - for ti := range tests { - tt := tests[ti] + for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { t.Parallel() out, err := FilesWithGlobs(tt.in) diff --git a/config/helm_charts_config_test.go b/config/helm_charts_config_test.go index cce526da..2d98f7fc 100644 --- a/config/helm_charts_config_test.go +++ b/config/helm_charts_config_test.go @@ -116,8 +116,7 @@ func TestParseHelmChartsFile(t *testing.T) { }, }, }} - for ti := range tests { - tt := tests[ti] + for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { t.Parallel() ext := "yaml" @@ -324,8 +323,7 @@ func TestMergeHelmConfig(t *testing.T) { }, } - for ti := range tests { - tt := tests[ti] + for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { t.Parallel() got := tt.src.Merge(tt.with) diff --git a/docker/ecr/registry_test.go b/docker/ecr/registry_test.go index edd8b5a1..7ee9ccdf 100644 --- a/docker/ecr/registry_test.go +++ b/docker/ecr/registry_test.go @@ -46,7 +46,6 @@ func TestIsECRRegistry(t *testing.T) { want: true, }} for _, tt := range tests { - tt := tt // Capture range variable. t.Run(tt.name, func(t *testing.T) { t.Parallel() if got := IsECRRegistry(tt.registryAddress); got != tt.want { @@ -102,7 +101,6 @@ func TestParseECRRegistry(t *testing.T) { wantRegion: "", }} for _, tt := range tests { - tt := tt // Capture range variable. t.Run(tt.name, func(t *testing.T) { t.Parallel() gotID, gotFips, gotRegion, gotErr := ParseECRRegistry(tt.registryAddress) diff --git a/go.mod b/go.mod index ff992ae9..b540db9c 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/mesosphere/mindthegap -go 1.21 +go 1.22 require ( github.com/aws/aws-sdk-go-v2 v1.26.1 diff --git a/hack/flakes/flake.lock b/hack/flakes/flake.lock index 3bfd004b..7cdf6a6f 100644 --- a/hack/flakes/flake.lock +++ b/hack/flakes/flake.lock @@ -5,11 +5,11 @@ "systems": "systems" }, "locked": { - "lastModified": 1701680307, - "narHash": "sha256-kAuep2h5ajznlPMD9rnQyffWG8EM/C73lejGofXvdM8=", + "lastModified": 1710146030, + "narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=", "owner": "numtide", "repo": "flake-utils", - "rev": "4022d587cbbfd70fe950c1e2083a02621806a725", + "rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a", "type": "github" }, "original": { @@ -20,11 +20,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1702312524, - "narHash": "sha256-gkZJRDBUCpTPBvQk25G0B7vfbpEYM5s5OZqghkjZsnE=", + "lastModified": 1712439257, + "narHash": "sha256-aSpiNepFOMk9932HOax0XwNxbA38GOUVOiXfUVPOrck=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "a9bf124c46ef298113270b1f84a164865987a91c", + "rev": "ff0dbd94265ac470dda06a657d5fe49de93b4599", "type": "github" }, "original": { diff --git a/hack/flakes/flake.nix b/hack/flakes/flake.nix index 068115be..19d87538 100644 --- a/hack/flakes/flake.nix +++ b/hack/flakes/flake.nix @@ -10,7 +10,7 @@ flake-utils.lib.eachDefaultSystem (system: with nixpkgs.legacyPackages.${system}; rec { packages = rec { - golangci-lint = pkgs.golangci-lint.override { buildGoModule = buildGo121Module; }; + golangci-lint = pkgs.golangci-lint.override { buildGoModule = buildGo122Module; }; go-mod-upgrade = buildGo121Module rec { name = "go-mod-upgrade"; diff --git a/images/authnhelpers/static_keychain.go b/images/authnhelpers/static_keychain.go index 68612dfe..a22aca97 100644 --- a/images/authnhelpers/static_keychain.go +++ b/images/authnhelpers/static_keychain.go @@ -14,8 +14,6 @@ type staticHelper struct { authConfig *types.DockerAuthConfig } -var _ authn.Helper = staticHelper{} - func (h staticHelper) Get(serverURL string) (username, password string, err error) { if h.authConfig != nil && serverURL == h.registry { password := h.authConfig.Password diff --git a/images/httputils/configurable_tls_transport.go b/images/httputils/configurable_tls_transport.go index ae66a00b..4d0343f2 100644 --- a/images/httputils/configurable_tls_transport.go +++ b/images/httputils/configurable_tls_transport.go @@ -32,7 +32,7 @@ func TLSConfiguredRoundTripper( if tr.TLSClientConfig.RootCAs == nil { systemPool, err := tlsconfig.SystemCertPool() if err != nil { - return nil, fmt.Errorf("unable to get system cert pool: %v", err) + return nil, fmt.Errorf("unable to get system cert pool: %w", err) } tr.TLSClientConfig.RootCAs = systemPool } diff --git a/images/manifest_test.go b/images/manifest_test.go index 55b67273..e892732a 100644 --- a/images/manifest_test.go +++ b/images/manifest_test.go @@ -204,7 +204,6 @@ func TestManifestListForImage_RemoteIndex(t *testing.T) { }, }} for _, tt := range tests { - tt := tt // Capture range variable t.Run(tt.name, func(t *testing.T) { t.Parallel() svr := httptest.NewServer( @@ -411,7 +410,6 @@ func TestManifestListForImage_RemoteImage(t *testing.T) { }, }} for _, tt := range tests { - tt := tt // Capture range variable t.Run(tt.name, func(t *testing.T) { t.Parallel()