Skip to content

Commit

Permalink
Fix #2158: Add conversion to string and regen resources
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolaferraro committed Mar 25, 2021
1 parent a134e48 commit 6b506ae
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 25 deletions.
7 changes: 3 additions & 4 deletions deploy/traits.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1257,6 +1257,9 @@
},
{
"properties": {
"break-on-shutdown": {
"type": "string"
},
"copy": {
"type": "string"
},
Expand Down Expand Up @@ -3129,7 +3132,7 @@
"include": {
"type": "string"
},
"json-view": {
"json-view-type-name": {
"type": "string"
},
"module-class-names": {
Expand Down Expand Up @@ -3272,7 +3275,7 @@
"include": {
"type": "string"
},
"json-view": {
"json-view-type-name": {
"type": "string"
},
"library": {
Expand Down Expand Up @@ -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",
Expand Down
26 changes: 18 additions & 8 deletions docs/modules/ROOT/assets/attachments/schema/kamelet-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -1192,6 +1192,9 @@
},
{
"properties": {
"break-on-shutdown": {
"type": "string"
},
"copy": {
"type": "string"
},
Expand Down Expand Up @@ -3064,7 +3067,7 @@
"include": {
"type": "string"
},
"json-view": {
"json-view-type-name": {
"type": "string"
},
"module-class-names": {
Expand Down Expand Up @@ -3207,7 +3210,7 @@
"include": {
"type": "string"
},
"json-view": {
"json-view-type-name": {
"type": "string"
},
"library": {
Expand Down Expand Up @@ -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",
Expand Down
5 changes: 2 additions & 3 deletions docs/modules/traits/pages/knative.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion docs/modules/traits/pages/service-binding.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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

|===

Expand Down
18 changes: 17 additions & 1 deletion pkg/util/reference/reference.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ limitations under the License.
package reference

import (
"errors"
"fmt"
"regexp"
"unicode"
Expand Down Expand Up @@ -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
}
22 changes: 22 additions & 0 deletions pkg/util/reference/reference_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ func TestExpressions(t *testing.T) {
name string
error bool
ref corev1.ObjectReference
stringRef string
}{
{
name: "lowercase:source",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -79,6 +93,7 @@ func TestExpressions(t *testing.T) {
Namespace: "ns3",
Name: "ch2",
},
stringRef: "messaging.knative.dev/v1:Channel:ns3/ch2",
},
{
name: "broker:default",
Expand All @@ -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",
Expand All @@ -95,6 +111,7 @@ func TestExpressions(t *testing.T) {
Namespace: "ns1",
Name: "db",
},
stringRef: "PostgreSQL:ns1/db",
},
{
name: "postgres.org/v1alpha1:PostgreSQL:ns1/db",
Expand All @@ -104,6 +121,7 @@ func TestExpressions(t *testing.T) {
Namespace: "ns1",
Name: "db",
},
stringRef: "postgres.org/v1alpha1:PostgreSQL:ns1/db",
},
}

Expand All @@ -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)
}
})
}
Expand Down

0 comments on commit 6b506ae

Please sign in to comment.