Skip to content

enable environment based configuration - #64

Merged
Gerrit91 merged 4 commits into
mainfrom
env-vars
Oct 2, 2026
Merged

Gerrit91 merged 4 commits into
mainfrom
env-vars

Conversation

@mwennrich

Copy link
Copy Markdown
Contributor

Description

Example:

before:

$ rm ~/.metal-stack/config.yaml
$ export METAL_STACK_API_URL=https://v2.metal-stack.dev
$ metalctlv2 login
Error: neither BaseURL nor METAL_APIV2_URL were given

(btw, the error message is misleading, setting METAL_APIV2_URL leads to another strange error)

with this PR:

$ rm ~/.metal-stack/config.yaml
$ export METAL_STACK_API_URL=https://v2.metal-stack.dev
$ ./cli/bin/metalctlv2-linux-amd64 login
Starting server at http://127.0.0.1:46263...

@mwennrich
mwennrich requested a review from a team as a code owner September 29, 2026 07:21
@mwennrich
mwennrich requested a review from Gerrit91 September 29, 2026 07:21
@Gerrit91

Copy link
Copy Markdown
Contributor

I think @majst01 insisted on special variable naming. 😅
This would be breaking for the mini-lab and the releases repo, I think. They seem to work there?

https://github.com/metal-stack/mini-lab/blob/master/Makefile#L438-L445

@Gerrit91 Gerrit91 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Sorry, I was mistaken, this PR would just overwrite the client env var when it is set. So this should be good to go.

Comment thread cmd/root.go Outdated
func NewRootCmd(c *config.Config) *cobra.Command {
viper.SetEnvPrefix(strings.ToUpper(config.ConfigDir))
viper.SetEnvKeyReplacer(strings.NewReplacer("-", "_"))
viper.AutomaticEnv()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Maybe we can just whitelist specific flags where it makes sense, otherwise I have the feeling this could lead to behavior that can be sometimes unexpected.

After flag definition we could do:

	viper.MustBindEnv("config")
	viper.MustBindEnv("force-color")
	viper.MustBindEnv("debug")
	viper.MustBindEnv("timeout")
	viper.MustBindEnv("api-url")
	viper.MustBindEnv("api-token")

@Gerrit91
Gerrit91 merged commit 346bb7a into main Oct 2, 2026
8 checks passed
@Gerrit91
Gerrit91 deleted the env-vars branch October 2, 2026 12:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants