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

apps: Nest dev-config settings under 'dev' #1286

Merged
merged 3 commits into from
Oct 18, 2022
Merged

Conversation

andrewsomething
Copy link
Member

The flagName method that is used when binding flags to viper only supports nesting a setting three levels deep.

doctl/commands/doit.go

Lines 287 to 292 in de1918a

func flagName(cmd *Command, name string) string {
if cmd.Parent() != nil {
return fmt.Sprintf("%s.%s.%s", cmd.Parent().Name(), cmd.Name(), name)
}
return fmt.Sprintf("%s.%s", cmd.Name(), name)
}

This causes issues for some deeply nested commands. This is particularly problematic for the doctl apps dev config set/unset commands which contain --dev-config flag. The resulting setting for it is config.set.dev-config which conflicts with the top level config setting that should be a string.

When Viper is init-ed, there is a race to register the setting. Sometimes, it results in the config file containing:

config:
  set:
    dev-config: ""

Others, it has the appropriate:

config: /home/<user>/.config/doctl/config.yaml

This breaks things in bad ways causing doctl auth init to fail unpredictably.

This PR forces the dev-config setting to be nested more deeply, i.e. dev.config.set.dev-config. I don't entirely love this solution, but a more general one would be a breaking change to the configuration file format For example, the settings for DOKS are like cluster.create.region rather than kubernetes.cluster.create.region. I think we should prioritize getting this specific problem fixed over a broader solution.

Fixes: #1281, #1280

@andrewsomething andrewsomething requested review from kamaln7, nicktate and a team October 18, 2022 15:54
@andrewsomething andrewsomething changed the title Asb/issues/1280 Oct 18, 2022
bentranter
bentranter previously approved these changes Oct 18, 2022
Copy link
Member

@bentranter bentranter left a comment

Choose a reason for hiding this comment

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

LGTM!

nicktate
nicktate previously approved these changes Oct 18, 2022
Copy link
Contributor

@nicktate nicktate left a comment

Choose a reason for hiding this comment

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

good catch and fix on this -- I'm on board with the current solution as a fast fix

kamaln7
kamaln7 previously approved these changes Oct 18, 2022
@andrewsomething
Copy link
Member Author

Pushed an additional commit to not nest deeper if it is already under dev., e.g. if the app dev build command gets a dev-config flag.

@andrewsomething andrewsomething merged commit 0c91e24 into main Oct 18, 2022
@andrewsomething andrewsomething deleted the asb/issues/1280 branch October 18, 2022 17:27
Copy link
Contributor

@scotchneat scotchneat left a comment

Choose a reason for hiding this comment

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

LGTM

@Marotenten
Copy link

Am waiting for what to do

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