diff --git a/deploy/traits.yaml b/deploy/traits.yaml index 9797ee1927..46b078583a 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 76c8fa9e41..1a0ffde1d6 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 304ed7b1ce..6660115fe3 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 32df45f04f..c3c06e8b0d 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 266402ab5e..c283343a29 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 07e9454780..79193ffe2c 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 }