Skip to content
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

Merged
merged 1 commit into from
Nov 15, 2024

Conversation

marccampbell
Copy link
Member

No description provided.

Copy link

github-actions bot commented Nov 11, 2024

This PR has been released (on staging) and is available for download with a embedded-cluster-smoke-test-staging-app license ID.

Online Installer:

curl "https://staging.replicated.app/embedded/embedded-cluster-smoke-test-staging-app/ci/appver-dev-ccecd84" -H "Authorization: $EC_SMOKE_TEST_LICENSE_ID" -o embedded-cluster-smoke-test-staging-app-ci.tgz

Airgap Installer (may take a few minutes before the airgap bundle is built):

curl "https://staging.replicated.app/embedded/embedded-cluster-smoke-test-staging-app/ci-airgap/appver-dev-ccecd84?airgap=true" -H "Authorization: $EC_SMOKE_TEST_LICENSE_ID" -o embedded-cluster-smoke-test-staging-app-ci.tgz

Happy debugging!

@marccampbell marccampbell force-pushed the lam-cobra-viper branch 2 times, most recently from 204051f to e0e3f8b Compare November 13, 2024 19:04
@marccampbell marccampbell changed the title use cobra and viper for local-artifact-mirror chore: use cobra and viper for local-artifact-mirror Nov 13, 2024
@marccampbell marccampbell force-pushed the lam-cobra-viper branch 4 times, most recently from dba9c60 to de5ec7d Compare November 15, 2024 13:55
@marccampbell marccampbell marked this pull request as ready for review November 15, 2024 19:13
@marccampbell marccampbell merged commit fbc6db8 into main Nov 15, 2024
65 of 67 checks passed
@marccampbell marccampbell deleted the lam-cobra-viper branch November 15, 2024 20:12
return nil
},
RunE: func(cmd *cobra.Command, args []string) error {
v := viper.GetViper()
Copy link
Member

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()
Copy link
Member

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()
Copy link
Member

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()
Copy link
Member

Choose a reason for hiding this comment

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

this isnt needed

Comment on lines +43 to +47
RunE: func(cmd *cobra.Command, args []string) error {
cmd.Help()
os.Exit(1)
return nil
},
Copy link
Member

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

Comment on lines +40 to +46
// 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")
}
}
Copy link
Member

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") != "" {
Copy link
Member

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?

https://pkg.go.dev/github.com/spf13/viper#BindEnv

Copy link
Member

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") != "" {
Copy link
Member

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?

https://pkg.go.dev/github.com/spf13/viper#BindEnv

Copy link
Member

Choose a reason for hiding this comment

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

This will not work

Comment on lines +62 to +63
if v.Get("data-dir") != nil {
provider = defaults.NewProvider(v.GetString("data-dir"))
Copy link
Member

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

Copy link
Member

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

Comment on lines +72 to +73
port := v.GetInt("port")
if port == 0 {
Copy link
Member

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

Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants