This is an automated email from the ASF dual-hosted git repository.

nferraro pushed a commit to branch release-1.3.x
in repository https://gitbox.apache.org/repos/asf/camel-k.git

commit 06fd19f3e5309cd64e60eb233a71d9e0aa7ae70a
Author: nicolaferraro <ni.ferr...@gmail.com>
AuthorDate: Tue Feb 2 13:30:35 2021 +0100

    Fix #1986: use properties instead of URL encoding for Kamelets in bindings
---
 pkg/controller/kameletbinding/common.go | 19 +++++++++++++++++++
 pkg/util/bindings/api.go                |  2 ++
 pkg/util/bindings/bindings_test.go      | 29 +++++++++++++++++++++++++++--
 pkg/util/bindings/kamelet.go            | 24 ++++++++++++++++++------
 script/gen_release_notes.sh             |  4 ++--
 5 files changed, 68 insertions(+), 10 deletions(-)

diff --git a/pkg/controller/kameletbinding/common.go 
b/pkg/controller/kameletbinding/common.go
index a50b202..1fc8dc6 100644
--- a/pkg/controller/kameletbinding/common.go
+++ b/pkg/controller/kameletbinding/common.go
@@ -20,6 +20,8 @@ package kameletbinding
 import (
        "context"
        "encoding/json"
+       "fmt"
+       "sort"
 
        v1 "github.com/apache/camel-k/pkg/apis/camel/v1"
        "github.com/apache/camel-k/pkg/apis/camel/v1alpha1"
@@ -90,6 +92,23 @@ func createIntegrationFor(ctx context.Context, c 
client.Client, kameletbinding *
                }
        }
 
+       if len(from.ApplicationProperties) > 0 || len(to.ApplicationProperties) 
> 0 {
+               propList := make([]string, 0, 
len(from.ApplicationProperties)+len(to.ApplicationProperties))
+               for k, v := range from.ApplicationProperties {
+                       propList = append(propList, fmt.Sprintf("%s=%s", k, v))
+               }
+               for k, v := range to.ApplicationProperties {
+                       propList = append(propList, fmt.Sprintf("%s=%s", k, v))
+               }
+               sort.Strings(propList)
+               for _, p := range propList {
+                       it.Spec.Configuration = append(it.Spec.Configuration, 
v1.ConfigurationSpec{
+                               Type:  "property",
+                               Value: p,
+                       })
+               }
+       }
+
        flow := map[string]interface{}{
                "from": map[string]interface{}{
                        "uri": from.URI,
diff --git a/pkg/util/bindings/api.go b/pkg/util/bindings/api.go
index 05ea123..f5debd3 100644
--- a/pkg/util/bindings/api.go
+++ b/pkg/util/bindings/api.go
@@ -38,6 +38,8 @@ type Binding struct {
        URI string
        // Traits is a partial trait specification that should be merged into 
the integration
        Traits map[string]v1.TraitSpec
+       // ApplicationProperties contain properties that should be set on the 
integration for the binding to work
+       ApplicationProperties map[string]string
 }
 
 // BindingProvider maps a KameletBinding endpoint into Camel K resources
diff --git a/pkg/util/bindings/bindings_test.go 
b/pkg/util/bindings/bindings_test.go
index 55d005f..6108af1 100644
--- a/pkg/util/bindings/bindings_test.go
+++ b/pkg/util/bindings/bindings_test.go
@@ -39,6 +39,7 @@ func TestBindings(t *testing.T) {
                profile      camelv1.TraitProfile
                uri          string
                traits       map[string]camelv1.TraitSpec
+               props        map[string]string
        }{
                {
                        endpointType: v1alpha1.EndpointTypeSink,
@@ -113,6 +114,7 @@ func TestBindings(t *testing.T) {
                        uri: 
"knative:event/myeventtype?apiVersion=eventing.knative.dev%2Fv1beta1&kind=Broker",
                },
                {
+                       endpointType: v1alpha1.EndpointTypeSource,
                        endpoint: v1alpha1.Endpoint{
                                Ref: &corev1.ObjectReference{
                                        Kind:       "Kamelet",
@@ -120,9 +122,10 @@ func TestBindings(t *testing.T) {
                                        Name:       "mykamelet",
                                },
                        },
-                       uri: "kamelet:mykamelet",
+                       uri: "kamelet:mykamelet/source",
                },
                {
+                       endpointType: v1alpha1.EndpointTypeSink,
                        endpoint: v1alpha1.Endpoint{
                                Ref: &corev1.ObjectReference{
                                        Kind:       "Kamelet",
@@ -134,7 +137,28 @@ func TestBindings(t *testing.T) {
                                        "encodedkey?": "encoded=val",
                                }),
                        },
-                       uri: 
"kamelet:mykamelet?encodedkey%3F=encoded%3Dval&mymessage=myval",
+                       uri: "kamelet:mykamelet/sink",
+                       props: map[string]string{
+                               "camel.kamelet.mykamelet.sink.encodedkey?": 
"encoded=val",
+                               "camel.kamelet.mykamelet.sink.mymessage":   
"myval",
+                       },
+               },
+               {
+                       endpoint: v1alpha1.Endpoint{
+                               Ref: &corev1.ObjectReference{
+                                       Kind:       "Kamelet",
+                                       APIVersion: "camel.apache.org/v1any1",
+                                       Name:       "mykamelet",
+                               },
+                               Properties: 
asEndpointProperties(map[string]string{
+                                       "id":        "myid?",
+                                       "mymessage": "myval",
+                               }),
+                       },
+                       uri: "kamelet:mykamelet/myid%3F",
+                       props: map[string]string{
+                               "camel.kamelet.mykamelet.myid?.mymessage": 
"myval",
+                       },
                },
                {
                        endpoint: v1alpha1.Endpoint{
@@ -206,6 +230,7 @@ func TestBindings(t *testing.T) {
                        assert.NotNil(t, binding)
                        assert.Equal(t, tc.uri, binding.URI)
                        assert.Equal(t, tc.traits, binding.Traits)
+                       assert.Equal(t, tc.props, binding.ApplicationProperties)
                })
        }
 }
diff --git a/pkg/util/bindings/kamelet.go b/pkg/util/bindings/kamelet.go
index 089a7d4..ca83252 100644
--- a/pkg/util/bindings/kamelet.go
+++ b/pkg/util/bindings/kamelet.go
@@ -22,7 +22,6 @@ import (
        "net/url"
 
        "github.com/apache/camel-k/pkg/apis/camel/v1alpha1"
-       "github.com/apache/camel-k/pkg/util/uri"
        "k8s.io/apimachinery/pkg/runtime/schema"
 )
 
@@ -44,22 +43,35 @@ func (k KameletBindingProvider) Translate(ctx 
BindingContext, endpointType v1alp
        }
        // it translates only Kamelet refs
        if e.Ref.Kind == v1alpha1.KameletKind && gv.Group == 
v1alpha1.SchemeGroupVersion.Group {
-               kameletURI := fmt.Sprintf("kamelet:%s", 
url.PathEscape(e.Ref.Name))
+               kameletName := url.PathEscape(e.Ref.Name)
+               kameletURI := fmt.Sprintf("kamelet:%s", kameletName)
 
                props, err := e.Properties.GetPropertyMap()
                if err != nil {
                        return nil, err
                }
 
-               if id, ok := props[v1alpha1.KameletIDProperty]; ok && id != "" {
+               id, idPresent := props[v1alpha1.KameletIDProperty]
+               if idPresent {
                        delete(props, v1alpha1.KameletIDProperty)
-                       kameletURI = fmt.Sprintf("%s/%s", kameletURI, 
url.PathEscape(id))
+               } else {
+                       // Let's use literal "source" or "sink" as ID for the 
Kamelet
+                       id = string(endpointType)
                }
+               kameletURI = fmt.Sprintf("%s/%s", kameletURI, 
url.PathEscape(id))
 
-               kameletURI = uri.AppendParameters(kameletURI, props)
+               var applicationProperties map[string]string
+               if len(props) > 0 {
+                       applicationProperties = make(map[string]string, 
len(props))
+                       for k, v := range props {
+                               propKey := 
fmt.Sprintf("camel.kamelet.%s.%s.%s", kameletName, id, k)
+                               applicationProperties[propKey] = v
+                       }
+               }
 
                return &Binding{
-                       URI: kameletURI,
+                       URI:                   kameletURI,
+                       ApplicationProperties: applicationProperties,
                }, nil
        }
        return nil, nil
diff --git a/script/gen_release_notes.sh b/script/gen_release_notes.sh
index 4caea9f..070e08d 100755
--- a/script/gen_release_notes.sh
+++ b/script/gen_release_notes.sh
@@ -23,8 +23,8 @@ if [ "$#" -ne 2 ]; then
 fi
 
 location=$(dirname $0)
-last_tag=$1
-new_tag=$2
+last_tag=v$1
+new_tag=v$2
 
 echo "Generating release notes for version $new_tag starting from tag 
$last_tag"
 

Reply via email to