-
Notifications
You must be signed in to change notification settings - Fork 207
Define and implement command line parsing with Options struct #1984
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: Etai Lev Ran <[email protected]>
Signed-off-by: Etai Lev Ran <[email protected]>
Signed-off-by: Etai Lev Ran <[email protected]>
✅ Deploy Preview for gateway-api-inference-extension ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: elevran The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
|
/test pull-gateway-api-inference-extension-test-e2e-main |
Signed-off-by: Etai Lev Ran <[email protected]>
|
/test pull-gateway-api-inference-extension-test-unit-main |
| zapopts := zap.Options{ | ||
| Development: true, | ||
| } | ||
| gfs := goflag.NewFlagSet("zap", goflag.ExitOnError) | ||
| opts.BindFlags(gfs) // zap expects a standard Go FlagSet and pflag.FlagSet is not compatible. | ||
| flag.CommandLine.AddGoFlagSet(gfs) | ||
| flag.Parse() | ||
| initLogging(&opts) | ||
| gfs := flag.NewFlagSet("zap", flag.ExitOnError) | ||
| zapopts.BindFlags(gfs) // zap expects a standard Go FlagSet and pflag.FlagSet is not compatible. | ||
| pflag.CommandLine.AddGoFlagSet(gfs) | ||
| opts.AddFlags(pflag.CommandLine) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we move this part inside options? or is there a reason for it being here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe also the pflag.Parse itself, and then wrap it with a single options.Parse function?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there's reason: the zap.Options are used in initLogging in main, and not accessible in runserver.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what are your thought about moving initLogging to be called from options.Complete and then move all this to options.go file?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think runner logging belongs in options.go
I will thin if there's a way to bind the zap options so it's "hidden" in Options and not expose in runner's main, but otherwise tend to leave as is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the following would work in options.Complete()
// ensure zap log level is set - explicitly by user or from "-v"
zapLogLevelFlag := pflag.CommandLine.Lookup(ZapLogLevelFlagName)
if zapLogLevelFlag != nil && !zapLogLevelFlag.Changed { // not set explicitly
zapLevel := -1 * opts.LogVerbosity // See https://pkg.go.dev/sigs.k8s.io/controller-runtime/pkg/log/zap#Options.Level
zapLevelString := fmt.Sprintf("%d", zapLevel)
if err := zapLogLevelFlag.Value.Set(zapLevelString); err != nil {
return fmt.Errorf("failed to set %q to %s: %w", ZapLogLevelFlagName, zapLevelString, err)
}
zapLogLevelFlag.Changed = true
}and then the runner code becomes:
func initLogging(opts *zap.Options) {
logger := zap.New(zap.UseFlagOptions(opts), zap.RawZapOpts(uberzap.AddCaller()))
ctrl.SetLogger(logger)
}Not sure it is justified to make this change.
…er pflag.Parse() Signed-off-by: Etai Lev Ran <[email protected]>
Signed-off-by: Etai Lev Ran <[email protected]>
|
PR needs rebase. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
What type of PR is this?
/kind feature
What this PR does / why we need it:
Move EPP command line defintion and handling into an Options struct, that includes CLI flag binding and value validation.
Which issue(s) this PR fixes:
Refs #1947
Does this PR introduce a user-facing change?: