feat: refactor aks-node-controller to use urfave cli to manually do command line parsing, setting#8397
Conversation
…ommand line parsing, setting
There was a problem hiding this comment.
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/v3as the CLI framework dependency. - Replaces manual
flagparsing + command registry indirection withcli.Commandwiring inapp.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 |
| 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 | ||
| }, |
There was a problem hiding this comment.
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.
e7cd152 to
60dcb11
Compare
60dcb11 to
85f28e6
Compare
Summary
Refactor
aks-node-controllerCLI parsing to useurfave/cli/v3and simplify the command wiring so it is much closer to the nativecli.Command{...}pattern.What changed
urfave/cli/v3app.gocmd.goindirectionexecuteCommandwrapper with direct command-specific methods:runProvisionCommand(...)runProvisionWaitCommand(...)provisionprovision-waitversion--help--version--dry-runaks-node-controller startedlog 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.