feat(scriptless): compare AKSNodeConfig generated cse cmd with NBC cse cmd#8416
feat(scriptless): compare AKSNodeConfig generated cse cmd with NBC cse cmd#8416
Conversation
There was a problem hiding this comment.
Pull request overview
Adds a diagnostic capability to compare env vars derived from an AKSNodeConfig-generated CSE command vs an NBC “phase 2” CSE command, intended to help validate scriptless provisioning parity.
Changes:
- Add
compareEnvsto diff env vars between--provision-configand--nbc-cmd, plus a parser for env assignments from an NBC one-liner. - Adjust
Provisionselection so NBCCmd execution is skipped when--provision-configis also provided (while still running the comparison). - Add unit tests for env parsing and env comparison via captured
slogoutput.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| aks-node-controller/app.go | Introduces env diffing/parsing utilities and changes Provision flow when both flags are present. |
| aks-node-controller/app_test.go | Adds a custom slog handler to capture logs and tests for env parsing + env comparison behavior. |
Comments suppressed due to low confidence (1)
aks-node-controller/app.go:427
- When both flags are provided, compareEnvs calls buildCmdFromProvisionConfig, and then Provision calls buildCmdFromProvisionConfig again to actually execute. This duplicates JSON parsing and CSE cmd construction. Consider refactoring so the cmd/env derived during comparison is reused (or compareEnvs accepts the already-built exec.Cmd/env map) to avoid the extra work in diagnostic mode.
// If both flags are provided, compare environments before proceeding.
if flags.ProvisionConfig != "" && flags.NBCCmd != "" {
compareEnvs(ctx, flags, a.getNodeCustomDataPath())
}
var cmd *exec.Cmd
if flags.ProvisionConfig != "" {
var err error
cmd, err = buildCmdFromProvisionConfig(ctx, flags.ProvisionConfig)
if err != nil {
| } | ||
|
|
||
| var cmd *exec.Cmd | ||
| if flags.ProvisionConfig != "" { |
There was a problem hiding this comment.
You might need to change teh ordering here. We always prefer nbccsecmd first and then use provisionconfig if nbccsecmd is not present
|
|
||
| // If both flags are provided, compare environments before proceeding. | ||
| if flags.ProvisionConfig != "" && flags.NBCCmd != "" { | ||
| compareEnvs(ctx, flags, a.getNodeCustomDataPath()) |
There was a problem hiding this comment.
might need some kind of error checking/block so any exception or errors here are just gobbled up (so we dont fail provisioning)
Agent-Logs-Url: https://github.com/Azure/AgentBaker/sessions/7c8d3dab-bef8-4048-9015-7456791ea703 Co-authored-by: lilypan26 <106703606+lilypan26@users.noreply.github.com>
| eventLogger.LogEvent("CompareEnvs", "env vars match between provision-config and nbc-cmd", helpers.EventLevelInformational, now, now) | ||
| } else { | ||
| message := fmt.Sprintf("env var differences (%d): %s", len(diffs), strings.Join(diffs, "; ")) | ||
| slog.Info(message) | ||
| eventLogger.LogEvent("CompareEnvs", message, helpers.EventLevelInformational, now, now) |
There was a problem hiding this comment.
compareEnvs calls eventLogger.LogEvent unconditionally. If eventLogger is nil (or becomes nil in future refactors), this panics and relies on the defer/recover to keep provisioning moving, which also logs an error-level "compareEnvs panicked" message. Prefer an explicit nil check (skip event emission when nil) so panics are reserved for truly unexpected failures.
| eventLogger.LogEvent("CompareEnvs", "env vars match between provision-config and nbc-cmd", helpers.EventLevelInformational, now, now) | |
| } else { | |
| message := fmt.Sprintf("env var differences (%d): %s", len(diffs), strings.Join(diffs, "; ")) | |
| slog.Info(message) | |
| eventLogger.LogEvent("CompareEnvs", message, helpers.EventLevelInformational, now, now) | |
| if eventLogger != nil { | |
| eventLogger.LogEvent("CompareEnvs", "env vars match between provision-config and nbc-cmd", helpers.EventLevelInformational, now, now) | |
| } | |
| } else { | |
| message := fmt.Sprintf("env var differences (%d): %s", len(diffs), strings.Join(diffs, "; ")) | |
| slog.Info(message) | |
| if eventLogger != nil { | |
| eventLogger.LogEvent("CompareEnvs", message, helpers.EventLevelInformational, now, now) | |
| } |
40d0b81 to
462b717
Compare
What this PR does / why we need it:
Which issue(s) this PR fixes:
Fixes #