Skip to content

Commit

Permalink
Enable linter for aks-node-controller (#5618)
Browse files Browse the repository at this point in the history
  • Loading branch information
r2k1 authored Jan 21, 2025
1 parent 326b862 commit fafa7a4
Show file tree
Hide file tree
Showing 13 changed files with 24 additions and 74 deletions.
10 changes: 7 additions & 3 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 0 additions & 20 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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:)
Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion aks-node-controller/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions aks-node-controller/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,17 +176,17 @@ 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)
}()
},
},
{
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)
},
},
{
Expand Down
2 changes: 1 addition & 1 deletion aks-node-controller/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
6 changes: 2 additions & 4 deletions aks-node-controller/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down Expand Up @@ -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=
Expand Down
4 changes: 0 additions & 4 deletions aks-node-controller/helpers/const.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
package helpers

const (
contractVersion = "v0"
)

const (
VMTypeStandard = "standard"
VMTypeVmss = "vmss"
Expand Down
1 change: 1 addition & 0 deletions aks-node-controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
1 change: 1 addition & 0 deletions aks-node-controller/parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
32 changes: 0 additions & 32 deletions aks-node-controller/test_helpers.go

This file was deleted.

1 change: 0 additions & 1 deletion aks-node-controller/utils/sensitive_string.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
6 changes: 4 additions & 2 deletions pkg/agent/baker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 <no value> from go template
return ""
}
return v["value"].(paramsMap)[p]
return param
}
return ""
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/agent/baker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit fafa7a4

Please sign in to comment.