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

Creating bool debug #1469

Merged
merged 9 commits into from
Aug 28, 2024
Merged

Creating bool debug #1469

merged 9 commits into from
Aug 28, 2024

Conversation

JaylonmcShan03
Copy link
Contributor

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

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

@JaylonmcShan03 JaylonmcShan03 requested a review from a team as a code owner August 28, 2024 17:14
helm-framework/helm/provider.go Show resolved Hide resolved
debug := false
if os.Getenv("HELM_DEBUG") == "true" {
debug = true
}
// Override environment variables if the configuration values are provided
Copy link
Contributor

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.

  1. Getting the HELM_DEBUG where it's "true" will mark `debug = true
  2. 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"

Copy link
Contributor Author

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.

Copy link
Contributor

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:

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 
}

Copy link
Contributor Author

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!

Copy link
Contributor

@BBBmau BBBmau Aug 28, 2024

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

Copy link
Contributor Author

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()
}`

Copy link
Contributor

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.

debug = fmt.Sprintf("%t", config.Debug.ValueBool())
}

debug := os.Getenv("HELM_DEBUG") == "true" || config.Debug.ValueBool()
Copy link
Contributor

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:

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.

Copy link
Contributor

@BBBmau BBBmau left a comment

Choose a reason for hiding this comment

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

nice red diff! 🎉

@JaylonmcShan03 JaylonmcShan03 merged commit 82b6aae into helm-framework Aug 28, 2024
2 checks passed
@JaylonmcShan03 JaylonmcShan03 deleted the Creating-bool-debug branch August 28, 2024 20:24
JaylonmcShan03 added a commit that referenced this pull request Oct 8, 2024
* 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants