You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by lb...@apache.org on 2019/06/05 08:00:54 UTC

[camel-k] branch master updated: Fix #722: filter allowed env variables in Knative

This is an automated email from the ASF dual-hosted git repository.

lburgazzoli pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel-k.git


The following commit(s) were added to refs/heads/master by this push:
     new d179ded  Fix #722: filter allowed env variables in Knative
d179ded is described below

commit d179dedeead6c886edf03dde197260b20baf9660
Author: nferraro <ni...@gmail.com>
AuthorDate: Tue Jun 4 18:14:37 2019 +0200

    Fix #722: filter allowed env variables in Knative
---
 pkg/trait/knative_service.go | 26 +++++++++++++++++++++++++-
 1 file changed, 25 insertions(+), 1 deletion(-)

diff --git a/pkg/trait/knative_service.go b/pkg/trait/knative_service.go
index cb04bc6..042470d 100644
--- a/pkg/trait/knative_service.go
+++ b/pkg/trait/knative_service.go
@@ -207,7 +207,7 @@ func (t *knativeServiceTrait) getServiceFor(e *Environment) *serving.Service {
 	envvar.SetVal(environment, "CAMEL_K_CONF_D", "/etc/camel/conf.d")
 
 	// add env vars from traits
-	for _, envVar := range e.EnvVars {
+	for _, envVar := range t.getAllowedEnvVars(e) {
 		envvar.SetVar(&svc.Spec.RunLatest.Configuration.RevisionTemplate.Spec.Container.Env, envVar)
 	}
 
@@ -218,3 +218,27 @@ func (t *knativeServiceTrait) getServiceFor(e *Environment) *serving.Service {
 
 	return &svc
 }
+
+func (t *knativeServiceTrait) getAllowedEnvVars(e *Environment) []corev1.EnvVar {
+	res := make([]corev1.EnvVar, 0, len(e.EnvVars))
+	for _, env := range e.EnvVars {
+		if env.ValueFrom == nil {
+			// Standard env vars are supported
+			res = append(res, env)
+		} else if env.ValueFrom.FieldRef != nil && env.ValueFrom.FieldRef.FieldPath == "metadata.namespace" {
+			// Namespace is known to the operator
+			res = append(res, corev1.EnvVar{
+				Name:  env.Name,
+				Value: e.Integration.Namespace,
+			})
+		} else if env.ValueFrom.FieldRef != nil {
+			t.L.Infof("Environment variable %s uses fieldRef and cannot be set on a Knative service", env.Name)
+		} else if env.ValueFrom.ResourceFieldRef != nil {
+			t.L.Infof("Environment variable %s uses resourceFieldRef and cannot be set on a Knative service", env.Name)
+		} else {
+			// Other downward APIs should be supported
+			res = append(res, env)
+		}
+	}
+	return res
+}