You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by or...@apache.org on 2021/06/23 07:48:42 UTC

[camel-k] 11/15: Fix #2361: refactor code

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 f507e8ac31c552947aa2b4c3dc2e6c41ebf4ced0
Author: nicolaferraro <ni...@gmail.com>
AuthorDate: Tue Jun 8 00:16:07 2021 +0200

    Fix #2361: refactor code
---
 pkg/cmd/run.go                          |  2 +-
 pkg/controller/kameletbinding/common.go | 31 +++++++++++++++++++++++++------
 2 files changed, 26 insertions(+), 7 deletions(-)

diff --git a/pkg/cmd/run.go b/pkg/cmd/run.go
index 585f991..4fe1d1a 100644
--- a/pkg/cmd/run.go
+++ b/pkg/cmd/run.go
@@ -18,7 +18,6 @@ limitations under the License.
 package cmd
 
 import (
-	"bytes"
 	"context"
 	"encoding/json"
 	"fmt"
@@ -31,6 +30,7 @@ import (
 	"strings"
 	"syscall"
 
+	"github.com/apache/camel-k/pkg/util/property"
 	"github.com/magiconair/properties"
 	"github.com/mitchellh/mapstructure"
 	"github.com/pkg/errors"
diff --git a/pkg/controller/kameletbinding/common.go b/pkg/controller/kameletbinding/common.go
index 7c9fde7..9a381a3 100644
--- a/pkg/controller/kameletbinding/common.go
+++ b/pkg/controller/kameletbinding/common.go
@@ -125,10 +125,21 @@ func createIntegrationFor(ctx context.Context, c client.Client, kameletbinding *
 		}
 	}
 
-	configureBinding(&it, from)
-	configureBinding(&it, steps...)
-	configureBinding(&it, to)
-	configureBinding(&it, errorHandler)
+	if err := configureBinding(&it, from); err != nil {
+		return nil, err
+	}
+
+	if err := configureBinding(&it, steps...); err != nil {
+		return nil, err
+	}
+
+	if err := configureBinding(&it, to); err != nil {
+		return nil, err
+	}
+
+	if err := configureBinding(&it, errorHandler); err != nil {
+		return nil, err
+	}
 
 	if it.Spec.Configuration != nil {
 		sort.SliceStable(it.Spec.Configuration, func(i, j int) bool {
@@ -178,7 +189,7 @@ func createIntegrationFor(ctx context.Context, c client.Client, kameletbinding *
 	return &it, nil
 }
 
-func configureBinding(integration *v1.Integration, bindings ...*bindings.Binding) {
+func configureBinding(integration *v1.Integration, bindings ...*bindings.Binding) error {
 	for _, b := range bindings {
 		if b == nil {
 			continue
@@ -190,13 +201,21 @@ func configureBinding(integration *v1.Integration, bindings ...*bindings.Binding
 			integration.Spec.Traits[k] = v
 		}
 		for k, v := range b.ApplicationProperties {
+			entry, err := property.EncodePropertyFileEntry(k, v)
+
+			if err != nil {
+				return err
+			}
+
 			integration.Spec.Configuration = append(integration.Spec.Configuration, v1.ConfigurationSpec{
 				Type:  "property",
-				Value: property.EncodePropertyFileEntry(k, v),
+				Value: entry,
 			})
 		}
 
 	}
+
+	return nil
 }
 
 func determineProfile(ctx context.Context, c client.Client, binding *v1alpha1.KameletBinding) (v1.TraitProfile, error) {