You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by nf...@apache.org on 2019/03/13 22:36:07 UTC

[camel-k] branch master updated: knative: fix copy secrets to env vars

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

nferraro 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 5a8bbe6  knative: fix copy secrets to env vars
5a8bbe6 is described below

commit 5a8bbe695a10e2618d6a953059a6178f4872bdc1
Author: lburgazzoli <lb...@gmail.com>
AuthorDate: Wed Mar 13 19:51:45 2019 +0100

    knative: fix copy secrets to env vars
---
 pkg/trait/knative_service_env.go | 13 ++++++-------
 pkg/util/util.go                 | 17 ++++++-----------
 2 files changed, 12 insertions(+), 18 deletions(-)

diff --git a/pkg/trait/knative_service_env.go b/pkg/trait/knative_service_env.go
index e481706..416d36c 100644
--- a/pkg/trait/knative_service_env.go
+++ b/pkg/trait/knative_service_env.go
@@ -21,12 +21,11 @@ import (
 	"fmt"
 	"strings"
 
+	"github.com/apache/camel-k/pkg/apis/camel/v1alpha1"
 	"github.com/apache/camel-k/pkg/util"
-
+	"github.com/apache/camel-k/pkg/util/envvar"
 	"github.com/apache/camel-k/pkg/util/kubernetes"
 
-	"github.com/apache/camel-k/pkg/apis/camel/v1alpha1"
-	"github.com/apache/camel-k/pkg/util/envvar"
 	serving "github.com/knative/serving/pkg/apis/serving/v1alpha1"
 )
 
@@ -44,12 +43,12 @@ func (t *knativeServiceTrait) bindToEnvVar(e *Environment, service *serving.Serv
 	})
 
 	VisitConfigurations("configmap", e.IntegrationContext, e.Integration, func(cmName string) {
-		cm, err := kubernetes.GetConfigMap(e.C, e.Client, e.Integration.Namespace, cmName)
+		cm, err := kubernetes.GetConfigMap(e.C, e.Client, cmName, e.Integration.Namespace)
 		if err != nil {
 			t.L.Errorf(err, "failed to lookup ConfigMap %s", cmName)
 		}
 		if cm != nil {
-			err = util.ExtractApplicationProperties(cm.Data, func(key string, val string) {
+			err = util.ExtractApplicationPropertiesString(cm.Data, func(key string, val string) {
 				properties[key] = val
 			})
 			if err != nil {
@@ -59,12 +58,12 @@ func (t *knativeServiceTrait) bindToEnvVar(e *Environment, service *serving.Serv
 	})
 
 	VisitConfigurations("secret", e.IntegrationContext, e.Integration, func(secretName string) {
-		cm, err := kubernetes.GetSecret(e.C, e.Client, e.Integration.Namespace, secretName)
+		cm, err := kubernetes.GetSecret(e.C, e.Client, secretName, e.Integration.Namespace)
 		if err != nil {
 			t.L.Errorf(err, "failed to lookup Secret %s", secretName)
 		}
 		if cm != nil {
-			err = util.ExtractEncodedApplicationProperties(cm.Data, func(key string, val string) {
+			err = util.ExtractApplicationPropertiesBytes(cm.Data, func(key string, val string) {
 				properties[key] = val
 			})
 			if err != nil {
diff --git a/pkg/util/util.go b/pkg/util/util.go
index 519b9f6..4ab515f 100644
--- a/pkg/util/util.go
+++ b/pkg/util/util.go
@@ -18,7 +18,6 @@ limitations under the License.
 package util
 
 import (
-	"encoding/base64"
 	"os"
 	"os/signal"
 	"path"
@@ -157,8 +156,8 @@ func FindAllDistinctStringSubmatch(data string, regexps ...*regexp.Regexp) []str
 	return submatchs.List()
 }
 
-// ExtractApplicationProperties --
-func ExtractApplicationProperties(data map[string]string, consumer func(string, string)) error {
+// ExtractApplicationPropertiesString --
+func ExtractApplicationPropertiesString(data map[string]string, consumer func(string, string)) error {
 	pstr, ok := data["application.properties"]
 	if !ok {
 		return nil
@@ -176,18 +175,14 @@ func ExtractApplicationProperties(data map[string]string, consumer func(string,
 	return nil
 }
 
-// ExtractEncodedApplicationProperties --
-func ExtractEncodedApplicationProperties(data map[string][]byte, consumer func(string, string)) error {
-	encoded, ok := data["application.properties"]
+// ExtractApplicationPropertiesBytes --
+func ExtractApplicationPropertiesBytes(data map[string][]byte, consumer func(string, string)) error {
+	pstr, ok := data["application.properties"]
 	if !ok {
 		return nil
 	}
-	decoded, err := base64.StdEncoding.DecodeString(string(encoded))
-	if err != nil {
-		return err
-	}
 
-	p, err := properties.Load(decoded, properties.UTF8)
+	p, err := properties.Load(pstr, properties.UTF8)
 	if err != nil {
 		return err
 	}