Skip to content

Instantly share code, notes, and snippets.

@ricardozanini
Created April 22, 2021 20:37
Show Gist options
  • Select an option

  • Save ricardozanini/9d0652194db6738245fa4fcc566b543e to your computer and use it in GitHub Desktop.

Select an option

Save ricardozanini/9d0652194db6738245fa4fcc566b543e to your computer and use it in GitHub Desktop.

Revisions

  1. ricardozanini created this gist Apr 22, 2021.
    54 changes: 54 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,54 @@
    ## 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:
    ```shell
    kubectl run curl --image=radial/busyboxplus:curl -i --tty --rm
    ```
    4. In a new terminal window, run:
    ```shell
    watch kubectl logs -l serving.knative.dev/service=cloudevent-display -c user-container
    ```
    6. Send this request in the terminal of step #3:
    ```shell
    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>
    ```
    7. 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
    ```
    9. Now run this:
    ```shell
    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
    ```
    32 changes: 32 additions & 0 deletions resources.yaml
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,32 @@
    # 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