tdiesler commented on code in PR #5639:
URL: https://github.com/apache/camel-k/pull/5639#discussion_r1642985345
##########
pkg/trait/environment.go:
##########
@@ -99,12 +102,85 @@ func (t *environmentTrait) Apply(e *Environment) error {
}
}
- if t.Vars != nil {
- for _, env := range t.Vars {
- k, v := property.SplitPropertyFileEntry(env)
+ for _, env := range t.Vars {
+ k, v := property.SplitPropertyFileEntry(env)
+ switch {
+ case strings.HasPrefix(v, "configmap:"):
+
+ err := setValFromConfigMapKeySelector(&e.EnvVars, k, v)
+ if err != nil {
+ return err
+ }
+ case strings.HasPrefix(v, "secret:"):
+ err := setValFromSecretKeySelector(&e.EnvVars, k, v)
+ if err != nil {
+ return err
+ }
+ default:
envvar.SetVal(&e.EnvVars, k, v)
}
}
+ return nil
+}
+func setValFromConfigMapKeySelector(vars *[]corev1.EnvVar, envName string,
path string) error {
+ vs, err := v1.DecodeValueSource(path, "", "invalid configmap reference:
"+path)
Review Comment:
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.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]