Skip to content

Commit

Permalink
fix(knative): Make knative broker name configurable
Browse files Browse the repository at this point in the history
#2864

* Add e2e knative tests
* Change the kamelet-binding-broker yaks test to use a custom broker
  name
  • Loading branch information
claudio4j authored and squakez committed Aug 25, 2022
1 parent 04c76ec commit e771b8a
Show file tree
Hide file tree
Showing 13 changed files with 79 additions and 16 deletions.
22 changes: 22 additions & 0 deletions e2e/global/knative/files/knative_broker_receiver.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

from('knative:event/hello.1?name=sample-broker')
.log('Received 1: ${body}')

from('knative:event/hello.2?name=sample-broker')
.log('Received 2: ${body}')
24 changes: 24 additions & 0 deletions e2e/global/knative/files/knative_broker_sender.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

from('timer:tick')
.setBody().constant("Hello 1 from sample-broker")
.to('knative:event/hello.1?name=sample-broker')

from('timer:tick')
.setBody().constant("Hello 2 from sample-broker")
.to('knative:event/hello.2?name=sample-broker')
16 changes: 16 additions & 0 deletions e2e/support/test_support.go
Original file line number Diff line number Diff line change
Expand Up @@ -1763,6 +1763,22 @@ func CreateKnativeChannel(ns string, name string) func() error {
}
}

func CreateKnativeBroker(ns string, name string) func() error {
return func() error {
broker := eventing.Broker{
TypeMeta: metav1.TypeMeta{
Kind: "Broker",
APIVersion: eventing.SchemeGroupVersion.String(),
},
ObjectMeta: metav1.ObjectMeta{
Namespace: ns,
Name: name,
},
}
return TestClient().Create(TestContext, &broker)
}
}

/*
Kamelets
*/
Expand Down
4 changes: 2 additions & 2 deletions e2e/yaks/common/kamelet-binding-broker/kamelet.feature
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ Feature: Camel K can bind Kamelets to the broker
| maxAttempts | 40 |
| delayBetweenAttempts | 3000 |

Scenario: Sending event to the broker with KameletBinding
Scenario: Sending event to the custom broker with KameletBinding
Given Camel K integration logger-sink-binding is running
Then Camel K integration logger-sink-binding should print message: Hello Custom Event
Then Camel K integration logger-sink-binding should print message: Hello Custom Event from sample-broker
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ spec:
ref:
kind: Broker
apiVersion: eventing.knative.dev/v1
name: default
name: sample-broker
properties:
type: custom-type
sink:
Expand Down
4 changes: 4 additions & 0 deletions e2e/yaks/common/kamelet-binding-broker/sample-broker.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
apiVersion: eventing.knative.dev/v1
kind: Broker
metadata:
name: sample-broker
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ spec:
apiVersion: camel.apache.org/v1alpha1
name: timer-source
properties:
message: Hello Custom Event
message: Hello Custom Event from sample-broker
period: 1000
sink:
ref:
kind: Broker
apiVersion: eventing.knative.dev/v1
name: default
name: sample-broker
properties:
type: custom-type
5 changes: 1 addition & 4 deletions e2e/yaks/common/kamelet-binding-broker/yaks-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,9 @@ config:
pre:
- name: installation
run: |
# One of the two labels should work
oc label namespace $YAKS_NAMESPACE eventing.knative.dev/injection=enabled
oc label namespace $YAKS_NAMESPACE knative-eventing-injection=enabled
kamel install -n $YAKS_NAMESPACE --force --operator-env-vars KAMEL_INSTALL_DEFAULT_KAMELETS=false
kubectl apply -f sample-broker.yaml -n $YAKS_NAMESPACE
kubectl apply -f timer-source.kamelet.yaml -n $YAKS_NAMESPACE
kubectl apply -f logger-sink.kamelet.yaml -n $YAKS_NAMESPACE
Expand Down
1 change: 1 addition & 0 deletions pkg/apis/camel/v1/knative/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ const (
CamelMetaKnativeKind = "knative.kind"
CamelMetaKnativeAPIVersion = "knative.apiVersion"
CamelMetaKnativeReply = "knative.reply"
CamelMetaKnativeName = "knative.name"

CamelMetaEndpointKind = "camel.endpoint.kind"

Expand Down
1 change: 1 addition & 0 deletions pkg/apis/camel/v1/knative/types_support.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ func BuildCamelServiceDefinition(name string, endpointKind CamelEndpointKind, se
CamelMetaEndpointKind: string(endpointKind),
CamelMetaKnativeAPIVersion: apiVersion,
CamelMetaKnativeKind: kind,
CamelMetaKnativeName: name,
},
}

Expand Down
1 change: 1 addition & 0 deletions pkg/trait/knative.go
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,7 @@ func (t *knativeTrait) configureEvents(e *Environment, env *knativeapi.CamelEnvi
knativeapi.CamelMetaEndpointKind: string(knativeapi.CamelEndpointKindSource),
knativeapi.CamelMetaKnativeAPIVersion: ref.APIVersion,
knativeapi.CamelMetaKnativeKind: ref.Kind,
knativeapi.CamelMetaKnativeName: ref.Name,
knativeapi.CamelMetaKnativeReply: "false",
},
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/util/bindings/bindings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func TestBindings(t *testing.T) {
"type": "myeventtype",
}),
},
uri: "knative:event/myeventtype?apiVersion=eventing.knative.dev%2Fv1&kind=Broker",
uri: "knative:event/myeventtype?apiVersion=eventing.knative.dev%2Fv1&kind=Broker&name=default",
},
{
endpointType: v1alpha1.EndpointTypeSource,
Expand Down
9 changes: 3 additions & 6 deletions pkg/util/bindings/knative_ref.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,9 @@ func (k KnativeRefBindingProvider) Translate(ctx BindingContext, endpointCtx End

var serviceURI string
if *serviceType == knativeapis.CamelServiceTypeEvent {
// TODO enable this when the runtime will support changing the broker name (https://github.com/apache/camel-k-runtime/issues/535)
/*
if props["name"] == "" {
props["name"] = e.Ref.Name
}
*/
if props["name"] == "" {
props["name"] = e.Ref.Name
}
if eventType, ok := props["type"]; ok {
// consume prop
delete(props, "type")
Expand Down

0 comments on commit e771b8a

Please sign in to comment.