This is an automated email from the ASF dual-hosted git repository. lburgazzoli pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/camel-k.git
commit e7bc5eccadf3c4cd89e998726c01a96e189fc6b7 Author: Luca Burgazzoli <lburgazz...@gmail.com> AuthorDate: Fri Aug 5 11:50:54 2022 +0200 fix: KameletBinding vs Integration traits comparison shouyld be based on the traits configured on the KameletBinding only #3479 --- pkg/controller/integration/kits.go | 8 ++++---- pkg/trait/util.go | 41 +++++++++++++++++++++++--------------- 2 files changed, 29 insertions(+), 20 deletions(-) diff --git a/pkg/controller/integration/kits.go b/pkg/controller/integration/kits.go index 1e4bd9b84..433d96180 100644 --- a/pkg/controller/integration/kits.go +++ b/pkg/controller/integration/kits.go @@ -114,11 +114,11 @@ func integrationMatches(integration *v1.Integration, kit *v1.IntegrationKit) (bo // A kit can be used only if it contains a subset of the traits and related configurations // declared on integration. - itc, err := trait.NewUnstructuredTraitsForIntegration(integration) + itc, err := trait.NewTraitsOptionsForIntegration(integration) if err != nil { return false, err } - ikc, err := trait.NewUnstructuredTraitsForIntegrationKit(kit) + ikc, err := trait.NewTraitsOptionsForIntegrationKit(kit) if err != nil { return false, err } @@ -170,11 +170,11 @@ func kitMatches(kit1 *v1.IntegrationKit, kit2 *v1.IntegrationKit) (bool, error) return false, nil } - c1, err := trait.NewUnstructuredTraitsForIntegrationKit(kit1) + c1, err := trait.NewTraitsOptionsForIntegrationKit(kit1) if err != nil { return false, err } - c2, err := trait.NewUnstructuredTraitsForIntegrationKit(kit2) + c2, err := trait.NewTraitsOptionsForIntegrationKit(kit2) if err != nil { return false, err } diff --git a/pkg/trait/util.go b/pkg/trait/util.go index 737b54883..880098c71 100644 --- a/pkg/trait/util.go +++ b/pkg/trait/util.go @@ -347,11 +347,11 @@ func Equals(i1 Options, i2 Options) bool { // IntegrationsHaveSameTraits return if traits are the same. func IntegrationsHaveSameTraits(i1 *v1.Integration, i2 *v1.Integration) (bool, error) { - c1, err := NewUnstructuredTraitsForIntegration(i1) + c1, err := NewTraitsOptionsForIntegration(i1) if err != nil { return false, err } - c2, err := NewUnstructuredTraitsForIntegration(i2) + c2, err := NewTraitsOptionsForIntegration(i2) if err != nil { return false, err } @@ -361,11 +361,11 @@ func IntegrationsHaveSameTraits(i1 *v1.Integration, i2 *v1.Integration) (bool, e // IntegrationKitsHaveSameTraits return if traits are the same. func IntegrationKitsHaveSameTraits(i1 *v1.IntegrationKit, i2 *v1.IntegrationKit) (bool, error) { - c1, err := NewUnstructuredTraitsForIntegrationKit(i1) + c1, err := NewTraitsOptionsForIntegrationKit(i1) if err != nil { return false, err } - c2, err := NewUnstructuredTraitsForIntegrationKit(i2) + c2, err := NewTraitsOptionsForIntegrationKit(i2) if err != nil { return false, err } @@ -375,11 +375,11 @@ func IntegrationKitsHaveSameTraits(i1 *v1.IntegrationKit, i2 *v1.IntegrationKit) // KameletBindingsHaveSameTraits return if traits are the same. func KameletBindingsHaveSameTraits(i1 *v1alpha1.KameletBinding, i2 *v1alpha1.KameletBinding) (bool, error) { - c1, err := NewUnstructuredTraitsForKameletBinding(i1) + c1, err := NewTraitsOptionsForKameletBinding(i1) if err != nil { return false, err } - c2, err := NewUnstructuredTraitsForKameletBinding(i2) + c2, err := NewTraitsOptionsForKameletBinding(i2) if err != nil { return false, err } @@ -388,34 +388,43 @@ func KameletBindingsHaveSameTraits(i1 *v1alpha1.KameletBinding, i2 *v1alpha1.Kam } // IntegrationAndBindingSameTraits return if traits are the same. +// The comparison is done for the subset of traits defines on the binding as during the trait processing, +// some traits may be added to the Integration i.e. knative configuration in case of sink binding. func IntegrationAndBindingSameTraits(i1 *v1.Integration, i2 *v1alpha1.KameletBinding) (bool, error) { - c1, err := NewUnstructuredTraitsForIntegration(i1) + itOpts, err := NewTraitsOptionsForIntegration(i1) if err != nil { return false, err } - c2, err := NewUnstructuredTraitsForKameletBinding(i2) + klbOpts, err := NewTraitsOptionsForKameletBinding(i2) if err != nil { return false, err } - return Equals(c1, c2), nil + toCompare := make(Options) + for k := range klbOpts { + if v, ok := itOpts[k]; ok { + toCompare[k] = v + } + } + + return Equals(klbOpts, toCompare), nil } // IntegrationAndKitHaveSameTraits return if traits are the same. func IntegrationAndKitHaveSameTraits(i1 *v1.Integration, i2 *v1.IntegrationKit) (bool, error) { - c1, err := NewUnstructuredTraitsForIntegration(i1) + itOpts, err := NewTraitsOptionsForIntegration(i1) if err != nil { return false, err } - c2, err := NewUnstructuredTraitsForIntegrationKit(i2) + ikOpts, err := NewTraitsOptionsForIntegrationKit(i2) if err != nil { return false, err } - return Equals(c1, c2), nil + return Equals(ikOpts, itOpts), nil } -func NewUnstructuredTraitsForIntegration(i *v1.Integration) (Options, error) { +func NewTraitsOptionsForIntegration(i *v1.Integration) (Options, error) { m1, err := ToTraitMap(i.Spec.Traits) if err != nil { return nil, err @@ -433,7 +442,7 @@ func NewUnstructuredTraitsForIntegration(i *v1.Integration) (Options, error) { return m1, nil } -func NewUnstructuredTraitsForIntegrationKit(i *v1.IntegrationKit) (Options, error) { +func NewTraitsOptionsForIntegrationKit(i *v1.IntegrationKit) (Options, error) { m1, err := ToTraitMap(i.Spec.Traits) if err != nil { return nil, err @@ -451,7 +460,7 @@ func NewUnstructuredTraitsForIntegrationKit(i *v1.IntegrationKit) (Options, erro return m1, nil } -func NewUnstructuredTraitsForIntegrationPlatform(i *v1.IntegrationPlatform) (Options, error) { +func NewTraitsOptionsForIntegrationPlatform(i *v1.IntegrationPlatform) (Options, error) { m1, err := ToTraitMap(i.Spec.Traits) if err != nil { return nil, err @@ -469,7 +478,7 @@ func NewUnstructuredTraitsForIntegrationPlatform(i *v1.IntegrationPlatform) (Opt return m1, nil } -func NewUnstructuredTraitsForKameletBinding(i *v1alpha1.KameletBinding) (Options, error) { +func NewTraitsOptionsForKameletBinding(i *v1alpha1.KameletBinding) (Options, error) { if i.Spec.Integration != nil { m1, err := ToTraitMap(i.Spec.Integration.Traits) if err != nil {