This is an automated email from the ASF dual-hosted git repository. orpiske pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/camel-k.git
commit 4c78889877ea1d6c1ae5ffb7d53cea970d5ecae4 Author: Luca Burgazzoli <[email protected]> AuthorDate: Tue Jun 8 17:07:01 2021 +0200 kameletbinding: remove the need of allocation some intermediate slices --- pkg/controller/kameletbinding/common.go | 63 ++++++++++++++++++--------------- 1 file changed, 34 insertions(+), 29 deletions(-) diff --git a/pkg/controller/kameletbinding/common.go b/pkg/controller/kameletbinding/common.go index 18725fe..7c9fde7 100644 --- a/pkg/controller/kameletbinding/common.go +++ b/pkg/controller/kameletbinding/common.go @@ -125,36 +125,20 @@ func createIntegrationFor(ctx context.Context, c client.Client, kameletbinding * } } - allBindings := make([]*bindings.Binding, 0, len(steps)+3) - allBindings = append(allBindings, from) - allBindings = append(allBindings, steps...) - allBindings = append(allBindings, to) - if errorHandler != nil { - allBindings = append(allBindings, errorHandler) - } - - propList := make([]string, 0) - for _, b := range allBindings { - if it.Spec.Traits == nil { - it.Spec.Traits = make(map[string]v1.TraitSpec) - } - for k, v := range b.Traits { - it.Spec.Traits[k] = v - } - for k, v := range b.ApplicationProperties { - entry, err := property.EncodePropertyFileEntry(k, v) - if err != nil { - return nil, err + configureBinding(&it, from) + configureBinding(&it, steps...) + configureBinding(&it, to) + configureBinding(&it, errorHandler) + + if it.Spec.Configuration != nil { + sort.SliceStable(it.Spec.Configuration, func(i, j int) bool { + mi, mj := it.Spec.Configuration[i], it.Spec.Configuration[j] + switch { + case mi.Type != mj.Type: + return mi.Type < mj.Type + default: + return mi.Value < mj.Value } - propList = append(propList, entry) - } - } - - sort.Strings(propList) - for _, p := range propList { - it.Spec.Configuration = append(it.Spec.Configuration, v1.ConfigurationSpec{ - Type: "property", - Value: p, }) } @@ -194,6 +178,27 @@ func createIntegrationFor(ctx context.Context, c client.Client, kameletbinding * return &it, nil } +func configureBinding(integration *v1.Integration, bindings ...*bindings.Binding) { + for _, b := range bindings { + if b == nil { + continue + } + if integration.Spec.Traits == nil { + integration.Spec.Traits = make(map[string]v1.TraitSpec) + } + for k, v := range b.Traits { + integration.Spec.Traits[k] = v + } + for k, v := range b.ApplicationProperties { + integration.Spec.Configuration = append(integration.Spec.Configuration, v1.ConfigurationSpec{ + Type: "property", + Value: property.EncodePropertyFileEntry(k, v), + }) + } + + } +} + func determineProfile(ctx context.Context, c client.Client, binding *v1alpha1.KameletBinding) (v1.TraitProfile, error) { if binding.Spec.Integration != nil && binding.Spec.Integration.Profile != "" { return binding.Spec.Integration.Profile, nil
