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 2020/12/04 13:52:43 UTC
[camel-k] 01/02: Fix #1654: enable sinkbinding automatically
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 787f97ef986ddb8c9af73b0650814ec029fbc3b5
Author: nicolaferraro <ni...@gmail.com>
AuthorDate: Fri Nov 27 16:01:52 2020 +0100
Fix #1654: enable sinkbinding automatically
---
deploy/traits.yaml | 2 +-
.../attachments/schema/integration-schema.json | 10 +++++++++
docs/modules/traits/pages/knative.adoc | 3 ++-
pkg/trait/knative.go | 24 +++++++++++++++++++++-
pkg/util/bindings/bindings_test.go | 9 --------
pkg/util/bindings/knative_ref.go | 24 +---------------------
6 files changed, 37 insertions(+), 35 deletions(-)
diff --git a/deploy/traits.yaml b/deploy/traits.yaml
index 9797ee1..46b0785 100755
--- a/deploy/traits.yaml
+++ b/deploy/traits.yaml
@@ -401,7 +401,7 @@ traits:
description: Enables Knative CamelSource pre 0.15 compatibility fixes (will be removed in future versions).
- name: sink-binding
type: bool
- description: Allows binding the integration to a sink via a Knative SinkBinding resource.This can be used when the integration targets a single sink.It's disabled by default.
+ description: Allows binding the integration to a sink via a Knative SinkBinding resource.This can be used when the integration targets a single sink.It's enabled by default when the integration targets a single sink(except when the integration is owned by a Knative source).
- name: auto
type: bool
description: Enable automatic discovery of all trait properties.
diff --git a/docs/modules/ROOT/assets/attachments/schema/integration-schema.json b/docs/modules/ROOT/assets/attachments/schema/integration-schema.json
index 76c8fa9..1a0ffde 100644
--- a/docs/modules/ROOT/assets/attachments/schema/integration-schema.json
+++ b/docs/modules/ROOT/assets/attachments/schema/integration-schema.json
@@ -8502,6 +8502,11 @@
"items": {
"description": "IntegrationCondition describes the state of a resource at a certain point.",
"properties": {
+ "firstTruthyTime": {
+ "description": "First time the condition status transitioned to True.",
+ "format": "date-time",
+ "type": "string"
+ },
"lastTransitionTime": {
"description": "Last time the condition transitioned from one status to another.",
"format": "date-time",
@@ -8690,6 +8695,11 @@
"kit": {
"type": "string"
},
+ "lastInitTimestamp": {
+ "description": "The timestamp representing the last time when this integration was initialized.",
+ "format": "date-time",
+ "type": "string"
+ },
"phase": {
"description": "IntegrationPhase --",
"type": "string"
diff --git a/docs/modules/traits/pages/knative.adoc b/docs/modules/traits/pages/knative.adoc
index 304ed7b..6660115 100755
--- a/docs/modules/traits/pages/knative.adoc
+++ b/docs/modules/traits/pages/knative.adoc
@@ -77,7 +77,8 @@ listening from more than 1 channel.
| bool
| Allows binding the integration to a sink via a Knative SinkBinding resource.
This can be used when the integration targets a single sink.
-It's disabled by default.
+It's enabled by default when the integration targets a single sink
+(except when the integration is owned by a Knative source).
| knative.auto
| bool
diff --git a/pkg/trait/knative.go b/pkg/trait/knative.go
index 32df45f..c3c06e8 100644
--- a/pkg/trait/knative.go
+++ b/pkg/trait/knative.go
@@ -77,7 +77,8 @@ type knativeTrait struct {
CamelSourceCompat *bool `property:"camel-source-compat" json:"camelSourceCompat,omitempty"`
// Allows binding the integration to a sink via a Knative SinkBinding resource.
// This can be used when the integration targets a single sink.
- // It's disabled by default.
+ // It's enabled by default when the integration targets a single sink
+ // (except when the integration is owned by a Knative source).
SinkBinding *bool `property:"sink-binding" json:"sinkBinding,omitempty"`
// Enable automatic discovery of all trait properties.
Auto *bool `property:"auto" json:"auto,omitempty"`
@@ -195,6 +196,10 @@ func (t *knativeTrait) Configure(e *Environment) (bool, error) {
filter := true
t.FilterSourceChannels = &filter
}
+ if t.SinkBinding == nil {
+ allowed := t.isSinkBindingAllowed(e)
+ t.SinkBinding = &allowed
+ }
}
return true, nil
@@ -454,6 +459,23 @@ func (t *knativeTrait) configureEvents(e *Environment, env *knativeapi.CamelEnvi
return nil
}
+func (t *knativeTrait) isSinkBindingAllowed(e *Environment) bool {
+ services := t.extractServices(t.ChannelSinks, knativeapi.CamelServiceTypeChannel)
+ services = append(services, t.extractServices(t.EndpointSinks, knativeapi.CamelServiceTypeEndpoint)...)
+ services = append(services, t.extractServices(t.EventSinks, knativeapi.CamelServiceTypeEvent)...)
+
+ if len(services) != 1 {
+ return false
+ }
+
+ for _, owner := range e.Integration.OwnerReferences {
+ if strings.Contains(owner.APIVersion, "sources.knative.dev") {
+ return false
+ }
+ }
+ return true
+}
+
func (t *knativeTrait) configureSinkBinding(e *Environment, env *knativeapi.CamelEnvironment) error {
if t.SinkBinding == nil || !*t.SinkBinding {
return nil
diff --git a/pkg/util/bindings/bindings_test.go b/pkg/util/bindings/bindings_test.go
index 266402a..c283343 100644
--- a/pkg/util/bindings/bindings_test.go
+++ b/pkg/util/bindings/bindings_test.go
@@ -50,9 +50,6 @@ func TestBindings(t *testing.T) {
},
},
uri: "knative:endpoint/myservice?apiVersion=serving.knative.dev%2Fv1&kind=Service",
- traits: asTraitSpec("knative", map[string]interface{}{
- "sinkBinding": true,
- }),
},
{
endpointType: v1alpha1.EndpointTypeSink,
@@ -67,9 +64,6 @@ func TestBindings(t *testing.T) {
}),
},
uri: "knative:endpoint/myservice?apiVersion=serving.knative.dev%2Fv1&ce.override.ce-type=mytype&kind=Service",
- traits: asTraitSpec("knative", map[string]interface{}{
- "sinkBinding": true,
- }),
},
{
endpointType: v1alpha1.EndpointTypeSink,
@@ -81,9 +75,6 @@ func TestBindings(t *testing.T) {
},
},
uri: "knative:channel/mychannel?apiVersion=messaging.knative.dev%2Fv1&kind=Channel",
- traits: asTraitSpec("knative", map[string]interface{}{
- "sinkBinding": true,
- }),
},
{
endpointType: v1alpha1.EndpointTypeSource,
diff --git a/pkg/util/bindings/knative_ref.go b/pkg/util/bindings/knative_ref.go
index 07e9454..79193ff 100644
--- a/pkg/util/bindings/knative_ref.go
+++ b/pkg/util/bindings/knative_ref.go
@@ -18,12 +18,10 @@ limitations under the License.
package bindings
import (
- "encoding/json"
"errors"
"fmt"
"net/url"
- v1 "github.com/apache/camel-k/pkg/apis/camel/v1"
knativeapis "github.com/apache/camel-k/pkg/apis/camel/v1/knative"
"github.com/apache/camel-k/pkg/apis/camel/v1alpha1"
"github.com/apache/camel-k/pkg/util/knative"
@@ -91,28 +89,8 @@ func (k KnativeRefBindingProvider) Translate(ctx BindingContext, endpointType v1
}
serviceURI = uri.AppendParameters(serviceURI, props)
-
- var traits map[string]v1.TraitSpec
- if endpointType == v1alpha1.EndpointTypeSink {
- knativeConfig := make(map[string]interface{})
- // TODO remove this after making sinkbinding the default (https://github.com/apache/camel-k/issues/1654)
- knativeConfig["sinkBinding"] = true
- knativeConfigJSON, err := json.Marshal(knativeConfig)
- if err != nil {
- return nil, err
- }
- traits = map[string]v1.TraitSpec{
- "knative": {
- Configuration: v1.TraitConfiguration{
- RawMessage: knativeConfigJSON,
- },
- },
- }
- }
-
return &Binding{
- URI: serviceURI,
- Traits: traits,
+ URI: serviceURI,
}, nil
}