Skip to content

Instantly share code, notes, and snippets.

@ricardozanini
Created April 22, 2021 20:37
Show Gist options
  • Save ricardozanini/9d0652194db6738245fa4fcc566b543e to your computer and use it in GitHub Desktop.
Save ricardozanini/9d0652194db6738245fa4fcc566b543e to your computer and use it in GitHub Desktop.
Knative Broker doesn't support cloudevents+json content-type?

Steps to reproduce

  1. Apply the resources.yaml file kubectl apply -f resources.yaml -n <namespace>
  2. This will deploy a default InMemory Broker, a Trigger filtering by source: /from/ping and a custom event display, so we can see the content-type header.
  3. Run the following command from your terminal to create a temporary container to run curl:
kubectl run curl --image=radial/busyboxplus:curl -i --tty --rm
  1. In a new terminal window, run:
watch kubectl logs -l serving.knative.dev/service=cloudevent-display -c user-container
  1. Send this request in the terminal of step #3:
curl -vvv -X POST -H "content-type: application/cloudevents+json" \
    -d '{"specversion": "1.0", "type": "ping", "id": "123456", "source": "/from/ping", "data": {"message": "Hello world!"}}' \
    <broker internal URL>
  1. You should see no content-type in the event-display logs:
Ce-Source=/from/ping
Ce-Specversion=1.0
Ce-Type=ping
Forwarded=for=10.131.2.6;proto=http
K-Proxy-Request=activator
Traceparent=00-a1e415d80e39a33debb33420b9a87840-1e8a7713586c1dfe-00
X-Forwarded-For=10.131.2.6, 10.131.2.22
X-Forwarded-Proto=http
X-Request-Id=2f2e1e1b-3fd0-400a-ac78-0bbdf710942f
  1. Now run this:
curl -vvv -X POST -H "content-type: application/json" \
      -H "ce-specversion: 1.0"  \
      -H "ce-source: /from/ping"  \
      -H "ce-type: ping"  \
      -H "ce-id: 123456"  \
    -d '{"message": "Hello world!"}' \
    <broker internal URL>

You should see the correct content-type:

Ce-Specversion=1.0
Ce-Type=ping
Content-Type=application/json
Forwarded=for=10.131.2.6;proto=http
K-Proxy-Request=activator
Traceparent=00-1847ca93971bd3385ddeaf760c70c0fa-71e109a039a3beff-00
X-Forwarded-For=10.131.2.6, 10.130.2.5
X-Forwarded-Proto=http
X-Request-Id=b10d34ba-0677-4c58-b199-6d64044a7f5e
# a default broker
apiVersion: eventing.knative.dev/v1
kind: Broker
metadata:
name: default
---
# simple knative application to display the routed messages
apiVersion: serving.knative.dev/v1
kind: Service
metadata:
name: cloudevent-display
spec:
template:
spec:
containers:
- image: quay.io/ricardozanini/cloudevent-display:latest
---
# our display service will get any events in the broker
apiVersion: eventing.knative.dev/v1
kind: Trigger
metadata:
name: cloudevent-display-trigger
spec:
broker: default
filter:
attributes:
source: "/from/ping"
subscriber:
ref:
apiVersion: serving.knative.dev/v1
kind: Service
name: cloudevent-display
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment