diff --git a/pkg/apis/camel/v1alpha1/common_types_support.go b/pkg/apis/camel/v1alpha1/common_types_support.go index 29c6ef1d66..2e45408707 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 3ed42f5ff7..b008864888 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 339f7db93a..54b1850a63 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 0cb46a4205..bb7eb97193 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 0a22442662..30ab45a22e 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) +}