-
Notifications
You must be signed in to change notification settings - Fork 260
feat: [NPM] Add config file and feature toggles #979
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
Conversation
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.
few organizational nitpicks, ❤️ consolidating on cobra and a proper config pkg
npm/cmd/main.go
Outdated
|
|
||
| func init() { | ||
| cobra.OnInitialize(initConfig) | ||
| rootCmd.Flags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.azure-npm-debug-cli.yaml)") |
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.
help string is misleading, maybe:
| rootCmd.Flags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.azure-npm-debug-cli.yaml)") | |
| rootCmd.Flags().StringVar(&cfgFile, "config", "", fmt.Sprintf("config file (default is %s)", npmconfig.GetConfigPath())) |
npm/cmd/main.go
Outdated
| config := &npmconfig.Config{} | ||
| err := viper.Unmarshal(config) | ||
| if err != nil { | ||
| fmt.Printf("unable to decode into config struct, %v", err) |
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.
since this is a RunE, probably better to wrap and return
npm/cmd/main.go
Outdated
| fmt.Printf("unable to decode into config struct, %v", err) | ||
| } | ||
|
|
||
| Start(*config) |
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.
similarly, this func should block or return an error, and we should return Start(...)
npm/cmd/main.go
Outdated
| var cfgFile string | ||
|
|
||
| // rootCmd represents the base command when called without any subcommands | ||
| var rootCmd = &cobra.Command{ |
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.
very subjective, but i prefer to put the root command in a root.go, and keep main.go very lean, with only a main() and the min cobra imports
| @@ -1,4 +1,4 @@ | |||
| package cmd | |||
| package main | |||
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.
the package is cmd, isn't it? and we can drop the "cmd" from this filename.
npm/util/errors/errors.go
Outdated
| ) | ||
|
|
||
| var ( | ||
| SrcNotSpecified = errors.New("source not specified") |
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.
should these be in the package where they get used instead of a util?
huntergregory
left a comment
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.
Looks great
|
|
||
| // Start starts shared informers and waits for the shared informer cache to sync. | ||
| func (npMgr *NetworkPolicyManager) Start(stopCh <-chan struct{}) error { | ||
| func (npMgr *NetworkPolicyManager) Start(config npmconfig.Config, stopCh <-chan struct{}) error { |
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.
should we include this argument if we're not using the config here yet?
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.
this is a preliminary change, it will be required when subsequent pr's with resourcehandlers behind toggles are added
|
|
||
| restserver := restserver.NewNpmRestServer(restserver.DefaultHTTPListeningAddress) | ||
| go restserver.NPMRestServerListenAndServe(npMgr) | ||
| go restserver.NPMRestServerListenAndServe(config, npMgr) |
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.
delete "restserver." since you made this a function instead of a method
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.
restserver here is indicative of the package import where NPMRestServerListenAndServe lives, previously in this section it was overloaded as both package import and var declaration
79c61c6 to
cbee786
Compare
a5cbe2a to
9386b1a
Compare
vakalapa
left a comment
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.
Lgtm 🚀
Reason for Change:
Issue Fixed:
Requirements:
Notes: