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

[#981] Avoid using JAVA_ARGS_APPEND for internal configuration #982

Merged
merged 1 commit into from
Jul 29, 2024

Conversation

gaohoward
Copy link
Collaborator

@gaohoward gaohoward commented Jul 12, 2024

This PR add tests on how to properly append to JAVA_ARGS_APPEND env var

@gaohoward gaohoward requested review from gtully and brusdev July 12, 2024 06:15
@gaohoward
Copy link
Collaborator Author

(Test is supposed to fail at the moment until the dependent PR is merged)

@gtully
Copy link
Contributor

gtully commented Jul 12, 2024

In some cases we want to split, but in general the intent is that we use JDK_JAVA_ARGS and we append to any existing value, and JAVA_ARGS_APPEND is a way to override as a duplicate command line argument. They are env vars that are at either end of the java command line.

The user should always have control to override if necessary, it is like a build in escape hatch.

But the append depends on env values. However we can combine, b/c env vars can be dependent.

If the user wants an env var from source, that can be separate and included in the env vars we care about.

I tried a little test of this:

crd.Spec.Env = []corev1.EnvVar{
				{
					Name: "ENV_FROM_X",
					ValueFrom: &corev1.EnvVarSource{
						SecretKeyRef: &corev1.SecretKeySelector{
							LocalObjectReference: corev1.LocalObjectReference{Name: secret.Name},
							Key:                  "envKey",
						},
					}},
				{Name: "JAVA_ARGS_APPEND", Value: "-Dhawtio.realm=console $(ENV_FROM_X)"},
			}

and it works as expected, $(ENV_FROM_X) gets expanded into the value of the envKey from the secret just fine.

@gaohoward
Copy link
Collaborator Author

In some cases we want to split, but in general the intent is that we use JDK_JAVA_ARGS and we append to any existing value, and JAVA_ARGS_APPEND is a way to override as a duplicate command line argument. They are env vars that are at either end of the java command line.

The user should always have control to override if necessary, it is like a build in escape hatch.

But the append depends on env values. However we can combine, b/c env vars can be dependent.

If the user wants an env var from source, that can be separate and included in the env vars we care about.

I tried a little test of this:

crd.Spec.Env = []corev1.EnvVar{
				{
					Name: "ENV_FROM_X",
					ValueFrom: &corev1.EnvVarSource{
						SecretKeyRef: &corev1.SecretKeySelector{
							LocalObjectReference: corev1.LocalObjectReference{Name: secret.Name},
							Key:                  "envKey",
						},
					}},
				{Name: "JAVA_ARGS_APPEND", Value: "-Dhawtio.realm=console $(ENV_FROM_X)"},
			}

and it works as expected, $(ENV_FROM_X) gets expanded into the value of the envKey from the secret just fine.

That makes sense. Thanks!

@gaohoward gaohoward marked this pull request as ready for review July 12, 2024 16:29
@gaohoward
Copy link
Collaborator Author

@gtully test updated. please review. Thanks!

Copy link
Contributor

@gtully gtully left a comment

Choose a reason for hiding this comment

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

I think this is the right approach.

Did you consider doing this check at the validation phase?
I imagine if valueFrom and value are defined that creating the stateful set will fail/error which is very similar. ie: a deployment failure.
If we identify the env vars we modify, in some internal collection - we already use createorappend for those in the code, then we can trap a validation error if any env var matches that set and has valueFrom set.
if that set ever gets out of sync, the stateful set error will be a fallback.
I think it makes sense for us to document or callout the env vars we modify or want to modify. The set should be small.
in the error message we should point to using dependent variables as the desired approach. It can be very specific, and can be very specific, in a validation failure condition/error.

@gaohoward
Copy link
Collaborator Author

validation phase?

I think this is the right approach.

Did you consider doing this check at the validation phase? I imagine if valueFrom and value are defined that creating the stateful set will fail/error which is very similar. ie: a deployment failure. If we identify the env vars we modify, in some internal collection - we already use createorappend for those in the code, then we can trap a validation error if any env var matches that set and has valueFrom set. if that set ever gets out of sync, the stateful set error will be a fallback. I think it makes sense for us to document or callout the env vars we modify or want to modify. The set should be small. in the error message we should point to using dependent variables as the desired approach. It can be very specific, and can be very specific, in a validation failure condition/error.

Yeah I think doing it at validation makes sense. I'll update and add a document about the env vars the operator uses internally. Thanks!

@gaohoward
Copy link
Collaborator Author

@gtully PR updated. Now

  • check valueFrom at validation phase
  • document internal used env vars

@gaohoward gaohoward force-pushed the e_java_args_append branch 2 times, most recently from a40fd17 to 4a9b660 Compare July 25, 2024 03:08
@gaohoward gaohoward requested a review from gtully July 25, 2024 03:08
added tests to show how to append user defined JAVA_ARGS_APPEND env var using ValueFrom field
added document for how to proper use valueFrom for internal env vars
@gaohoward gaohoward merged commit 25673b4 into artemiscloud:main Jul 29, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

CRD env JAVA_ARGS_APPEND fromSource needs to be flagged as invalid
4 participants