Skip to content

Commit

Permalink
knative: fix copy secrets to env vars
Browse files Browse the repository at this point in the history
  • Loading branch information
lburgazzoli authored and nicolaferraro committed Mar 13, 2019
1 parent eaed6b9 commit 5a8bbe6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 18 deletions.
13 changes: 6 additions & 7 deletions pkg/trait/knative_service_env.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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 {
Expand All @@ -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 {
Expand Down
17 changes: 6 additions & 11 deletions pkg/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ limitations under the License.
package util

import (
"encoding/base64"
"os"
"os/signal"
"path"
Expand Down Expand Up @@ -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
Expand All @@ -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
}
Expand Down

0 comments on commit 5a8bbe6

Please sign in to comment.