-
Notifications
You must be signed in to change notification settings - Fork 3
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
chore: use cobra and viper for local-artifact-mirror #1487
Conversation
This PR has been released (on staging) and is available for download with a embedded-cluster-smoke-test-staging-app license ID. Online Installer:
Airgap Installer (may take a few minutes before the airgap bundle is built):
Happy debugging! |
204051f
to
e0e3f8b
Compare
dba9c60
to
de5ec7d
Compare
0386970
to
ccecd84
Compare
return nil | ||
}, | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
v := viper.GetViper() |
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 isnt needed
return nil | ||
}, | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
v := viper.GetViper() |
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 isnt needed
return nil | ||
}, | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
v := viper.GetViper() |
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 isnt needed
if err != nil { | ||
panic(fmt.Errorf("unable to get provider from filesystem: %w", err)) | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
v := viper.GetViper() |
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 isnt needed
RunE: func(cmd *cobra.Command, args []string) error { | ||
cmd.Help() | ||
os.Exit(1) | ||
return nil | ||
}, |
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 feel like you can omit this entirely but maybe you tried that
// Support for older env vars | ||
flag := cmd.Flags().Lookup("data-dir") | ||
if flag == nil || !flag.Changed { | ||
if os.Getenv("LOCAL_ARTIFACT_MIRROR_DATA_DIR") != "" { | ||
dataDir = os.Getenv("LOCAL_ARTIFACT_MIRROR_DATA_DIR") | ||
} | ||
} |
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.
could you make a convenience function for this since its repeated 3 times?
v := viper.GetViper() | ||
|
||
// there are some env vars that we still support for backwards compatibility | ||
if os.Getenv("LOCAL_ARTIFACT_MIRROR_PORT") != "" { |
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.
Have you tried v.BindEnv for this?
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 will not work
} | ||
port = int(envvarPort) | ||
} | ||
if os.Getenv("LOCAL_ARTIFACT_MIRROR_DATA_DIR") != "" { |
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.
Have you tried v.BindEnv for this?
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 will not work
if v.Get("data-dir") != nil { | ||
provider = defaults.NewProvider(v.GetString("data-dir")) |
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 does not respect the env var LOCAL_ARTIFACT_MIRROR_DATA_DIR
. You need to use the dataDir
variable
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 we could really benefit from moving the flag and env var parsing to functions and write unit tests
port := v.GetInt("port") | ||
if port == 0 { |
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 overwrites the env var
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 we could really benefit from moving the flag and env var parsing to functions and write unit tests
This reverts commit fbc6db8.
No description provided.