Yassir S
Yassir S

Reputation: 1042

Knative Service can't be triggered by Knative Broker & Trigger

I am testing Knative in GKE and Here is what I would like to do:

enter image description here

However, I got the following error in logs of "default-broker-filter" :

caller: "http/transport.go:508"   
error: "Post http://helloworld-python.knative-samples.svc.cluster.local: dial tcp: lookup helloworld-python.knative-samples.svc.cluster.local on 10.0.0.10:53: no such host"   
level: "warn"   
logger: "fallback"   
msg: "got an error from receiver fn" 

I use this official tutorial to install Knative with the following command:

kubectl apply --selector knative.dev/crd-install=true \
--filename https://github.com/knative/serving/releases/download/v0.12.0/serving.yaml \
--filename https://github.com/knative/eventing/releases/download/v0.12.0/eventing.yaml \
--filename https://github.com/knative/serving/releases/download/v0.12.0/monitoring.yaml

kubectl apply --filename https://github.com/knative/serving/releases/download/v0.12.0/serving.yaml \
--filename https://github.com/knative/eventing/releases/download/v0.12.0/eventing.yaml \
--filename https://github.com/knative/serving/releases/download/v0.12.0/monitoring.yaml

Here is my yaml template I used to install my trigger and my service hello world in python:

# Namespace for sample application with eventing enabled
apiVersion: v1
kind: Namespace
metadata:
  name: knative-samples
  labels:
    knative-eventing-injection: enabled
---
apiVersion: serving.knative.dev/v1
kind: Service
metadata:
  name: helloworld-python
  namespace: knative-samples
spec:
  template:
    spec:
      containers:
        - image: gcr.io/knative-samples/helloworld-python
          env:
            - name: TARGET
              value: "Python Sample v1"

---
# Knative Eventing Trigger to trigger the helloworld-go service
apiVersion: eventing.knative.dev/v1alpha1
kind: Trigger
metadata:
  name: my-service-trigger
  namespace: knative-samples
spec:
  broker: default
  filter:
    attributes:
      type: dev.knative.samples.helloworld
  subscriber:
    ref:
      apiVersion: serving.knative.dev/v1
      kind: Service
      name: helloworld-python

Then I create a pod to execute my curl command:

kubectl --namespace knative-samples run curl --image=radial/busyboxplus:curl -it

curl -v "default-broker.knative-samples.svc.cluster.local" \
  -X POST \
  -H "Ce-Id: 536808d3-88be-4077-9d7a-a3f162705f79" \
  -H "Ce-specversion: 0.3" \
  -H "Ce-Type: dev.knative.samples.helloworld" \
  -H "Ce-Source: dev.knative.samples/helloworldsource" \
  -H "Content-Type: application/json" \
  -d '{"msg":"Hello World from the curl pod."}'

Can you tell me what it is wrong because I spent all my week-end without finding any clue ?

Thanks,

Upvotes: 1

Views: 1010

Answers (2)

rom
rom

Reputation: 1049

Your application is accepting GET requests only, as you can see here - https://github.com/knative/docs/blob/master/docs/serving/samples/hello-world/helloworld-python/app.py

As you can see in the cloudevents spec - https://github.com/cloudevents/spec/blob/master/http-webhook.md#21-delivery-request

The HTTP method for the delivery request MUST be POST.

You have to use POST method to trigger your service.

If you want to fix it, you have two simple choices:

  1. You can change the image of the service to event_display (gcr.io/knative-releases/github.com/knative/eventing-sources/cmd/event_display)

  2. You can change the code of your application, and change L7 from @app.route('/') to @app.route('/', methods=['GET', 'POST'])

Upvotes: 0

josiemundi
josiemundi

Reputation: 11

Do you have cluster local gateway enabled? If not then this might be the reason why it isn't working. Details at the following link:

https://knative.dev/docs/install/installing-istio/

Upvotes: 1

Related Questions