Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Normalize names #2169

Merged
merged 3 commits into from Mar 25, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 3 additions & 4 deletions deploy/traits.yaml
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
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
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
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
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
2 changes: 1 addition & 1 deletion pkg/cmd/run.go
Expand Up @@ -73,7 +73,7 @@ func newCmdRun(rootCmdOptions *RootCmdOptions) (*cobra.Command, *runCmdOptions)
}

cmd.Flags().String("name", "", "The integration name")
cmd.Flags().StringArrayP("connect", "c", nil, "A ServiceBinding or Provisioned Service that the integration should bind to specified as KIND.VERSION.GROUP/NAME[/NAMESPACE]")
cmd.Flags().StringArrayP("connect", "c", nil, "A ServiceBinding or Provisioned Service that the integration should bind to, specified as [[apigroup/]version:]kind:[namespace/]name")
cmd.Flags().StringArrayP("dependency", "d", nil, "An external library that should be included. E.g. for Maven dependencies \"mvn:org.my/app:1.0\"")
cmd.Flags().BoolP("wait", "w", false, "Wait for the integration to be running")
cmd.Flags().StringP("kit", "k", "", "The kit used to run the integration")
Expand Down
55 changes: 21 additions & 34 deletions pkg/trait/service_binding.go
Expand Up @@ -19,8 +19,8 @@ package trait

import (
"fmt"
"strings"

"github.com/apache/camel-k/pkg/util/reference"
corev1 "k8s.io/api/core/v1"
k8serrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand All @@ -38,7 +38,7 @@ import (
// +camel-k:trait=service-binding
type serviceBindingTrait struct {
BaseTrait `property:",squash"`
// 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
ServiceBindings []string `property:"service-bindings" json:"serviceBindings,omitempty"`
}

Expand Down Expand Up @@ -173,33 +173,23 @@ func (t *serviceBindingTrait) getServiceBinding(e *Environment, name string) (sb

func (t *serviceBindingTrait) parseProvisionedServices(e *Environment) ([]sb.Service, error) {
services := make([]sb.Service, 0)
converter := reference.NewConverter("")
for _, s := range t.ServiceBindings {
seg := strings.Split(s, "/")
if !(len(seg) == 3 || len(seg) == 2) {
return nil, fmt.Errorf("ServiceBinding: %s should be specified in the form KIND.VERSION.GROUP/NAME[/NAMESPACE]", s)
ref, err := converter.FromString(s)
if err != nil {
return services, err
}
gvk := seg[0]
index := strings.Index(gvk, ".")
kind := seg[0][0:index]
if kind == "ServiceBinding" {
continue
}
vg := seg[0][index+1 : len(gvk)]
index = strings.Index(vg, ".")
version := vg[0:index]
group := vg[index+1 : len(vg)]
name := seg[1]
namespace := e.Integration.Namespace
if len(seg) == 3 {
namespace = seg[2]
if ref.Namespace != "" {
namespace = ref.Namespace
}
service := sb.Service{
NamespacedRef: sb.NamespacedRef{
Ref: sb.Ref{
Group: group,
Version: version,
Kind: kind,
Name: name,
Group: ref.GroupVersionKind().Group,
Version: ref.GroupVersionKind().Version,
Kind: ref.Kind,
Name: ref.Name,
},
Namespace: &namespace,
},
Expand All @@ -211,23 +201,20 @@ func (t *serviceBindingTrait) parseProvisionedServices(e *Environment) ([]sb.Ser

func (t *serviceBindingTrait) parseServiceBindings(e *Environment) ([]string, error) {
serviceBindings := make([]string, 0)
converter := reference.NewConverter("")
for _, s := range t.ServiceBindings {
seg := strings.Split(s, "/")
if !(len(seg) == 3 || len(seg) == 2) {
return nil, fmt.Errorf("ServiceBinding: %s should be specified in the form KIND.VERSION.GROUP/NAME[/NAMESPACE]", s)
ref, err := converter.FromString(s)
if err != nil {
return serviceBindings, err
}
gvk := seg[0]
index := strings.Index(gvk, ".")
kind := seg[0][0:index]
if kind == "ServiceBinding" {
vg := seg[0][index+1 : len(gvk)]
if vg != "v1alpha1.binding.operators.coreos.com" {
return nil, fmt.Errorf("ServiceBinding: %s VERSION.GROUP should be v1alpha1.binding.operators.coreos.com", s)
if ref.Kind == "ServiceBinding" {
if ref.GroupVersionKind().String() != sb.GroupVersion.String() {
return nil, fmt.Errorf("ServiceBinding: %q api version should be %q", s, sb.GroupVersion.String())
}
if len(seg) == 3 && seg[2] != e.Integration.Namespace {
if ref.Namespace != e.Integration.Namespace {
return nil, fmt.Errorf("ServiceBinding: %s should be in the same namespace %s as the integration", s, e.Integration.Namespace)
}
serviceBindings = append(serviceBindings, seg[1])
serviceBindings = append(serviceBindings, ref.Name)
}
}
return serviceBindings, nil
Expand Down