Skip to content

Fix provider env var panic#1402

Merged
liranmauda merged 1 commit intonoobaa:masterfrom
bernerhat:fix-provider-env-panic
Aug 21, 2024
Merged

Fix provider env var panic#1402
liranmauda merged 1 commit intonoobaa:masterfrom
bernerhat:fix-provider-env-panic

Conversation

@bernerhat
Copy link
Contributor

Explain the changes

  1. moved the check for the env var to the appropriate location
  2. changed env var location in yaml file and made it optional

Issues: Fixed #xxx / Gap #xxx

  1. https://bugzilla.redhat.com/show_bug.cgi?id=2301889
  2. change introduced as part of epic were causing clusters deployed in provider mode to fail deployment, operator crashed while trying to change env var value which was not found.

Testing Instructions:

  • Doc added/updated
  • Tests added

@bernerhat bernerhat force-pushed the fix-provider-env-panic branch 2 times, most recently from 5a1f175 to 7400d1d Compare August 1, 2024 16:29
@liranmauda liranmauda requested a review from dannyzaken August 4, 2024 11:51
Copy link
Contributor

@liranmauda liranmauda left a comment

Choose a reason for hiding this comment

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

LGTM
@dannyzaken WDYT?

@bernerhat bernerhat force-pushed the fix-provider-env-panic branch 3 times, most recently from 4179fa8 to 2fa4c94 Compare August 5, 2024 15:20
@pull-request-size pull-request-size bot added size/M and removed size/S labels Aug 5, 2024
@bernerhat bernerhat force-pushed the fix-provider-env-panic branch from 2fa4c94 to a7e22b6 Compare August 5, 2024 15:30
annotationValue, annotationExists := util.GetAnnotationValue(r.NooBaa.Annotations, "MulticloudObjectGatewayProviderMode")
annotationBoolVal := false
if annotationExists {
annotationBoolVal = strings.ToLower(annotationValue) == strconv.FormatBool(true)
Copy link
Member

Choose a reason for hiding this comment

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

Why is strconv.FormatBool necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

to prevent typos at the very least, i try to avoid hardcoding text strings if not necessary

Copy link
Member

@dannyzaken dannyzaken left a comment

Choose a reason for hiding this comment

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

There is no need to pass the env through the noobaa-config config map. the purpose of this configmap is to provide configurable envs that can be modified by the user. This env is controlled by the annotation and is not meant to be configured by the user.

I suggest adding this env to the setDesiredCoreEnv function. add a case for this env that will set the value according to the annotation

@bernerhat bernerhat force-pushed the fix-provider-env-panic branch 2 times, most recently from 42ceadb to 88cefae Compare August 7, 2024 08:39
@pull-request-size pull-request-size bot added size/S and removed size/M labels Aug 7, 2024
@bernerhat bernerhat force-pushed the fix-provider-env-panic branch from 88cefae to 12186c5 Compare August 7, 2024 08:55
@Neon-White Neon-White requested a review from dannyzaken August 7, 2024 09:04
@bernerhat bernerhat force-pushed the fix-provider-env-panic branch from 12186c5 to 4134a70 Compare August 7, 2024 09:30
Copy link
Member

@dannyzaken dannyzaken left a comment

Choose a reason for hiding this comment

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

one small comment. other than that looks good

annotationValue, annotationExists := util.GetAnnotationValue(r.NooBaa.Annotations, "MulticloudObjectGatewayProviderMode")
annotationBoolVal := false
if annotationExists {
annotationBoolVal = strings.ToLower(annotationValue) == strconv.FormatBool(true)
Copy link
Member

Choose a reason for hiding this comment

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

The strconv is not so readable. Please use a const instead. You can define trueStr or a similar const in the file scope. Use it also for setting the env value below

@bernerhat bernerhat force-pushed the fix-provider-env-panic branch 2 times, most recently from 62df992 to 5f76184 Compare August 14, 2024 11:33
@bernerhat bernerhat requested a review from dannyzaken August 15, 2024 11:22
Comment on lines +444 to +450
if annotationBoolVal {
c.Env[j].Value = "true"
}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if annotationBoolVal {
c.Env[j].Value = "true"
}
if annotationBoolVal {
c.Env[j].Value = trueStr
} else {
c.Env[j].Value = falseStr
}

configMapKeyRef:
name: noobaa-config
key: NOOBAA_LOG_LEVEL
- name: CONFIG_JS_RESTRICT_RESOURCE_DELETION
Copy link
Contributor

Choose a reason for hiding this comment

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

An env variable should not start with CONFIG_JS_

Suggested change
- name: CONFIG_JS_RESTRICT_RESOURCE_DELETION
- name: RESTRICT_RESOURCE_DELETION

} else {
c.Env[j].Value = ""
}
case "CONFIG_JS_RESTRICT_RESOURCE_DELETION":
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
case "CONFIG_JS_RESTRICT_RESOURCE_DELETION":
case "RESTRICT_RESOURCE_DELETION":

@bernerhat bernerhat force-pushed the fix-provider-env-panic branch from 5f76184 to 4b90303 Compare August 19, 2024 07:26
name: noobaa-config
key: NOOBAA_LOG_LEVEL
- name: RESTRICT_RESOURCE_DELETION
value: "false"
Copy link
Contributor

Choose a reason for hiding this comment

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

We do not need a default.
anything other than true will result in false.
With that said, we can keep it to make it more explicit.
@dannyzaken WDYT?

Copy link
Member

Choose a reason for hiding this comment

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

we can leave the default

Copy link
Contributor

Choose a reason for hiding this comment

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

@liranmauda Can you please approve the PR so this could merge

@pull-request-size pull-request-size bot added size/M and removed size/S labels Aug 19, 2024
@bernerhat bernerhat force-pushed the fix-provider-env-panic branch from 5ccdd5d to 4b90303 Compare August 19, 2024 14:55
@pull-request-size pull-request-size bot added size/S and removed size/M labels Aug 19, 2024
@bernerhat bernerhat force-pushed the fix-provider-env-panic branch from 4b90303 to c1d5ba3 Compare August 19, 2024 14:56
moved check location and and set env var to optional

Signed-off-by: Amit Berner <aberner@redhat.com>
@bernerhat bernerhat force-pushed the fix-provider-env-panic branch from c1d5ba3 to b014677 Compare August 19, 2024 15:03
@liranmauda liranmauda merged commit 3e21d19 into noobaa:master Aug 21, 2024
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.

4 participants