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

(#5522) Enhance environment trait to include values from secrets/conf… #5639

Closed
wants to merge 1 commit into from

Conversation

tdiesler
Copy link
Contributor

No description provided.

Copy link
Contributor

⚠️ Unit test coverage report - coverage decreased from 39.9% to 39.8% (-0.1%)

Copy link
Contributor

@squakez squakez left a comment

Choose a reason for hiding this comment

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

Thanks for the work. However, I think this is going too deep in introspecting the value provided by the user. The operator should not peek at any config or secret for a matter of sensitive data. In fact, the goal of the feature is to let the user only provide the configuration and the goal of the operator should be syntactic sugar, transforming the trait parameter into the env container format. We should not worry if the user has provided a missing value, this should be an error that the rest of kubernetes logic should worry about.

Also, it would be better to have some unit test and increase coverage. E2E are fine, but, they must be in conjunction with unit test.

e2e/advanced/environment_test.go Outdated Show resolved Hide resolved
e2e/advanced/environment_test.go Outdated Show resolved Hide resolved
@@ -29,6 +29,7 @@ type EnvironmentTrait struct {
HTTPProxy *bool `property:"http-proxy" json:"httpProxy,omitempty"`
// A list of environment variables to be added to the integration container.
// The syntax is KEY=VALUE, e.g., `MY_VAR="my value"`.
// The value may also be a reference to a configmap or secret, e.g. `MY_VAR=configmap:my-cm/my-cm-key`
Copy link
Contributor

Choose a reason for hiding this comment

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

You need to perform make generate to regen the spec and documentation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I unfortunately get an NPE when running this on my Mac as well as on some Linux server

Copy link
Contributor

Choose a reason for hiding this comment

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

Okey, we have an auto regen in the nightly so it will be eventually sync-ed, but you should report this to get it sorted.

pkg/util/property/property.go Outdated Show resolved Hide resolved
pkg/trait/environment.go Outdated Show resolved Hide resolved
@tdiesler
Copy link
Contributor Author

Thanks for the work. However, I think this is going too deep in introspecting the value provided by the user. The operator should not peek at any config or secret for a matter of sensitive data. In fact, the goal of the feature is to let the user only provide the configuration and the goal of the operator should be syntactic sugar, transforming the trait parameter into the env container format. We should not worry if the user has provided a missing value, this should be an error that the rest of kubernetes logic should worry about.

Of course, I should have thought about that and read the issue description properly. I'll have something alternative to look at later today.

Copy link
Contributor

⚠️ Unit test coverage report - coverage decreased from 39.9% to 39.8% (-0.1%)

@tdiesler tdiesler force-pushed the ghi5522 branch 2 times, most recently from 88509c0 to 9f64364 Compare June 17, 2024 10:51
@tdiesler tdiesler requested a review from squakez June 17, 2024 10:56
@@ -29,6 +29,7 @@ type EnvironmentTrait struct {
HTTPProxy *bool `property:"http-proxy" json:"httpProxy,omitempty"`
// A list of environment variables to be added to the integration container.
// The syntax is KEY=VALUE, e.g., `MY_VAR="my value"`.
// The value may also be a reference to a configmap or secret, e.g. `MY_VAR=configmap:my-cm/my-cm-key`
Copy link
Contributor

Choose a reason for hiding this comment

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

Okey, we have an auto regen in the nightly so it will be eventually sync-ed, but you should report this to get it sorted.

pkg/trait/environment.go Outdated Show resolved Hide resolved

func setValFromConfigMapKeySelector(vars *[]corev1.EnvVar, envName string, path string) error {
vs, err := v1.DecodeValueSource(path, "", "invalid configmap reference: "+path)
Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, I only gave you the link to the struct without explaining how I was thinking to use it. If you see, the object is already in charge to decode a string of type configmap|secret:my-val. The idea is to leverage such an abstraction by passing the user value without worrying about the type. Then, we can iterate over such objects and again, just setting corev1.ConfigMapKeySelector if such value is not nil, or corev1.SecretMapKeySelector accordingly. This would reduce the need to have these setValFromXYZKeySelector funcs

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can this really be optimised without loosing specific error messages and the override of potentially existing EnvVarSource for a given key? I don't really understand why the if envVar := envvar.Get(*vars, envName); envVar != nil check is necessary. Should we get rid of that?

These setValFromXYZKeySelector funcs are mainly there for better readability. I could put the code in the above switch but there isn't any redundant duplication here afaict.

Copy link
Contributor

Choose a reason for hiding this comment

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

You don't need to provide specialized error messages. This can be much more compacted (hence more maintainable and less error prone) by:

  1. If not configmap/secret, just do the normal logic
  2. if configmap/secret, decode the parameter (note that it returns an error we can bubble up, the operator would know what to do with it)
  3. if the decoded value is a configmap (check its decoded struct is not nil), add it as a configmap, otherwise add as a secret
    I don't see the need to verify if the env var already exists either. If it exists by any chance, we are just setting it again.

@tdiesler tdiesler force-pushed the ghi5522 branch 2 times, most recently from b8a3796 to cf56225 Compare June 18, 2024 12:29
@tdiesler
Copy link
Contributor Author

Failed (unrelated) in ...
❌ TestOLMOperatorUpgrade

@squakez
Copy link
Contributor

squakez commented Aug 8, 2024

Superseded by #5754

@squakez squakez closed this Aug 8, 2024
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.

2 participants