diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml index 7ca335f0472..8586e91768f 100644 --- a/.github/workflows/golangci-lint.yml +++ b/.github/workflows/golangci-lint.yml @@ -18,16 +18,20 @@ jobs: golangci: name: lint runs-on: ubuntu-24.04 + strategy: + matrix: + dirs: [".", "aks-node-controller"] steps: - - uses: actions/setup-go@v3 + - uses: actions/setup-go@v5 with: go-version: '1.22' - uses: actions/checkout@v4 - name: golangci-lint - uses: golangci/golangci-lint-action@v4 + uses: golangci/golangci-lint-action@v6 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.59.1 + version: v1.63.4 + working-directory: ${{ matrix.dirs }} # Optional: working directory, useful for monorepos # working-directory: somedir diff --git a/.golangci.yaml b/.golangci.yaml index fad075732f5..d4218c5f8da 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -100,22 +100,6 @@ linters-settings: # Default: true skipRecvDeref: false - gomnd: - # List of function patterns to exclude from analysis. - # Values always ignored: `time.Date`, - # `strconv.FormatInt`, `strconv.FormatUint`, `strconv.FormatFloat`, - # `strconv.ParseInt`, `strconv.ParseUint`, `strconv.ParseFloat`. - # Default: [] - ignored-functions: - - os.Chmod - - os.Mkdir - - os.MkdirAll - - os.OpenFile - - os.WriteFile - - prometheus.ExponentialBuckets - - prometheus.ExponentialBucketsRange - - prometheus.LinearBuckets - gomodguard: blocked: # List of blocked modules. @@ -210,9 +194,7 @@ linters: - durationcheck # checks for two durations multiplied together - errname # checks that sentinel errors are prefixed with the Err and error types are suffixed with the Error - errorlint # finds code that will cause problems with the error wrapping scheme introduced in Go 1.13 - - execinquery # checks query string in Query function which reads your Go src files and warning it finds - exhaustive # checks exhaustiveness of enum switch statements - - exportloopref # checks for pointers to enclosing loop variables - forbidigo # forbids identifiers - funlen # tool for detection of long functions - gocheckcompilerdirectives # validates go compiler directive comments (//go:) @@ -224,8 +206,6 @@ linters: - gocyclo # computes and checks the cyclomatic complexity of functions - godot # checks if comments end in a period - goimports # in addition to fixing imports, goimports also formats your code in the same style as gofmt - - gomnd # detects magic numbers - - gomoddirectives # manages the use of 'replace', 'retract', and 'excludes' directives in go.mod - gomodguard # allow and block lists linter for direct Go module dependencies. This is different from depguard where there are different block types for example version constraints and module recommendations - goprintffuncname # checks that printf-like functions are named with f at the end - gosec # inspects source code for security problems diff --git a/aks-node-controller/app.go b/aks-node-controller/app.go index 1d53a2b88bd..fd17529cdb1 100644 --- a/aks-node-controller/app.go +++ b/aks-node-controller/app.go @@ -14,7 +14,7 @@ import ( "github.com/Azure/agentbaker/aks-node-controller/parser" "github.com/Azure/agentbaker/aks-node-controller/pkg/nodeconfigutils" - "gopkg.in/fsnotify.v1" + "github.com/fsnotify/fsnotify" ) type App struct { @@ -75,6 +75,7 @@ func (a *App) run(ctx context.Context, args []string) error { case "provision-wait": provisionStatusFiles := ProvisionStatusFiles{ProvisionJSONFile: provisionJSONFilePath, ProvisionCompleteFile: provisionCompleteFilePath} provisionOutput, err := a.ProvisionWait(ctx, provisionStatusFiles) + //nolint:forbidigo // stdout is part of the interface fmt.Println(provisionOutput) slog.Info("provision-wait finished", "provisionOutput", provisionOutput) return err diff --git a/aks-node-controller/app_test.go b/aks-node-controller/app_test.go index 24eba3f9a44..9424b3ece91 100644 --- a/aks-node-controller/app_test.go +++ b/aks-node-controller/app_test.go @@ -176,8 +176,8 @@ func TestApp_ProvisionWait(t *testing.T) { // Run the test in a goroutine to simulate file creation after some delay go func() { time.Sleep(200 * time.Millisecond) // Simulate file creation delay - os.WriteFile(provisionStatusFiles.ProvisionJSONFile, []byte(testData), 0644) - os.Create(provisionStatusFiles.ProvisionCompleteFile) + _ = os.WriteFile(provisionStatusFiles.ProvisionJSONFile, []byte(testData), 0644) + _, _ = os.Create(provisionStatusFiles.ProvisionCompleteFile) }() }, }, @@ -185,8 +185,8 @@ func TestApp_ProvisionWait(t *testing.T) { name: "wait for provision completion", wantsErr: false, setup: func(provisionStatusFiles ProvisionStatusFiles) { - os.WriteFile(provisionStatusFiles.ProvisionJSONFile, []byte(testData), 0644) - os.Create(provisionStatusFiles.ProvisionCompleteFile) + _ = os.WriteFile(provisionStatusFiles.ProvisionJSONFile, []byte(testData), 0644) + _, _ = os.Create(provisionStatusFiles.ProvisionCompleteFile) }, }, { diff --git a/aks-node-controller/go.mod b/aks-node-controller/go.mod index b61e95b45db..4b24db61beb 100644 --- a/aks-node-controller/go.mod +++ b/aks-node-controller/go.mod @@ -7,9 +7,9 @@ toolchain go1.23.0 require ( github.com/Azure/agentbaker v0.20240503.0 github.com/blang/semver v3.5.1+incompatible + github.com/fsnotify/fsnotify v1.8.0 github.com/stretchr/testify v1.9.0 google.golang.org/protobuf v1.35.2 - gopkg.in/fsnotify.v1 v1.4.7 ) require ( diff --git a/aks-node-controller/go.sum b/aks-node-controller/go.sum index 99409be5ea0..4fc2d528780 100644 --- a/aks-node-controller/go.sum +++ b/aks-node-controller/go.sum @@ -11,8 +11,8 @@ github.com/blang/semver v3.5.1+incompatible/go.mod h1:kRBLl5iJ+tD4TcOOxsy/0fnweb github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM= github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY= -github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw= +github.com/fsnotify/fsnotify v1.8.0 h1:dAwr6QBTBZIkG8roQaJjGof0pp0EeF+tNV7YBP3F/8M= +github.com/fsnotify/fsnotify v1.8.0/go.mod h1:8jBTzvmWwFyi3Pb8djgCCO5IBqzKJ/Jwo8TRcHyHii0= github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= @@ -44,8 +44,6 @@ google.golang.org/protobuf v1.35.2/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojt gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= -gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4= -gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= diff --git a/aks-node-controller/helpers/const.go b/aks-node-controller/helpers/const.go index 7085b43464c..e9d49da5ab8 100644 --- a/aks-node-controller/helpers/const.go +++ b/aks-node-controller/helpers/const.go @@ -1,9 +1,5 @@ package helpers -const ( - contractVersion = "v0" -) - const ( VMTypeStandard = "standard" VMTypeVmss = "vmss" diff --git a/aks-node-controller/main.go b/aks-node-controller/main.go index 1ad6d37ae74..07a65e5c0d3 100644 --- a/aks-node-controller/main.go +++ b/aks-node-controller/main.go @@ -22,6 +22,7 @@ func configureLogging() func() { logPath := setupLogPath() if err := os.MkdirAll(filepath.Dir(logPath), 0755); err != nil { + //nolint:forbidigo // there is no other way to communicate the error fmt.Printf("failed to create log directory: %s\n", err) os.Exit(1) } diff --git a/aks-node-controller/parser/parser.go b/aks-node-controller/parser/parser.go index 69e7c1a0ff8..b8e54a5f22e 100644 --- a/aks-node-controller/parser/parser.go +++ b/aks-node-controller/parser/parser.go @@ -29,6 +29,7 @@ func executeBootstrapTemplate(inputContract *aksnodeconfigv1.Configuration) (str return buffer.String(), nil } +//nolint:funlen func getCSEEnv(config *aksnodeconfigv1.Configuration) map[string]string { env := map[string]string{ "PROVISION_OUTPUT": "/var/log/azure/cluster-provision.log", diff --git a/aks-node-controller/test_helpers.go b/aks-node-controller/test_helpers.go deleted file mode 100644 index b83d3854806..00000000000 --- a/aks-node-controller/test_helpers.go +++ /dev/null @@ -1,32 +0,0 @@ -package main - -import ( - "github.com/Azure/agentbaker/pkg/agent/datamodel" -) - -func Ptr[T any](input T) *T { - return &input -} - -func validAKSNodeConfig() *datamodel.NodeBootstrappingConfiguration { - return &datamodel.NodeBootstrappingConfiguration{ - ContainerService: &datamodel.ContainerService{ - Properties: &datamodel.Properties{ - CertificateProfile: &datamodel.CertificateProfile{ - CaCertificate: "test-ca-cert", - }, - OrchestratorProfile: &datamodel.OrchestratorProfile{ - OrchestratorType: datamodel.Kubernetes, - OrchestratorVersion: "1.31.0", - KubernetesConfig: &datamodel.KubernetesConfig{ - DockerBridgeSubnet: "1.1.1.1", - }, - }, - }, - }, - CustomSecureTLSBootstrapAADServerAppID: "test-app-id", - AgentPoolProfile: &datamodel.AgentPoolProfile{ - KubeletDiskType: datamodel.TempDisk, - }, - } -} diff --git a/aks-node-controller/utils/sensitive_string.go b/aks-node-controller/utils/sensitive_string.go index a1e6e5ccb85..55b9fbcec50 100644 --- a/aks-node-controller/utils/sensitive_string.go +++ b/aks-node-controller/utils/sensitive_string.go @@ -22,7 +22,6 @@ func (s SensitiveString) MarshalJSON() ([]byte, error) { return json.Marshal(s.String()) } -//nolint:unparam // this is an interface implementation func (s SensitiveString) MarshalYAML() (interface{}, error) { return s.String(), nil } diff --git a/pkg/agent/baker.go b/pkg/agent/baker.go index 7f8df08cb97..46baab3048e 100644 --- a/pkg/agent/baker.go +++ b/pkg/agent/baker.go @@ -199,11 +199,13 @@ func getBakerFuncMap(config *datamodel.NodeBootstrappingConfiguration, params pa // TODO: GetParameterPropertyLower funcMap["GetParameterProperty"] = func(s, p string) interface{} { if v, ok := params[s].(paramsMap); ok && v != nil { - if v["value"].(paramsMap)[p] == nil { + //nolint:errcheck // this code been writen before linter was added + param := v["value"].(paramsMap)[p] + if param == nil { // return empty string so we don't get from go template return "" } - return v["value"].(paramsMap)[p] + return param } return "" } diff --git a/pkg/agent/baker_test.go b/pkg/agent/baker_test.go index 6f09c9f129b..ce3899c0aea 100644 --- a/pkg/agent/baker_test.go +++ b/pkg/agent/baker_test.go @@ -345,7 +345,7 @@ var _ = Describe("Assert generated customData and cseCmd", func() { Expect(err).To(BeNil()) nodeBootstrapping, err := ab.GetNodeBootstrapping( context.Background(), - configCustomDataInput.(*datamodel.NodeBootstrappingConfiguration), + configCustomDataInput.(*datamodel.NodeBootstrappingConfiguration), //nolint:errcheck // this code been writen before linter was added ) Expect(err).To(BeNil()) @@ -378,7 +378,7 @@ var _ = Describe("Assert generated customData and cseCmd", func() { Expect(err).To(BeNil()) nodeBootstrapping, err = ab.GetNodeBootstrapping( context.Background(), - configCseInput.(*datamodel.NodeBootstrappingConfiguration), + configCseInput.(*datamodel.NodeBootstrappingConfiguration), //nolint:errcheck // this code been writen before linter was added ) Expect(err).To(BeNil()) cseCommand := nodeBootstrapping.CSE