Skip to content

Replace Viper with encoding/json for config loading#143

Merged
wenxuan0923 merged 3 commits intomainfrom
wenx/replace-viper
Apr 14, 2026
Merged

Replace Viper with encoding/json for config loading#143
wenxuan0923 merged 3 commits intomainfrom
wenx/replace-viper

Conversation

@wenxuan0923
Copy link
Copy Markdown
Collaborator

@wenxuan0923 wenxuan0923 commented Apr 14, 2026

Replace Viper with encoding/json for config loading. encoding/json has no concept of a key-path delimiter and preserves map keys exactly as written. As a side effect: Viper's implicit AKS_NODE_CONTROLLER_* env-var override feature is removed. It was untested, undocumented, and its key-mapping behavior (lowercasing all field names) was fragile. No existing code or scripts relied on it.

Comment thread pkg/config/config.go Fixed
@wenxuan0923 wenxuan0923 deployed to e2e-testing April 14, 2026 17:29 — with GitHub Actions Active
@wenxuan0923 wenxuan0923 marked this pull request as ready for review April 14, 2026 18:01
Copilot AI review requested due to automatic review settings April 14, 2026 18:01
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

This PR replaces Viper-based config loading with encoding/json to preserve JSON map keys exactly (notably dotted Kubernetes label keys) and removes implicit env-var override behavior.

Changes:

  • Replace Viper config parsing with os.ReadFile + json.Unmarshal.
  • Adjust managed identity “explicitly set” detection to rely on JSON pointer presence.
  • Add regression tests ensuring node label keys with dots/slashes are preserved.

Reviewed changes

Copilot reviewed 4 out of 5 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
pkg/config/config.go Removes Viper and loads config JSON directly with encoding/json; updates MI presence tracking.
pkg/config/config_test.go Adds tests to ensure node label keys (including dotted segments) survive config load unchanged.
pkg/config/structs.go Removes Viper-specific comment from MI configuration helper.
go.mod Drops Viper dependency and associated indirect deps.
go.sum Removes checksums for Viper and transitive dependencies.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread pkg/config/config_test.go
Comment on lines +1159 to +1163
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()

configJSON := fmt.Sprintf(baseAzureJSON, tt.labelsJSON)
Copy link

Copilot AI Apr 14, 2026

Choose a reason for hiding this comment

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

t.Parallel() inside a range loop subtest captures the loop variable tt. On Go versions prior to 1.22 this can cause all parallel subtests to read the final tt value (flaky/incorrect assertions). Rebind tt := tt (or index into the slice) before t.Run to make the tests correct across Go versions.

Copilot uses AI. Check for mistakes.
Comment thread pkg/config/config.go
Comment on lines +47 to 55
data, err := os.ReadFile(filepath.Clean(configPath))
if err != nil {
return nil, fmt.Errorf("failed to read config file at %s: %w", configPath, err)
}

// Unmarshal config
config := &Config{}
if err := v.Unmarshal(config); err != nil {
if err := json.Unmarshal(data, config); err != nil {
return nil, fmt.Errorf("error unmarshaling config: %w", err)
}
Copy link

Copilot AI Apr 14, 2026

Choose a reason for hiding this comment

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

json.Unmarshal silently ignores unknown fields, which can allow config typos to go unnoticed (potentially leading to confusing runtime behavior). Consider decoding via json.Decoder with DisallowUnknownFields() and returning an error that includes the configPath to make misconfigurations easier to diagnose.

Copilot uses AI. Check for mistakes.
Comment thread pkg/config/config_test.go
tests := []struct {
name string
labelsJSON string
expectedLabels map[string]string // only the user-supplied labels; defaults are checked separately
Copy link

Copilot AI Apr 14, 2026

Choose a reason for hiding this comment

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

The inline comment says “defaults are checked separately”, but this test function doesn’t appear to verify defaults (and there’s no pointer here to where that happens). Either add an explicit assertion for expected default labels in this test, or adjust/remove the comment to avoid misleading future maintainers.

Suggested change
expectedLabels map[string]string // only the user-supplied labels; defaults are checked separately
expectedLabels map[string]string // labels expected to be preserved from the config file

Copilot uses AI. Check for mistakes.
@wenxuan0923 wenxuan0923 merged commit 0a130b5 into main Apr 14, 2026
11 checks passed
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.

4 participants