squakez commented on code in PR #5639: URL: https://github.com/apache/camel-k/pull/5639#discussion_r1642872536
########## 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: 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 -- 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: commits-unsubscr...@camel.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org