Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 32 additions & 56 deletions docs/eventing/samples/iot-core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ export IOTCORE_PROJECT="s9-demo"
#### Variables you may Change

```shell
export CHANNEL_NAME="iot-demo"
export IOTCORE_REGISTRY="iot-demo"
export IOTCORE_DEVICE="iot-demo-client"
export IOTCORE_REGION="us-central1"
Expand All @@ -34,12 +33,6 @@ export IOTCORE_TOPIC_DEVICE="iot-demo-device-pubsub-topic"

### Prerequisites

#### Local

1. Clone
[Knative Eventing Sources](https://github.com/knative/eventing-sources)
locally.

#### Kubernetes

1. Have a running Kubernetes cluster with `kubectl` pointing at it.
Expand Down Expand Up @@ -67,13 +60,6 @@ export IOTCORE_TOPIC_DEVICE="iot-demo-device-pubsub-topic"

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

1. Create a GCP
Expand All @@ -94,44 +80,39 @@ export IOTCORE_TOPIC_DEVICE="iot-demo-device-pubsub-topic"
controller.

```shell
pushd $HOME/go/src/github.com/knative/eventing-sources
ko apply --filename config/default-gcppubsub.yaml
popd
kubectl apply --filename https://github.com/knative/eventing-sources/releases/download/v0.5.0/gcppubsub.yaml
```

### Deploying

#### Channel
#### Broker

1. Create a `Channel`.
1. Install the default `Broker`.

```shell
sed "s/CHANNEL_NAME/$CHANNEL_NAME/" channel.yaml |
kubectl --namespace default apply --filename -
kubectl label namespace default knative-eventing-injection=enabled
```

#### GCP PubSub Source

1. Deploy `gcp-pubsub-source.yaml`.

```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/CHANNEL_NAME/$CHANNEL_NAME/" \
gcp-pubsub-source.yaml |
docs/eventing/samples/iot-core/gcp-pubsub-source.yaml |
kubectl apply --filename -
```

#### Subscription
#### Trigger

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
sed "s/CHANNEL_NAME/$CHANNEL_NAME/" subscription.yaml |
ko apply --filename -
kubectl apply --filename docs/eventing/samples/iot-core/trigger.yaml
```

- This uses a very simple Knative Service to see that events are flowing.
Expand Down Expand Up @@ -178,14 +159,7 @@ Core.
We now have everything installed and ready to go. We will generate events and
see them in the subscriber.

1. Setup [`kail`](https://github.com/boz/kail) to tail the logs of the
subscriber.

```shell
kail -d message-dumper -c user-container
```

1. In a separate terminal, run the following program to generate events.
1. Run the following program to generate events:

```shell
go run github.com/knative/docs/docs/eventing/samples/iot-core/generator \
Expand All @@ -199,37 +173,39 @@ see them in the subscriber.
-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

To cleanup the knative resources:

1. Remove the gcppubsub controller:
1. Remove the `GcpPubSubSource`:

```shell
pushd $HOME/go/src/github.com/knative/eventing-sources
kubectl delete --filename config/default-gcppubsub.yaml
popd
sed -e "s/PROJECT_ID/$IOTCORE_PROJECT/" \
-e "s/TOPIC_NAME/$IOTCORE_TOPIC_DATA/" \
docs/eventing/samples/iot-core/gcp-pubsub-source.yaml |
kubectl delete --filename -
```

2. Remove the channel:
1. Remove the Trigger:

```shell
sed "s/CHANNEL_NAME/$CHANNEL_NAME/" channel.yaml |
kubectl --namespace default delete --filename -
kubectl delete --filename docs/eventing/samples/iot-core/trigger.yaml
```

3. Remove the gcppubsub source:
1. Remove the `GcpPubSubSource` controller:

```shell
sed -e "s/MY_GCP_PROJECT/$IOTCORE_PROJECT/" \
-e "s/TOPIC_NAME/$IOTCORE_TOPIC_DATA/" \
-e "s/CHANNEL_NAME/$CHANNEL_NAME/" \
gcp-pubsub-source.yaml |
kubectl delete --filename -
kubectl delete --filename https://github.com/knative/eventing-sources/releases/download/v0.5.0/gcppubsub.yaml
```

4. Remove the subscription:
```shell
sed "s/CHANNEL_NAME/$CHANNEL_NAME/" subscription.yaml |
kubectl delete --filename -
```
10 changes: 0 additions & 10 deletions docs/eventing/samples/iot-core/channel.yaml

This file was deleted.

6 changes: 3 additions & 3 deletions docs/eventing/samples/iot-core/gcp-pubsub-source.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ spec:
gcpCredsSecret:
name: google-cloud-key
key: key.json
googleCloudProject: MY_GCP_PROJECT
googleCloudProject: PROJECT_ID
topic: TOPIC_NAME
sink:
apiVersion: eventing.knative.dev/v1alpha1
kind: Channel
name: CHANNEL_NAME
kind: Broker
name: default
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
apiVersion: eventing.knative.dev/v1alpha1
kind: Subscription
kind: Trigger
metadata:
name: iot-demo
namespace: default
spec:
channel:
apiVersion: eventing.knative.dev/v1alpha1
kind: Channel
name: CHANNEL_NAME
subscriber:
ref:
apiVersion: serving.knative.dev/v1alpha1
Expand All @@ -28,4 +24,6 @@ spec:
revisionTemplate:
spec:
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