Skip to content

Conversation

@matmerr
Copy link
Member

@matmerr matmerr commented Aug 24, 2021

Reason for Change:

Issue Fixed:

Requirements:

Notes:

Copy link
Collaborator

@rbtr rbtr left a 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)")
Copy link
Collaborator

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:

Suggested change
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)
Copy link
Collaborator

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)
Copy link
Collaborator

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{
Copy link
Collaborator

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
Copy link
Collaborator

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.

)

var (
SrcNotSpecified = errors.New("source not specified")
Copy link
Collaborator

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?

Copy link
Contributor

@huntergregory huntergregory left a 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 {
Copy link
Contributor

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?

Copy link
Member Author

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)
Copy link
Contributor

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

Copy link
Member Author

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

https://github.com/Azure/azure-container-networking/pull/979/files#diff-54d87eeeac79a36050c436502ff7ced4a6d8fc1ff6b06ad75e2b719cea0047d4R13

@matmerr matmerr force-pushed the npmconfigfile branch 2 times, most recently from 79c61c6 to cbee786 Compare August 25, 2021 23:53
@matmerr matmerr force-pushed the npmconfigfile branch 3 times, most recently from a5cbe2a to 9386b1a Compare August 31, 2021 19:06
Copy link
Contributor

@vakalapa vakalapa left a comment

Choose a reason for hiding this comment

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

Lgtm 🚀

@matmerr matmerr merged commit 836ee38 into Azure:master Sep 1, 2021
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