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/05/22 21:42:45 UTC

[camel-k] branch master updated: Fix #679: make sure we don't use external deps other than kube in apis

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 03e02e8  Fix #679: make sure we don't use external deps other than kube in apis
03e02e8 is described below

commit 03e02e854bc4fdf17e4a26644c184b6549599ef0
Author: nferraro <ni...@gmail.com>
AuthorDate: Wed May 22 17:57:42 2019 +0200

    Fix #679: make sure we don't use external deps other than kube in apis
---
 pkg/apis/camel/v1alpha1/common_types_support.go      | 20 --------------------
 pkg/apis/camel/v1alpha1/integration_types_support.go | 18 ++++++++++++------
 pkg/trait/trait_catalog.go                           |  2 +-
 pkg/trait/trait_test.go                              |  2 +-
 pkg/trait/util.go                                    | 20 ++++++++++++++++++++
 5 files changed, 34 insertions(+), 28 deletions(-)

diff --git a/pkg/apis/camel/v1alpha1/common_types_support.go b/pkg/apis/camel/v1alpha1/common_types_support.go
index 29c6ef1..2e45408 100644
--- a/pkg/apis/camel/v1alpha1/common_types_support.go
+++ b/pkg/apis/camel/v1alpha1/common_types_support.go
@@ -20,7 +20,6 @@ package v1alpha1
 import (
 	"fmt"
 
-	"github.com/mitchellh/mapstructure"
 	yaml2 "gopkg.in/yaml.v2"
 )
 
@@ -41,22 +40,3 @@ func (flows Flows) Serialize() (string, error) {
 	return string(res), nil
 }
 
-// Decode the trait configuration to a type safe struct
-func (in *TraitSpec) Decode(target interface{}) error {
-	md := mapstructure.Metadata{}
-
-	decoder, err := mapstructure.NewDecoder(
-		&mapstructure.DecoderConfig{
-			Metadata:         &md,
-			WeaklyTypedInput: true,
-			TagName:          "property",
-			Result:           &target,
-		},
-	)
-
-	if err != nil {
-		return err
-	}
-
-	return decoder.Decode(in.Configuration)
-}
diff --git a/pkg/apis/camel/v1alpha1/integration_types_support.go b/pkg/apis/camel/v1alpha1/integration_types_support.go
index 3ed42f5..b008864 100644
--- a/pkg/apis/camel/v1alpha1/integration_types_support.go
+++ b/pkg/apis/camel/v1alpha1/integration_types_support.go
@@ -20,7 +20,6 @@ package v1alpha1
 import (
 	"strings"
 
-	"github.com/apache/camel-k/pkg/util"
 	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
 )
 
@@ -82,12 +81,19 @@ func (is *IntegrationSpec) AddConfiguration(confType string, confValue string) {
 
 // AddDependency --
 func (is *IntegrationSpec) AddDependency(dependency string) {
-	switch {
-	case strings.HasPrefix(dependency, "camel-"):
-		util.StringSliceUniqueAdd(&is.Dependencies, "camel:"+strings.TrimPrefix(dependency, "camel-"))
-	default:
-		util.StringSliceUniqueAdd(&is.Dependencies, dependency)
+	if is.Dependencies == nil {
+		is.Dependencies = make([]string, 0)
 	}
+	newDep := dependency
+	if (strings.HasPrefix(newDep, "camel-")) {
+		newDep = "camel:"+strings.TrimPrefix(dependency, "camel-")
+	}
+	for _, d := range is.Dependencies {
+		if d == newDep {
+			return
+		}
+	}
+	is.Dependencies = append(is.Dependencies, newDep)
 }
 
 // Configurations --
diff --git a/pkg/trait/trait_catalog.go b/pkg/trait/trait_catalog.go
index 339f7db..54b1850 100644
--- a/pkg/trait/trait_catalog.go
+++ b/pkg/trait/trait_catalog.go
@@ -266,7 +266,7 @@ func (c *Catalog) configureTraits(traits map[string]v1alpha1.TraitSpec) error {
 	for id, traitSpec := range traits {
 		catTrait := c.GetTrait(id)
 		if catTrait != nil {
-			if err := traitSpec.Decode(catTrait); err != nil {
+			if err := decodeTraitSpec(&traitSpec, catTrait); err != nil {
 				return err
 			}
 		}
diff --git a/pkg/trait/trait_test.go b/pkg/trait/trait_test.go
index 0cb46a4..bb7eb97 100644
--- a/pkg/trait/trait_test.go
+++ b/pkg/trait/trait_test.go
@@ -157,7 +157,7 @@ func TestTraitDecode(t *testing.T) {
 	env.Integration.Spec.Traits["service"] = svcTrait
 
 	svc := newServiceTrait()
-	err := svcTrait.Decode(svc)
+	err := decodeTraitSpec(&svcTrait, svc)
 
 	assert.Nil(t, err)
 	assert.Equal(t, 7071, svc.Port)
diff --git a/pkg/trait/util.go b/pkg/trait/util.go
index 0a22442..30ab45a 100644
--- a/pkg/trait/util.go
+++ b/pkg/trait/util.go
@@ -24,6 +24,7 @@ import (
 	"regexp"
 	"strings"
 
+	"github.com/mitchellh/mapstructure"
 	"github.com/scylladb/go-set/strset"
 
 	"github.com/apache/camel-k/pkg/apis/camel/v1alpha1"
@@ -131,3 +132,22 @@ func parseCsvMap(csvMap *string) (map[string]string, error) {
 
 	return m, nil
 }
+
+func decodeTraitSpec(in *v1alpha1.TraitSpec, target interface{}) error {
+	md := mapstructure.Metadata{}
+
+	decoder, err := mapstructure.NewDecoder(
+		&mapstructure.DecoderConfig{
+			Metadata:         &md,
+			WeaklyTypedInput: true,
+			TagName:          "property",
+			Result:           &target,
+		},
+	)
+
+	if err != nil {
+		return err
+	}
+
+	return decoder.Decode(in.Configuration)
+}