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

tsato pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git

commit 1707ed18763c153aa8c1f08cdc4791672c2c5a98
Author: Tadayoshi Sato <[email protected]>
AuthorDate: Wed Jun 29 20:07:23 2022 +0900

    fix(api): fix Trait property name conflicts for generating CRDs
---
 pkg/apis/camel/v1/common_types.go  | 7 +++----
 pkg/apis/camel/v1/trait/base.go    | 3 +++
 pkg/apis/camel/v1/trait/knative.go | 2 +-
 pkg/trait/trait_configure.go       | 7 +++++++
 4 files changed, 14 insertions(+), 5 deletions(-)

diff --git a/pkg/apis/camel/v1/common_types.go 
b/pkg/apis/camel/v1/common_types.go
index f49bc83e1..a0906a52d 100644
--- a/pkg/apis/camel/v1/common_types.go
+++ b/pkg/apis/camel/v1/common_types.go
@@ -209,13 +209,12 @@ type TraitConfiguration struct {
        RawMessage `json:",inline"`
 }
 
-// +kubebuilder:validation:Type=object
-// +kubebuilder:validation:Format=""
-// +kubebuilder:pruning:PreserveUnknownFields
-
 // RawMessage is a raw encoded JSON value.
 // It implements Marshaler and Unmarshaler and can
 // be used to delay JSON decoding or precompute a JSON encoding.
+// +kubebuilder:validation:Type=object
+// +kubebuilder:validation:Format=""
+// +kubebuilder:pruning:PreserveUnknownFields
 type RawMessage []byte
 
 // +kubebuilder:object:generate=false
diff --git a/pkg/apis/camel/v1/trait/base.go b/pkg/apis/camel/v1/trait/base.go
index 5117e1ac9..8c571ba02 100644
--- a/pkg/apis/camel/v1/trait/base.go
+++ b/pkg/apis/camel/v1/trait/base.go
@@ -32,5 +32,8 @@ type Configuration struct {
        RawMessage `json:",inline"`
 }
 
+// +kubebuilder:validation:Type=object
+// +kubebuilder:validation:Format=""
+// +kubebuilder:pruning:PreserveUnknownFields
 // Deprecated: for backward compatibility.
 type RawMessage []byte
diff --git a/pkg/apis/camel/v1/trait/knative.go 
b/pkg/apis/camel/v1/trait/knative.go
index 13590557a..666953b08 100644
--- a/pkg/apis/camel/v1/trait/knative.go
+++ b/pkg/apis/camel/v1/trait/knative.go
@@ -29,7 +29,7 @@ package trait
 type KnativeTrait struct {
        Trait `property:",squash" json:",inline"`
        // Can be used to inject a Knative complete configuration in JSON 
format.
-       Configuration string `property:"configuration" 
json:"configuration,omitempty"`
+       Configuration string `property:"configuration" json:"config,omitempty"`
        // List of channels used as source of integration routes.
        // Can contain simple channel names or full Camel URIs.
        ChannelSources []string `property:"channel-sources" 
json:"channelSources,omitempty"`
diff --git a/pkg/trait/trait_configure.go b/pkg/trait/trait_configure.go
index f50fc26d2..94ae5578f 100644
--- a/pkg/trait/trait_configure.go
+++ b/pkg/trait/trait_configure.go
@@ -100,6 +100,13 @@ func decodeTrait(in map[string]interface{}, target Trait, 
root bool) error {
        // decode legacy configuration first if it exists
        if root && in["configuration"] != nil {
                if config, ok := in["configuration"].(map[string]interface{}); 
ok {
+                       // for traits that had the same property name 
"configuration",
+                       // it needs to be renamed to "config" to avoid naming 
conflicts
+                       // (e.g. Knative trait).
+                       if config["configuration"] != nil {
+                               config["config"] = config["configuration"]
+                       }
+
                        if err := decodeTrait(config, target, false); err != 
nil {
                                return err
                        }

Reply via email to