Skip to content

Commit

Permalink
fix #1676: allow using non-string values in properties
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolaferraro committed Sep 17, 2020
1 parent 713d260 commit 86ce1cd
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 13 deletions.
14 changes: 11 additions & 3 deletions deploy/resources.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion e2e/yaks/kamelets/timer-source.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ spec:
name: timer
properties:
message: Hello Kamelets
period: "1000"
period: 1000
sink:
ref:
kind: InMemoryChannel
Expand Down
10 changes: 9 additions & 1 deletion pkg/apis/camel/v1alpha1/kamelet_binding_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 --
Expand Down
29 changes: 22 additions & 7 deletions pkg/apis/camel/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 15 additions & 1 deletion pkg/controller/kameletbinding/initialize.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 86ce1cd

Please sign in to comment.