Skip to content

chore: reset golangci-lint config - #10150

Merged
Artur Khantimirov (r2k1) merged 3 commits into
devfrom
r2k1-reset-linter-settings
Nov 25, 2026
Merged

Artur Khantimirov (r2k1) merged 3 commits into
devfrom
r2k1-reset-linter-settings

Conversation

@r2k1

@r2k1 Artur Khantimirov (r2k1) commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

What this PR does / why we need it:

Replaces the golangci-lint config with a short config that needs little tuning.

Before: a large hand-tuned config with many per-linter settings and about 82 stale //nolint directives.

After: .golangci.yaml keeps the default linters and adds selected bug and security linters: asasalint, asciicheck, bidichk, bodyclose, canonicalheader, containedctx, contextcheck, durationcheck, errchkjson, errorlint, exhaustive, exptostd, fatcontext, forcetypeassert, gocritic, gomoddirectives, goprintffuncname, gosec, makezero, modernize, musttag, nilerr, nilnil, noctx, nolintlint, protogetter, reassign, revive, testifylint, unparam, usetesting. govet also enables nilness and shadow.

Settings are kept to a minimum. Each one has a reason in the config:

  • revive var-naming and exported are off. They are naming style only, and renames break importers of exported names.
  • revive unexported-return is off. Changing the return type of NewAgentBaker would break importers. Also, it reports on Go 1.26 but not on Go 1.27, so a //nolint is unused in CI.
  • modernize omitzero is off, so json tags stay as written.
  • gosec allows 0755 directories. Files that other processes must read have local //nolint directives.
  • nolintlint requires a linter name and a reason on each //nolint.
  • In tests, gosec, noctx, protogetter and revive are off.

Code changes:

  • Linter auto-fixes, mostly modernize: interface{}→any, new(x) instead of to.Ptr(x), strings.SplitSeq, maps.Copy. Also testifylint and canonicalheader fixes.
  • pkg/agent/datamodel: exact-name json tags such as json:"ResourceGroup" for musttag. A temporary test showed byte-identical JSON before and after, and the decode/encode round trip matched. Embedded structs stay untagged.
  • apiserver shutdown uses context.WithoutCancel(ctx).
  • aks-node-controller creates the KVP pool file with mode 0644 (was 0666).
  • Test-only helpers moved into _test.go files.
  • 2 tests that check byte-exact legacy output keep require.Equal.
  • IsVhd keeps a direct field read, because nil means VHD.
  • unparam: removed parameters that always get the same value from addSecret and strKeyValToMapBool.
  • exhaustive: getStringFromLoadBalancerSkuType lists the UNSPECIFIED case.

No exported Go API changes and no JSON wire-format changes.

Validation:

  • golangci-lint run ./... (v2.15.0) in ., aks-node-controller and aks-live-patching: 0 issues each, with Go 1.27.4 (GOOS=linux, as in CI) and with Go 1.26.
  • go build ./... and go vet ./... (also e2e): passed.
  • go test ./pkg/... ./apiserver/...: passed.
  • cd aks-node-controller && go test ./...: passed, except TestRunProvisionRemovesInputsAfterExecution and TestRunProvisionReportsInputCleanupFailure. These fail the same way on the base branch on macOS (no /bin/true).

Which issue(s) this PR fixes:

AB#40892308

Replace the large, hand-tuned golangci-lint config with a short config based on
default linters plus selected bug and security linters. Fix the findings in
code, apply linter auto-fixes, and remove stale //nolint directives.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@github-actions

github-actions Bot commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Windows Unit Test Results

  3 files   21 suites   1m 6s ⏱️
812 tests 812 ✅ 0 💤 0 ❌
839 runs  839 ✅ 0 💤 0 ❌

Results for commit 00c2fd9.

♻️ This comment has been updated with latest results.

@r2k1
Artur Khantimirov (r2k1) marked this pull request as ready for review November 22, 2026 22:31
Copilot AI balanced review requested due to automatic review settings November 22, 2026 22:31

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues block the lint configuration simplification and accompanying Go updates.

No open issues 🎉

What changed in this PR

Simplifies AgentBaker’s Go lint configuration and updates the service, node controller, and tests to match, with the intent of preserving exported APIs and JSON wire formats.

Changes:

  • Replaces extensive lint tuning with default linters, selected correctness/security checks, and focused exceptions.
  • Modernizes Go code, removes stale suppressions, moves test-only helpers, and adds explicit JSON tags matching existing field names.
  • Preserves context values during API shutdown and tightens newly created KVP pool files to mode 0644.
File Description
pkg/​vhdbuilder/​datamodel/​component_configs.go Uses any in the JSON loader.
pkg/​agent/​variables.go Constructs cloud-init data without a type assertion.
pkg/​agent/​variables_test.go Removes a stale lint suppression.
pkg/​agent/​utils.go Modernizes helpers and moves test-only code out.
pkg/​agent/​utils_test.go Modernizes tests and receives the script-encoding helper.
pkg/​agent/​toggles/​types.go Explicitly marks unused parameters.
pkg/​agent/​script_minification_artifacts_test.go Uses a dedicated error assertion.
pkg/​agent/​localdns_test.go Modernizes pointer creation and string iteration.
pkg/​agent/​datamodel/​versions.go Uses standard map-copy and slice-membership helpers.
pkg/​agent/​datamodel/​versions_test.go Removes redundant loop captures and suppressions.
pkg/​agent/​datamodel/​types.go Adds exact-name JSON tags and modernizes map copying.
pkg/​agent/​datamodel/​types_test.go Modernizes fixtures and receives test-only mock helpers.
pkg/​agent/​datamodel/​sig_config.go Adds exact-name JSON tags and simplifies membership checks.
pkg/​agent/​datamodel/​osimageconfig.go Removes a stale lint suppression.
pkg/​agent/​datamodel/​mocks.go Moves private test helpers into test files.
pkg/​agent/​datamodel/​helper.go Modernizes iteration and moves test-only URL helpers.
pkg/​agent/​datamodel/​helper_test.go Receives URL helpers and removes redundant loop captures.
pkg/​agent/​datamodel/​gpu_components.go Cleans up comments and stale suppressions.
pkg/​agent/​bakerapi.go Uses map copying and documents API compatibility exceptions.
pkg/​agent/​bakerapi_test.go Removes a stale lint suppression.
pkg/​agent/​baker.go Checks template type assertions and modernizes helpers.
pkg/​agent/​baker_test.go Modernizes assertions and receives the label-normalization helper.
image-fetcher/​image.go Adds spacing before a function comment.
hotfix/​render-nodecustomdata/​main.go Uses any for variadic arguments.
e2e/​scenario/​scenario_win.go Removes a suppression while retaining its explanatory comment.
e2e/​scenario/​scenario_kubelet_disk.go Formats import groups.
e2e/​scenario/​scenario_gpu_daemonset.go Formats import groups.
e2e/​scenario/​scenario_cse_perf.go Formats import groups.
cmd/​starter/​start.go Removes stale global-variable suppressions.
apiserver/​apiserver.go Preserves context values in uncancelled shutdown context.
aks-node-controller/​version.go Retains build-time documentation without the suppression.
aks-node-controller/​utils/​sensitive_string.go Uses any in the YAML marshaler signature.
aks-node-controller/​repository_telemetry.go Explains ignored string-marshaling errors.
aks-node-controller/​repository_telemetry_test.go Uses dedicated substring assertions.
aks-node-controller/​repository_hotfix.go Uses typed error extraction.
aks-node-controller/​repository_hotfix_test.go Modernizes assertions and avoids fatal assertions in handlers.
aks-node-controller/​repository_hotfix_rpm.go Modernizes version splitting and text iteration.
aks-node-controller/​repository_hotfix_deb.go Uses iterator-based repository parsing loops.
aks-node-controller/​pkg/​nodeconfigutils/​validation.go Uses protobuf getters and iterator-based parsing.
aks-node-controller/​pkg/​nodeconfigutils/​validation_test.go Modernizes pointer creation.
aks-node-controller/​pkg/​nodeconfigutils/​utils_test.go Modernizes MIME-header iteration.
aks-node-controller/​pkg/​nodeconfigutils/​testutil.go Uses integer-range loops.
aks-node-controller/​pkg/​gpu/​skus.go Cleans up comments and stale suppressions.
aks-node-controller/​parser/​parser.go Uses protobuf getters while preserving nil-sensitive VHD handling.
aks-node-controller/​parser/​parser_test.go Modernizes pointers, assertions, and suppressions.
aks-node-controller/​parser/​kubelet_config_test.go Modernizes tests while retaining byte-exact output checks.
aks-node-controller/​parser/​helper.go Simplifies protobuf access and modernizes iteration.
aks-node-controller/​parser/​helper_test.go Modernizes fixtures, map copying, and iteration.
aks-node-controller/​main.go Documents diagnostic log permissions and removes stale suppressions.
aks-node-controller/​hotfix.go Modernizes OS-release parsing.
aks-node-controller/​hotfix_test.go Uses dedicated empty-value assertions.
aks-node-controller/​goal_state.go Canonicalizes headers and creates KVP files with 0644.
aks-node-controller/​goal_state_test.go Matches canonical header spelling.
aks-node-controller/​embeddednodecustomdata.go Modernizes OS-release line iteration.
aks-node-controller/​const.go Retains path documentation without the suppression.
aks-node-controller/​checkhotfix.go Uses typed error extraction for fallback decisions.
aks-node-controller/​checkhotfix_test.go Uses a dedicated empty-value assertion.
aks-node-controller/​app.go Modernizes protobuf access, iteration, and error extraction.
aks-node-controller/​app_test.go Uses dedicated empty-value assertions.
.golangci.yaml Resets lint policy with focused settings and exceptions.

Review effort: Balanced

- exhaustive: proto enum switches must list every value.
- unparam: remove always-constant params from addSecret and strKeyValToMapBool.
- dupl: removed; its size threshold flags intentional similar code.
- revive unexported-return: disabled; it reports NewAgentBaker on Go 1.26
  but not on Go 1.27, so a //nolint was unused in CI.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 22, 2026 22:37

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues are recorded for the lint-configuration simplification and related Go updates.

No open issues 🎉

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings November 24, 2026 23:13
@github-actions

Copy link
Copy Markdown
Contributor

Code Coverage

Package Line Rate Health
test 0% ❌
windows 27% ❌
parts_windows Package 1 74% ➖
staging_cse_windows Package 1 72% ➖
debug 0% ❌
provisioningscripts 2% ❌
Summary 40% (2073 / 7280) ❌

@github-actions

Copy link
Copy Markdown
Contributor

Code Coverage

Package Line Rate Health
shellspec spec 30% ❌
Summary 30% (5106 / 16908) ❌

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

There are no active review issues blocking approval.

No open issues 🎉

Review effort: Balanced

@github-actions

Copy link
Copy Markdown
Contributor

Code Coverage

Package Line Rate Health
github.com/Azure/agentbaker/aks-live-patching/pkg/status 100% ✔
github.com/Azure/agentbaker/apiserver 24% ❌
github.com/Azure/agentbaker/cmd 0% ❌
github.com/Azure/agentbaker/cmd/starter 0% ❌
github.com/Azure/agentbaker/fuzz/api 0% ❌
github.com/Azure/agentbaker/hotfix/render-nodecustomdata 35% ❌
github.com/Azure/agentbaker/pkg/agent 79% ➖
github.com/Azure/agentbaker/pkg/agent/datamodel 78% ➖
github.com/Azure/agentbaker/pkg/agent/toggles 0% ❌
github.com/Azure/agentbaker/pkg/vhdbuilder/datamodel 87% ✔
github.com/Azure/agentbaker/aks-node-controller 73% ➖
github.com/Azure/agentbaker/aks-node-controller/common 100% ✔
github.com/Azure/agentbaker/aks-node-controller/helpers 68% ➖
github.com/Azure/agentbaker/aks-node-controller/parser 88% ✔
github.com/Azure/agentbaker/aks-node-controller/pkg/gpu 100% ✔
github.com/Azure/agentbaker/aks-node-controller/pkg/nodeconfigutils 91% ✔
github.com/Azure/agentbaker/aks-node-controller/utils 0% ❌
Summary 84% (6228 / 8196) ✔

@r2k1
Artur Khantimirov (r2k1) merged commit 0ec0b1a into dev Nov 25, 2026
50 of 52 checks passed
@r2k1
Artur Khantimirov (r2k1) deleted the r2k1-reset-linter-settings branch November 25, 2026 03:36
Artur Khantimirov (r2k1) added a commit that referenced this pull request Nov 26, 2026
Rebase onto dev after #10150. Use strings.SplitSeq, give gosec G302
directives a reason, drop gochecknoglobals directives, and ignore the
darwin syscall.Sync error.

AB#40892331

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants