You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by nf...@apache.org on 2021/03/25 14:08:17 UTC

[camel-k] 02/03: Fix #2158: Add conversion to string and regen resources

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 6b506ae548d23d40abfb341bc22feaa6b56f2680
Author: nicolaferraro <ni...@gmail.com>
AuthorDate: Wed Mar 24 17:15:49 2021 +0100

    Fix #2158: Add conversion to string and regen resources
---
 deploy/traits.yaml                                 |  7 +++---
 .../attachments/schema/integration-schema.json     | 26 +++++++++++++++-------
 .../assets/attachments/schema/kamelet-schema.json  | 26 +++++++++++++++-------
 docs/modules/traits/pages/knative.adoc             |  5 ++---
 docs/modules/traits/pages/service-binding.adoc     |  2 +-
 pkg/util/reference/reference.go                    | 18 ++++++++++++++-
 pkg/util/reference/reference_test.go               | 22 ++++++++++++++++++
 7 files changed, 81 insertions(+), 25 deletions(-)

diff --git a/deploy/traits.yaml b/deploy/traits.yaml
index 62288dc..69abaf6 100755
--- a/deploy/traits.yaml
+++ b/deploy/traits.yaml
@@ -530,9 +530,8 @@ traits:
   - name: filter-source-channels
     type: bool
     description: Enables filtering on events based on the header "ce-knativehistory".
-      Since this is an experimental headerthat can be removed in a future version
-      of Knative, filtering is enabled only when the integration islistening from
-      more than 1 channel.
+      Since this header has been removed in newer versions ofKnative, filtering is
+      disabled by default.
   - name: camel-source-compat
     type: bool
     description: Enables Knative CamelSource pre 0.15 compatibility fixes (will be
@@ -808,7 +807,7 @@ traits:
       property.
   - name: service-bindings
     type: '[]string'
-    description: List of Provisioned Services and ServiceBindings in the form KIND.VERSION.GROUP/NAME[/NAMESPACE]
+    description: List of Provisioned Services and ServiceBindings in the form [[apigroup/]version:]kind:[namespace/]name
 - name: service
   platform: false
   profiles:
diff --git a/docs/modules/ROOT/assets/attachments/schema/integration-schema.json b/docs/modules/ROOT/assets/attachments/schema/integration-schema.json
index 14b7051..6e72017 100644
--- a/docs/modules/ROOT/assets/attachments/schema/integration-schema.json
+++ b/docs/modules/ROOT/assets/attachments/schema/integration-schema.json
@@ -1257,6 +1257,9 @@
         },
         {
           "properties": {
+            "break-on-shutdown": {
+              "type": "string"
+            },
             "copy": {
               "type": "string"
             },
@@ -3129,7 +3132,7 @@
         "include": {
           "type": "string"
         },
-        "json-view": {
+        "json-view-type-name": {
           "type": "string"
         },
         "module-class-names": {
@@ -3272,7 +3275,7 @@
         "include": {
           "type": "string"
         },
-        "json-view": {
+        "json-view-type-name": {
           "type": "string"
         },
         "library": {
@@ -4500,15 +4503,22 @@
       ]
     },
     "org.apache.camel.model.loadbalancer.CustomLoadBalancerDefinition": {
-      "type": "object",
-      "properties": {
-        "id": {
+      "anyOf": [
+        {
           "type": "string"
         },
-        "ref": {
-          "type": "string"
+        {
+          "type": "object",
+          "properties": {
+            "id": {
+              "type": "string"
+            },
+            "ref": {
+              "type": "string"
+            }
+          }
         }
-      }
+      ]
     },
     "org.apache.camel.model.loadbalancer.FailoverLoadBalancerDefinition": {
       "type": "object",
diff --git a/docs/modules/ROOT/assets/attachments/schema/kamelet-schema.json b/docs/modules/ROOT/assets/attachments/schema/kamelet-schema.json
index 3b2cb45..3c5802b 100644
--- a/docs/modules/ROOT/assets/attachments/schema/kamelet-schema.json
+++ b/docs/modules/ROOT/assets/attachments/schema/kamelet-schema.json
@@ -1192,6 +1192,9 @@
         },
         {
           "properties": {
+            "break-on-shutdown": {
+              "type": "string"
+            },
             "copy": {
               "type": "string"
             },
@@ -3064,7 +3067,7 @@
         "include": {
           "type": "string"
         },
-        "json-view": {
+        "json-view-type-name": {
           "type": "string"
         },
         "module-class-names": {
@@ -3207,7 +3210,7 @@
         "include": {
           "type": "string"
         },
-        "json-view": {
+        "json-view-type-name": {
           "type": "string"
         },
         "library": {
@@ -4435,15 +4438,22 @@
       ]
     },
     "org.apache.camel.model.loadbalancer.CustomLoadBalancerDefinition": {
-      "type": "object",
-      "properties": {
-        "id": {
+      "anyOf": [
+        {
           "type": "string"
         },
-        "ref": {
-          "type": "string"
+        {
+          "type": "object",
+          "properties": {
+            "id": {
+              "type": "string"
+            },
+            "ref": {
+              "type": "string"
+            }
+          }
         }
-      }
+      ]
     },
     "org.apache.camel.model.loadbalancer.FailoverLoadBalancerDefinition": {
       "type": "object",
diff --git a/docs/modules/traits/pages/knative.adoc b/docs/modules/traits/pages/knative.adoc
index 4b23f30..5f54e1b 100755
--- a/docs/modules/traits/pages/knative.adoc
+++ b/docs/modules/traits/pages/knative.adoc
@@ -66,9 +66,8 @@ Can contain simple event types or full Camel URIs (to use a specific broker).
 
 | knative.filter-source-channels
 | bool
-| Enables filtering on events based on the header "ce-knativehistory". Since this is an experimental header
-that can be removed in a future version of Knative, filtering is enabled only when the integration is
-listening from more than 1 channel.
+| Enables filtering on events based on the header "ce-knativehistory". Since this header has been removed in newer versions of
+Knative, filtering is disabled by default.
 
 | knative.camel-source-compat
 | bool
diff --git a/docs/modules/traits/pages/service-binding.adoc b/docs/modules/traits/pages/service-binding.adoc
index eafff8f..75c755c 100755
--- a/docs/modules/traits/pages/service-binding.adoc
+++ b/docs/modules/traits/pages/service-binding.adoc
@@ -28,7 +28,7 @@ The following configuration options are available:
 
 | service-binding.service-bindings
 | []string
-| List of Provisioned Services and ServiceBindings in the form KIND.VERSION.GROUP/NAME[/NAMESPACE]
+| List of Provisioned Services and ServiceBindings in the form [[apigroup/]version:]kind:[namespace/]name
 
 |===
 
diff --git a/pkg/util/reference/reference.go b/pkg/util/reference/reference.go
index 0458a89..dc79cd5 100644
--- a/pkg/util/reference/reference.go
+++ b/pkg/util/reference/reference.go
@@ -18,6 +18,7 @@ limitations under the License.
 package reference
 
 import (
+	"errors"
 	"fmt"
 	"regexp"
 	"unicode"
@@ -124,5 +125,20 @@ func (c *Converter) simpleDecodeString(str string) (corev1.ObjectReference, erro
 }
 
 func (c *Converter) ToString(ref corev1.ObjectReference) (string, error) {
-	return "", nil
+	if ref.Kind == "" {
+		return "", errors.New(`object reference is missing the "kind" field`)
+	}
+	if ref.Name == "" {
+		return "", errors.New(`object reference is missing the "name" field`)
+	}
+	res := ""
+	if ref.APIVersion != "" {
+		res += ref.APIVersion + ":"
+	}
+	res += ref.Kind + ":"
+	if ref.Namespace != "" {
+		res += ref.Namespace + "/"
+	}
+	res += ref.Name
+	return res, nil
 }
diff --git a/pkg/util/reference/reference_test.go b/pkg/util/reference/reference_test.go
index 5539602..f13c5d8 100644
--- a/pkg/util/reference/reference_test.go
+++ b/pkg/util/reference/reference_test.go
@@ -32,6 +32,7 @@ func TestExpressions(t *testing.T) {
 		name          string
 		error         bool
 		ref           corev1.ObjectReference
+		stringRef     string
 	}{
 		{
 			name:  "lowercase:source",
@@ -53,6 +54,7 @@ func TestExpressions(t *testing.T) {
 				APIVersion: "camel.apache.org/v1alpha1",
 				Name:       "source",
 			},
+			stringRef: "camel.apache.org/v1alpha1:Kamelet:source",
 		},
 		{
 			name: "ns1/source",
@@ -62,6 +64,17 @@ func TestExpressions(t *testing.T) {
 				Namespace:  "ns1",
 				Name:       "source",
 			},
+			stringRef: "camel.apache.org/v1alpha1:Kamelet:ns1/source",
+		},
+		{
+			name: "v1:Secret:ns1/scr2",
+			ref: corev1.ObjectReference{
+				Kind:       "Secret",
+				APIVersion: "v1",
+				Namespace:  "ns1",
+				Name:       "scr2",
+			},
+			stringRef: "v1:Secret:ns1/scr2",
 		},
 		{
 			name: "ksvc:service",
@@ -70,6 +83,7 @@ func TestExpressions(t *testing.T) {
 				APIVersion: "serving.knative.dev/v1",
 				Name:       "service",
 			},
+			stringRef: "serving.knative.dev/v1:Service:service",
 		},
 		{
 			name: "channel:ns3/ch2",
@@ -79,6 +93,7 @@ func TestExpressions(t *testing.T) {
 				Namespace:  "ns3",
 				Name:       "ch2",
 			},
+			stringRef: "messaging.knative.dev/v1:Channel:ns3/ch2",
 		},
 		{
 			name: "broker:default",
@@ -87,6 +102,7 @@ func TestExpressions(t *testing.T) {
 				APIVersion: "eventing.knative.dev/v1",
 				Name:       "default",
 			},
+			stringRef: "eventing.knative.dev/v1:Broker:default",
 		},
 		{
 			name: "PostgreSQL:ns1/db",
@@ -95,6 +111,7 @@ func TestExpressions(t *testing.T) {
 				Namespace: "ns1",
 				Name:      "db",
 			},
+			stringRef: "PostgreSQL:ns1/db",
 		},
 		{
 			name: "postgres.org/v1alpha1:PostgreSQL:ns1/db",
@@ -104,6 +121,7 @@ func TestExpressions(t *testing.T) {
 				Namespace:  "ns1",
 				Name:       "db",
 			},
+			stringRef: "postgres.org/v1alpha1:PostgreSQL:ns1/db",
 		},
 	}
 
@@ -122,8 +140,12 @@ func TestExpressions(t *testing.T) {
 			if tc.error {
 				assert.Error(t, err)
 			} else {
+				asString, err2 := converter.ToString(ref)
+				assert.NoError(t, err2)
+
 				assert.NoError(t, err)
 				assert.Equal(t, tc.ref, ref)
+				assert.Equal(t, tc.stringRef, asString)
 			}
 		})
 	}