This is an automated email from the ASF dual-hosted git repository. nferraro pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/camel-k.git
commit 86ce1cdf897f7b654891cc8c12b390a9e2c58ccb Author: nicolaferraro <[email protected]> AuthorDate: Tue Sep 1 17:27:38 2020 +0200 fix #1676: allow using non-string values in properties --- deploy/resources.go | 14 +++++++++--- e2e/yaks/kamelets/timer-source.yaml | 2 +- pkg/apis/camel/v1alpha1/kamelet_binding_types.go | 10 +++++++- pkg/apis/camel/v1alpha1/zz_generated.deepcopy.go | 29 ++++++++++++++++++------ pkg/controller/kameletbinding/initialize.go | 16 ++++++++++++- 5 files changed, 58 insertions(+), 13 deletions(-) diff --git a/deploy/resources.go b/deploy/resources.go index a07493e..2950584 100644 --- a/deploy/resources.go +++ b/deploy/resources.go @@ -144,8 +144,15 @@ var assets = func() http.FileSystem { compressedContent: []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xec\x3a\x4f\x8f\xe2\x38\xf6\xf7\x7c\x8a\xa7\xe2\xd0\x33\x52\x01\xbf\x9e\xb9\xfc\xc4\x9e\x58\xba\x4b\xcb\x76\x37\x55\x02\x7a\x46\x73\x34\xce\x23\x78\xcb\xb1\xb3\xb6\x03\x5d\xbb\xda\xef\xbe\x7a\x76\x12\x92\x90\x50\x14\xd5\xad\x95\x46\x95\x1b\xf1\xfb\xff\xdf\x2f\x0c\x60\xf8\xfd\x9e\x68\x00\x9f\x05\x47\x65\x31\x06\xa7\xc1\xed\x10\xa6\x19\xe3\x3b\x84\x95\xde\xba\x03\x33\x08\x77\x3a\x57\x31\x73\x42\x2b\xf8\x69\xba\xba\xfb\x [...] }, - "/kamelets.camel.apache.org.crd.yaml": &vfsgen۰CompressedFileInfo{ - name: "kamelets.camel.apache.org.crd.yaml", + "/crd-kamelet-binding.yaml": &vfsgen۰CompressedFileInfo{ + name: "crd-kamelet-binding.yaml", + modTime: time.Time{}, + uncompressedSize: 1541, + + compressedContent: []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xac\x54\xcd\x6e\xe3\x36\x10\xbe\xeb\x29\x3e\x58\x97\x5d\x20\x96\x9b\x9e\x0a\xf5\xe4\xf5\x26\xa8\x9b\x40\x0e\x22\x6f\x17\x7b\x1c\x4b\x63\x69\x60\x8a\x64\x49\xca\x8e\x51\xf4\xdd\x0b\x4a\x72\xe2\x74\xf7\xb8\xba\x89\xf3\xf7\xfd\x0c\x99\x62\xfe\xf3\xbe\x24\xc5\xa3\x54\xac\x3d\xd7\x08\x06\xa1\x65\x2c\x2d\x55\x2d\xa3\x34\xfb\x70\x22\xc7\xb8\x37\xbd\xae\x29\x88\xd1\xf8\xb0\x2c\xef\x3f\xa2\xd7\x35\x3b\x18\xcd\x30\x0e\x9d\x71\x [...] + }, + "/crd-kamelet.yaml": &vfsgen۰CompressedFileInfo{ + name: "crd-kamelet.yaml", modTime: time.Time{}, uncompressedSize: 1498, @@ -387,7 +394,8 @@ var assets = func() http.FileSystem { fs["/crd-integration-kit.yaml"].(os.FileInfo), fs["/crd-integration-platform.yaml"].(os.FileInfo), fs["/crd-integration.yaml"].(os.FileInfo), - fs["/kamelets.camel.apache.org.crd.yaml"].(os.FileInfo), + fs["/crd-kamelet-binding.yaml"].(os.FileInfo), + fs["/crd-kamelet.yaml"].(os.FileInfo), fs["/operator-deployment.yaml"].(os.FileInfo), fs["/operator-role-binding-events.yaml"].(os.FileInfo), fs["/operator-role-binding-knative.yaml"].(os.FileInfo), diff --git a/e2e/yaks/kamelets/timer-source.yaml b/e2e/yaks/kamelets/timer-source.yaml index 35bfe52..0b48886 100644 --- a/e2e/yaks/kamelets/timer-source.yaml +++ b/e2e/yaks/kamelets/timer-source.yaml @@ -10,7 +10,7 @@ spec: name: timer properties: message: Hello Kamelets - period: "1000" + period: 1000 sink: ref: kind: InMemoryChannel diff --git a/pkg/apis/camel/v1alpha1/kamelet_binding_types.go b/pkg/apis/camel/v1alpha1/kamelet_binding_types.go index 844f5f0..64702c2 100644 --- a/pkg/apis/camel/v1alpha1/kamelet_binding_types.go +++ b/pkg/apis/camel/v1alpha1/kamelet_binding_types.go @@ -18,6 +18,8 @@ limitations under the License. package v1alpha1 import ( + "encoding/json" + v1 "github.com/apache/camel-k/pkg/apis/camel/v1" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -40,7 +42,13 @@ type Endpoint struct { // URI can alternatively be used to specify the (Camel) endpoint explicitly URI *string `json:"uri,omitempty"` // Properties are a key value representation of endpoint properties - Properties map[string]string `json:"properties,omitempty"` + Properties EndpointProperties `json:"properties,omitempty"` +} + +// EndpointProperties is a key/value struct represented as JSON raw to allow numeric/boolean values +// +kubebuilder:validation:Type=object +type EndpointProperties struct { + json.RawMessage `json:",inline"` } // KameletBindingStatus -- diff --git a/pkg/apis/camel/v1alpha1/zz_generated.deepcopy.go b/pkg/apis/camel/v1alpha1/zz_generated.deepcopy.go index 32596ba..fe54781 100644 --- a/pkg/apis/camel/v1alpha1/zz_generated.deepcopy.go +++ b/pkg/apis/camel/v1alpha1/zz_generated.deepcopy.go @@ -41,13 +41,7 @@ func (in *Endpoint) DeepCopyInto(out *Endpoint) { *out = new(string) **out = **in } - if in.Properties != nil { - in, out := &in.Properties, &out.Properties - *out = make(map[string]string, len(*in)) - for key, val := range *in { - (*out)[key] = val - } - } + in.Properties.DeepCopyInto(&out.Properties) return } @@ -62,6 +56,27 @@ func (in *Endpoint) DeepCopy() *Endpoint { } // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *EndpointProperties) DeepCopyInto(out *EndpointProperties) { + *out = *in + if in.RawMessage != nil { + in, out := &in.RawMessage, &out.RawMessage + *out = make(json.RawMessage, len(*in)) + copy(*out, *in) + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new EndpointProperties. +func (in *EndpointProperties) DeepCopy() *EndpointProperties { + if in == nil { + return nil + } + out := new(EndpointProperties) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *EventTypeSpec) DeepCopyInto(out *EventTypeSpec) { *out = *in if in.Schema != nil { diff --git a/pkg/controller/kameletbinding/initialize.go b/pkg/controller/kameletbinding/initialize.go index dd43839..d047ae6 100644 --- a/pkg/controller/kameletbinding/initialize.go +++ b/pkg/controller/kameletbinding/initialize.go @@ -119,7 +119,21 @@ func getEndpointURI(e v1alpha1.Endpoint) (string, error) { if err != nil { return baseURI, err } - return uri.AppendParameters(baseURI, e.Properties), nil + + // Convert json properties to string before using them in URI + if len(e.Properties.RawMessage) > 0 { + var props map[string]interface{} + if err := json.Unmarshal(e.Properties.RawMessage, &props); err != nil { + return "", err + } + stringProps := make(map[string]string, len(props)) + for k, v := range props { + stringProps[k] = fmt.Sprintf("%v", v) + } + return uri.AppendParameters(baseURI, stringProps), nil + } + + return baseURI, nil } func getEndpointBaseURI(e v1alpha1.Endpoint) (string, error) {
