Update the iot-core demo to use Broker rather than Channel (#1103)

* Update the iot-core demo to use Broker rather than Channel. Also remove ko and kail usage.

* Update docs/eventing/samples/iot-core/README.md

Co-Authored-By: Harwayne <harwayne@google.com>
This commit is contained in:
Adam Harwayne 2019-04-01 14:25:56 -07:00 committed by Knative Prow Robot
parent cb504f078a
commit 88f3afba53
4 changed files with 42 additions and 78 deletions

View File

@ -24,7 +24,6 @@ export IOTCORE_PROJECT="s9-demo"
#### Variables you may Change #### Variables you may Change
```shell ```shell
export CHANNEL_NAME="iot-demo"
export IOTCORE_REGISTRY="iot-demo" export IOTCORE_REGISTRY="iot-demo"
export IOTCORE_DEVICE="iot-demo-client" export IOTCORE_DEVICE="iot-demo-client"
export IOTCORE_REGION="us-central1" export IOTCORE_REGION="us-central1"
@ -34,12 +33,6 @@ export IOTCORE_TOPIC_DEVICE="iot-demo-device-pubsub-topic"
### Prerequisites ### Prerequisites
#### Local
1. Clone
[Knative Eventing Sources](https://github.com/knative/eventing-sources)
locally.
#### Kubernetes #### Kubernetes
1. Have a running Kubernetes cluster with `kubectl` pointing at it. 1. Have a running Kubernetes cluster with `kubectl` pointing at it.
@ -67,13 +60,6 @@ export IOTCORE_TOPIC_DEVICE="iot-demo-device-pubsub-topic"
1. Setup [Knative Eventing](../../../eventing). 1. Setup [Knative Eventing](../../../eventing).
1. Install the
[in-memory `ClusterChannelProvisioner`](https://github.com/knative/eventing/tree/master/config/provisioners/in-memory-channel).
- Note that you can skip this if you choose to use a different type of
`Channel`. If so, you will need to modify `channel.yaml` before deploying
it.
#### GCP PubSub Source #### GCP PubSub Source
1. Create a GCP 1. Create a GCP
@ -94,20 +80,17 @@ export IOTCORE_TOPIC_DEVICE="iot-demo-device-pubsub-topic"
controller. controller.
```shell ```shell
pushd $HOME/go/src/github.com/knative/eventing-sources kubectl apply --filename https://github.com/knative/eventing-sources/releases/download/v0.5.0/gcppubsub.yaml
ko apply --filename config/default-gcppubsub.yaml
popd
``` ```
### Deploying ### Deploying
#### Channel #### Broker
1. Create a `Channel`. 1. Install the default `Broker`.
```shell ```shell
sed "s/CHANNEL_NAME/$CHANNEL_NAME/" channel.yaml | kubectl label namespace default knative-eventing-injection=enabled
kubectl --namespace default apply --filename -
``` ```
#### GCP PubSub Source #### GCP PubSub Source
@ -115,23 +98,21 @@ export IOTCORE_TOPIC_DEVICE="iot-demo-device-pubsub-topic"
1. Deploy `gcp-pubsub-source.yaml`. 1. Deploy `gcp-pubsub-source.yaml`.
```shell ```shell
sed -e "s/MY_GCP_PROJECT/$IOTCORE_PROJECT/" \ sed -e "s/PROJECT_ID/$IOTCORE_PROJECT/" \
-e "s/TOPIC_NAME/$IOTCORE_TOPIC_DATA/" \ -e "s/TOPIC_NAME/$IOTCORE_TOPIC_DATA/" \
-e "s/CHANNEL_NAME/$CHANNEL_NAME/" \ docs/eventing/samples/iot-core/gcp-pubsub-source.yaml |
gcp-pubsub-source.yaml |
kubectl apply --filename - kubectl apply --filename -
``` ```
#### Subscription #### Trigger
Even though the `Source` isn't completely ready yet, we can setup the Even though the `Source` isn't completely ready yet, we can setup the
`Subscription` for all events coming out of it. `Trigger` for all events coming out of it.
1. Deploy `subscription.yaml`. 1. Deploy `trigger.yaml`.
```shell ```shell
sed "s/CHANNEL_NAME/$CHANNEL_NAME/" subscription.yaml | kubectl apply --filename docs/eventing/samples/iot-core/trigger.yaml
ko apply --filename -
``` ```
- This uses a very simple Knative Service to see that events are flowing. - This uses a very simple Knative Service to see that events are flowing.
@ -178,14 +159,7 @@ Core.
We now have everything installed and ready to go. We will generate events and We now have everything installed and ready to go. We will generate events and
see them in the subscriber. see them in the subscriber.
1. Setup [`kail`](https://github.com/boz/kail) to tail the logs of the 1. Run the following program to generate events:
subscriber.
```shell
kail -d message-dumper -c user-container
```
1. In a separate terminal, run the following program to generate events.
```shell ```shell
go run github.com/knative/docs/docs/eventing/samples/iot-core/generator \ go run github.com/knative/docs/docs/eventing/samples/iot-core/generator \
@ -199,37 +173,39 @@ see them in the subscriber.
-events 10 -events 10
``` ```
1. Inspect the logs of the subscriber:
```shell
kubectl logs --selector serving.knative.dev/service=message-dumper -c user-container
```
You should see something along the similar to:
```shell
{"ID":"481014114648052","Data":"eyJzb3VyY2VfaWQiOiJpb3QtY29yZSBkZW1vIiwiZXZlbnRfaWQiOiJlaWQtMzI3MjJiMzItZWU5Mi00YzZlLWEzOTgtNDlmYjRkYWYyNGE1IiwiZXZlbnRfdHMiOjE1NTM3MTczOTYsIm1ldHJpYyI6MC4xMzY1MjI5OH0=","Attributes":{"deviceId":"iot-demo-client","deviceNumId":"2754785852315736","deviceRegistryId":"iot-demo","deviceRegistryLocation":"us-central1","projectId":"s9-demo","subFolder":""},"PublishTime":"2019-03-27T20:09:56.685Z"}
### Cleanup ### Cleanup
To cleanup the knative resources: To cleanup the knative resources:
1. Remove the gcppubsub controller: 1. Remove the `GcpPubSubSource`:
```shell ```shell
pushd $HOME/go/src/github.com/knative/eventing-sources sed -e "s/PROJECT_ID/$IOTCORE_PROJECT/" \
kubectl delete --filename config/default-gcppubsub.yaml
popd
```
2. Remove the channel:
```shell
sed "s/CHANNEL_NAME/$CHANNEL_NAME/" channel.yaml |
kubectl --namespace default delete --filename -
```
3. Remove the gcppubsub source:
```shell
sed -e "s/MY_GCP_PROJECT/$IOTCORE_PROJECT/" \
-e "s/TOPIC_NAME/$IOTCORE_TOPIC_DATA/" \ -e "s/TOPIC_NAME/$IOTCORE_TOPIC_DATA/" \
-e "s/CHANNEL_NAME/$CHANNEL_NAME/" \ docs/eventing/samples/iot-core/gcp-pubsub-source.yaml |
gcp-pubsub-source.yaml |
kubectl delete --filename - kubectl delete --filename -
``` ```
4. Remove the subscription: 1. Remove the Trigger:
```shell ```shell
sed "s/CHANNEL_NAME/$CHANNEL_NAME/" subscription.yaml | kubectl delete --filename docs/eventing/samples/iot-core/trigger.yaml
kubectl delete --filename -
``` ```
1. Remove the `GcpPubSubSource` controller:
```shell
kubectl delete --filename https://github.com/knative/eventing-sources/releases/download/v0.5.0/gcppubsub.yaml
```

View File

@ -1,10 +0,0 @@
apiVersion: eventing.knative.dev/v1alpha1
kind: Channel
metadata:
name: CHANNEL_NAME
namespace: default
spec:
provisioner:
apiVersion: eventing.knative.dev/v1alpha1
kind: ClusterChannelProvisioner
name: in-memory-channel

View File

@ -10,9 +10,9 @@ spec:
gcpCredsSecret: gcpCredsSecret:
name: google-cloud-key name: google-cloud-key
key: key.json key: key.json
googleCloudProject: MY_GCP_PROJECT googleCloudProject: PROJECT_ID
topic: TOPIC_NAME topic: TOPIC_NAME
sink: sink:
apiVersion: eventing.knative.dev/v1alpha1 apiVersion: eventing.knative.dev/v1alpha1
kind: Channel kind: Broker
name: CHANNEL_NAME name: default

View File

@ -1,13 +1,9 @@
apiVersion: eventing.knative.dev/v1alpha1 apiVersion: eventing.knative.dev/v1alpha1
kind: Subscription kind: Trigger
metadata: metadata:
name: iot-demo name: iot-demo
namespace: default namespace: default
spec: spec:
channel:
apiVersion: eventing.knative.dev/v1alpha1
kind: Channel
name: CHANNEL_NAME
subscriber: subscriber:
ref: ref:
apiVersion: serving.knative.dev/v1alpha1 apiVersion: serving.knative.dev/v1alpha1
@ -28,4 +24,6 @@ spec:
revisionTemplate: revisionTemplate:
spec: spec:
container: container:
image: github.com/knative/eventing-sources/cmd/message_dumper # This corresponds to
# https://github.com/knative/eventing-sources/blob/release-0.3/cmd/message_dumper/dumper.go
image: gcr.io/knative-releases/github.com/knative/eventing-sources/cmd/message_dumper@sha256:8423232db7a7b4010c0cfbfaef95745efe962631af9b7456903825801a7893f7