-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
clusterctl generate not accepting environment variable #8097
Comments
/triage accepted |
@fabriziopandini: GuidelinesPlease ensure that the issue body includes answers to the following questions:
For more details on the requirements of such an issue, please see here and ensure that they are met. If this request no longer meets these requirements, the label can be removed In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
Investigating the code I found there is something wrong with this part - tmp, err = envsubst.Eval(tmp, func(in string) string {
- v, _ := variablesClient(in)
+ v := os.Getenv(in)
return v
}) replacing with $ export enableBMHNameBasedPreallocation="true"
$ ./bin/clusterctl generate yaml --from infrastructure-components.yaml | grep enableBMHNameBasedPreallocation
- --enableBMHNameBasedPreallocation=true There may be some issue with But actually, I am not sure if we are using this clusterctl/client/config/reader_memory.go#L63-L68 further investigating looks like it's a viper clusterctl/client/config/reader_viper.go#L173-L178 issue tmp, err = envsubst.Eval(tmp, func(in string) string {
v, err := variablesClient(in)
+ if err != nil {
+ log.Println(err)
+ }
return v
}) $ export enableBMHNameBasedPreallocation="true"
$ ./bin/clusterctl generate yaml --from infrastructure-components.yaml | grep enableBMHNameBasedPreallocation
2023/02/28 22:53:34 Failed to get value for variable "CAPM3_FAST_TRACK". Please set the variable value using os env variables or using the .clusterctl config file
2023/02/28 22:53:34 Failed to get value for variable "enableBMHNameBasedPreallocation". Please set the variable value using os env variables or using the .clusterctl config file
- --enableBMHNameBasedPreallocation=false |
By reading the code in viper, I think this is an issue caused by viper. When viper gets the environment variable, it will convert the environment variable name to uppercase.
if val, ok := v.getEnv(v.mergeWithEnvPrefix(envKey)); ok {
return val
}
func (v *Viper) mergeWithEnvPrefix(in string) string {
if v.envPrefix != "" {
return strings.ToUpper(v.envPrefix + "_" + in)
}
return strings.ToUpper(in)
} So that in this case, viper can not find the environment variable |
I'm not sure if this is an expected behavior or not. If we need to fix it, I'd like to take this up 😄 |
If the problem is in viper assuming the env variables names are all upper case, IMO this should be fixed there. Also the fix proposed above IMO is not correct, because we intentionally use the variableClient everywhere, and the default VariableClient implementation relies on viper to allow users to define clusterctl variables both as env variables or as an entry in the clusterctl config file What we can do at this state in CAPI is to document this viper behavior somewhere in the book, e.g. https://cluster-api.sigs.k8s.io/clusterctl/configuration.html#variables |
Let me take this up since it looks like a tiny fix of the docs. /assign |
One of the variables in CAPM3
infrastructure-components.yaml
does not seem to recognize the environment variable, but happily takes the value fromclusterctl.yaml
.What steps did you take and what happened:
What did you expect to happen:
The flag should take the value from the environment variable (and it should have higher priority than the value in
clusterctl.yaml
).Anything else you would like to add:
The other variable in this file (CAPM3_FAST_TRACK) works as expected and I cannot tell why it is in any way different.
Environment:
kubectl version
): -/etc/os-release
): Ubuntu 22.04/kind bug
/area clusterctl
The text was updated successfully, but these errors were encountered: