-
Notifications
You must be signed in to change notification settings - Fork 374
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
Creating bool debug #1469
Creating bool debug #1469
Conversation
…rm-provider-helm into Creating-bool-debug
helm-framework/helm/provider.go
Outdated
debug := false | ||
if os.Getenv("HELM_DEBUG") == "true" { | ||
debug = true | ||
} | ||
// Override environment variables if the configuration values are provided |
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'm curious how the config overrides the environment variables if both cases set the variable to true.
- Getting the
HELM_DEBUG
where it's "true" will mark `debug = true - Getting the configuration values will mark
debug = true
Yet i don't see how we apply the override of config values instead of env variables if:
configuration values are set AND
HELM_DEBUG
envvar is set to "true"
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.
the logic sets debug to true if either the environment variable HELM_DEBUG is "true" or if the configuration explicitly sets debug to true.
with my understanding this ensures that debugging is enabled if either source requests it.
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.
In that case we should consider treating the two conditionals as one:
terraform-provider-helm/helm-framework/helm/provider.go
Lines 342 to 348 in 393479e
debug := false | |
if os.Getenv("HELM_DEBUG") == "true" { | |
debug = true | |
} | |
if !config.Debug.IsNull() { | |
debug = true | |
} |
can be switched to:
debug := false
if os.Getenv("HELM_DEBUG") == "true" || !config.Debug.IsNull() {
debug = true
}
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.
Gotcha! Due to the previous confusion where I treated two conditions as one, it wasn't very clear what was going on. But these checks are self explanatory so I will update it!
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.
At a second glance I'm wondering if it's right to use !config.Debug.IsNull()
Since from my understanding if a user sets debug = false
it is technically not null anymore and would return true and mark debug = true
despite debug being set to false in the config. Thoughts?
Edit: This might be better suited: https://pkg.go.dev/github.com/hashicorp/[email protected]/types/basetypes#BoolValue.ValueBool
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.
Good catch, you are right if the user sets debug. = false, due to it check if its not null it was simply just override it to true. I believe in order to properly handle this scenario > we should check both the null state and the actual boolean value of the Debug field.
I believe it should look something like this >
`debug := false
if os.Getenv("HELM_DEBUG") == "true" {
debug = true
}
if !config.Debug.IsNull() {
debug = config.Debug.ValueBool()
}`
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 believe we can still keep them as one condition since from the docs it says:
ValueBool returns the known bool value. If Bool is null or unknown, returns false.
So in other words it would return the "known bool value" so it would return true
if debug = true
and false
if debug = false
in config.
if the value is unknown
or Null
would just return false
.
helm-framework/helm/provider.go
Outdated
debug = fmt.Sprintf("%t", config.Debug.ValueBool()) | ||
} | ||
|
||
debug := os.Getenv("HELM_DEBUG") == "true" || config.Debug.ValueBool() |
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.
nice one liner! One last request
Here debug
is initialized on line 342 but is first used here in the provider.go
file:
settings.Debug = debug |
It's best practice to include the variable initialization near the first call of the variable. In order to reduce the need to go searching for where the variable was first set.
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.
nice red diff! 🎉
* Fix acronyms in struct field names in kubeConfig.go and provider.go * Fixed acronym in kubeConfig that wasnt pushed in previous pr * Refactored debug handling to use a boolean variable * removing unnessary comment * Updating the debug two conditionals into one * Fixing edge case logic * Simpliyfing if statements * Fixing location of debug variable
Description
This PR refactors the handling of the debug mode in the Helm provider to use a boolean variable instead of repeated string comparisons.
Acceptance tests
Release Note
Release note for CHANGELOG:
References
Community Note