Skip to content

feat: refactor aks-node-controller to use urfave cli to manually do command line parsing, setting#8397

Merged
awesomenix merged 2 commits intomainfrom
nishp/fix/e2e/azurecni
Apr 24, 2026
Merged

feat: refactor aks-node-controller to use urfave cli to manually do command line parsing, setting#8397
awesomenix merged 2 commits intomainfrom
nishp/fix/e2e/azurecni

Conversation

@awesomenix
Copy link
Copy Markdown
Contributor

Summary

Refactor aks-node-controller CLI parsing to use urfave/cli/v3 and simplify the command wiring so it is much closer to the native cli.Command{...} pattern.

What changed

  • migrated CLI parsing from manual argument/flag handling to urfave/cli/v3
  • flattened command construction into app.go
  • removed the extra cmd.go indirection
  • replaced the generic executeCommand wrapper with direct command-specific methods:
    • runProvisionCommand(...)
    • runProvisionWaitCommand(...)
  • kept the existing command behavior for:
    • provision
    • provision-wait
    • version
    • --help
    • --version
    • --dry-run
  • preserved custom exit-code behavior instead of relying on default CLI error handling
  • limited the aks-node-controller started log to operational commands only (provision / provision-wait)

Why

This change keeps the important ANC-specific behavior (custom exit codes, event logging, self-update on operational paths, fail-fast handling) while making the CLI setup
much easier to read and maintain.

Scope

This PR is intentionally limited to CLI refactoring and simplification.

It does not change the shell/wrapper hotfix installation approach or remove the existing Go self-update flow.

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

Refactors aks-node-controller command-line handling to use urfave/cli/v3, consolidating command wiring into app.go while aiming to preserve existing command behavior and ANC-specific exit-code semantics.

Changes:

  • Introduces urfave/cli/v3 as the CLI framework dependency.
  • Replaces manual flag parsing + command registry indirection with cli.Command wiring in app.go.
  • Splits operational flows into command-specific helpers (runProvisionCommand, runProvisionWaitCommand).

Reviewed changes

Copilot reviewed 2 out of 3 changed files in this pull request and generated 1 comment.

File Description
aks-node-controller/app.go Replaces manual CLI parsing/dispatch with urfave/cli/v3 commands and new command-specific execution methods
aks-node-controller/go.mod Adds github.com/urfave/cli/v3 dependency (and promotes yaml.v3 to direct)
aks-node-controller/go.sum Adds sums for github.com/urfave/cli/v3

Comment on lines +66 to +106
cmd := &cli.Command{
Name: "aks-node-controller",
Usage: "Parse contract and run csecmd",
Version: Version,
ExitErrHandler: func(context.Context, *cli.Command, error) {
// Return errors to the caller so exit codes are derived consistently in one place.
},
Action: func(context.Context, *cli.Command) error {
if len(args) > 1 {
return fmt.Errorf("unknown command: %s", args[1])
}
return errors.New("missing command argument")
},
Commands: []*cli.Command{
{
Name: "provision",
Usage: "Run node provisioning",
Flags: []cli.Flag{
&cli.StringFlag{Name: "provision-config", Usage: "path to the provision config file"},
&cli.StringFlag{Name: "nbc-cmd", Usage: "path to the NBC command file"},
&cli.BoolFlag{Name: "dry-run", Usage: "print the command that would be run without executing it"},
},
Action: func(ctx context.Context, cmd *cli.Command) error {
return a.runProvisionCommand(ctx, ProvisionFlags{
ProvisionConfig: cmd.String("provision-config"),
NBCCmd: cmd.String("nbc-cmd"),
}, cmd.Bool("dry-run"))
},
},
{
Name: "provision-wait",
Usage: "Wait for provisioning to complete",
Action: func(ctx context.Context, cmd *cli.Command) error {
provisionStatusFiles := ProvisionStatusFiles{
ProvisionJSONFile: provisionJSONFilePath,
ProvisionCompleteFile: provisionCompleteFilePath,
}
provisionOutput, err := a.runProvisionWaitCommand(ctx, provisionStatusFiles)
_, _ = fmt.Fprintln(cmd.Root().Writer, provisionOutput)
return err
},
Copy link

Copilot AI Apr 24, 2026

Choose a reason for hiding this comment

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

With urfave/cli, flag parsing errors for provision (e.g., unknown flag, missing flag value) will occur before runProvisionCommand runs, so writeCompleteFileOnError(...) is never invoked. That can leave provision.complete/provision.json unwritten and cause provision-wait to block until its context times out. Consider handling CLI parse/usage errors in ExitErrHandler (or equivalent hook) to emit a ProvisionResult (ExitCode=240 + error) and write the sentinel files for provision invocations, matching the previous fail-fast behavior.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

should be fine

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

Copilot reviewed 6 out of 7 changed files in this pull request and generated 1 comment.

Comment thread aks-node-controller/app.go
@awesomenix awesomenix merged commit 51cec57 into main Apr 24, 2026
29 of 33 checks passed
@awesomenix awesomenix deleted the nishp/fix/e2e/azurecni branch April 24, 2026 21:00
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