From 84485aca15c423fec80fafde3d37727b9ad09af1 Mon Sep 17 00:00:00 2001 From: XiyueYu Date: Tue, 21 Jan 2020 14:24:30 -0800 Subject: [PATCH 1/5] Updated CloudPubSubSource docs --- docs/examples/cloudpubsubsource/README.md | 104 +++++++++++++++++- .../cloudpubsubsource/cloudpubsubsource.yaml | 21 ++++ .../cloudpubsubsource/event-display.yaml | 48 ++++++++ 3 files changed, 171 insertions(+), 2 deletions(-) create mode 100644 docs/examples/cloudpubsubsource/cloudpubsubsource.yaml create mode 100644 docs/examples/cloudpubsubsource/event-display.yaml diff --git a/docs/examples/cloudpubsubsource/README.md b/docs/examples/cloudpubsubsource/README.md index 88c8a48c88..83e1b88d7d 100644 --- a/docs/examples/cloudpubsubsource/README.md +++ b/docs/examples/cloudpubsubsource/README.md @@ -1,4 +1,104 @@ # CloudPubSubSource Example -Please refer to the [example](https://knative.dev/docs/eventing/samples/gcp-pubsub-source/) in Knative until we migrate -it to this repo. +## Overview + +This sample shows how to configure the CloudPubSubSource. +This source is most useful as a bridge from other GCP services, +such as [Cloud Storage](https://cloud.google.com/storage/docs/pubsub-notifications), +[Cloud Scheduler](https://cloud.google.com/scheduler/docs/creating#). + +## Prerequisites + +1. [Install Knative with GCP](../../install/README.md). + +1. [Create a Pub/Sub enabled Service Account](../../install/pubsub-service-account.md) + +## Deployment + +1. Create a GCP PubSub Topic. If you change its name (`testing`), you also need + to update the `topic` in the + [`CloudPubSubSource`](cloudpubsubsource.yaml) file: + + ```shell + gcloud pubsub topics create testing + ``` + +1. Create a [`CloudPubSubSource`](cloudpubsubsource.yaml) + + ```shell + kubectl apply --filename cloudpubsubsource.yaml + ``` + +1. Create a [`Service`](event-display.yaml) that the CloudAuditLogsSource will sink into: + + ```shell + kubectl apply --filename event-display.yaml + ``` + +## Publish + +Publish messages to your GCP PubSub topic: + +```shell +gcloud pubsub topics publish testing --message='{"Hello": "world"}' +``` + +## Verify + +We will verify that the published event was sent by looking at the logs of the +service that this CloudPubSubSource sinks to. + +1. We need to wait for the downstream pods to get started and receive our event, + wait 60 seconds. + + - You can check the status of the downstream pods with: + + ```shell + kubectl get pods --selector app=event-display + ``` + + You should see at least one. + +1. Inspect the logs of the service: + + ```shell + kubectl logs --selector app=event-display -c user-container --tail=200 + ``` + +You should see log lines similar to: + +```shell +☁️ cloudevents.Event +Validation: valid +Context Attributes, + specversion: 1.0 + type: com.google.cloud.pubsub.topic.publish + source: //pubsub.googleapis.com/projects/xiyue-knative-gcp/topics/testing + id: 946366448650699 + time: 2020-01-21T22:12:06.742Z + datacontenttype: application/octet-stream +Extensions, + knativecemode: binary +Data, + {"Hello": "world"} +``` + +## What's Next + +1. For integrating with Cloud Storage see the [Storage example](../../examples/cloudstoragesource/README.md). +1. For integrating with Cloud Scheduler see the [Scheduler example](../../examples/cloudschedulersource/README.md). +1. For integrating with Cloud Audit Logs see the [Cloud Audit Logs example](../../examples/cloudauditlogssource/README.md). +1. For more information about CloudEvents, see the [HTTP transport bindings documentation](https://github.com/cloudevents/spec). + +## Cleaning Up + +1. Delete the `CloudPubSubSource` + + ```shell + kubectl delete -f ./cloudpubsubsource.yaml + ``` +1. Delete the `Service` + + ```shell + kubectl delete -f ./event-display.yaml + ``` diff --git a/docs/examples/cloudpubsubsource/cloudpubsubsource.yaml b/docs/examples/cloudpubsubsource/cloudpubsubsource.yaml new file mode 100644 index 0000000000..ac7fdcd26b --- /dev/null +++ b/docs/examples/cloudpubsubsource/cloudpubsubsource.yaml @@ -0,0 +1,21 @@ +apiVersion: events.cloud.google.com/v1alpha1 +kind: CloudPubSubSource +metadata: + name: cloudpubsubsource-test +spec: + topic: testing + sink: + ref: + apiVersion: v1 + kind: Service + name: event-display + + # If running in GKE, we will ask the metadata server, change this if required. + #project: MY_PROJECT + # The default secret name and key, change this if required. + #secret: + # name: google-cloud-key + # key: key.json + #pubsubSecret: # A secret in the default namespace for Pub/Sub operations + #name: google-cloud-key + #key: key.json diff --git a/docs/examples/cloudpubsubsource/event-display.yaml b/docs/examples/cloudpubsubsource/event-display.yaml new file mode 100644 index 0000000000..89e01e9e15 --- /dev/null +++ b/docs/examples/cloudpubsubsource/event-display.yaml @@ -0,0 +1,48 @@ +# Copyright 2019 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# This is a very simple deployment that writes the incoming CloudEvent to its log. + +apiVersion: apps/v1 +kind: Deployment +metadata: + name: event-display +spec: + selector: + matchLabels: + app: event-display + template: + metadata: + labels: + app: event-display + spec: + containers: + - name: user-container + image: gcr.io/knative-releases/knative.dev/eventing-contrib/cmd/event_display@sha256:070f31589d919779a83adf3cc0f0b0e3f5f063eb57a67d53e5e8d0c5eefb57ba + ports: + - containerPort: 8080 + +--- + +apiVersion: v1 +kind: Service +metadata: + name: event-display +spec: + selector: + app: event-display + ports: + - protocol: TCP + port: 80 + targetPort: 8080 From fb54b128ece1268924a19995490f7c3d5d05d5b4 Mon Sep 17 00:00:00 2001 From: XiyueYu Date: Tue, 21 Jan 2020 14:26:21 -0800 Subject: [PATCH 2/5] fixed typo --- docs/examples/cloudauditlogssource/event-display.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/examples/cloudauditlogssource/event-display.yaml b/docs/examples/cloudauditlogssource/event-display.yaml index 89e01e9e15..8a165b141d 100644 --- a/docs/examples/cloudauditlogssource/event-display.yaml +++ b/docs/examples/cloudauditlogssource/event-display.yaml @@ -1,4 +1,4 @@ -# Copyright 2019 Google LLC +# Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. From 3dec1df727cda30aef48755645f64ebe400393cf Mon Sep 17 00:00:00 2001 From: XiyueYu Date: Tue, 21 Jan 2020 16:18:57 -0800 Subject: [PATCH 3/5] modified README.md --- docs/examples/cloudauditlogssource/README.md | 5 +---- docs/examples/cloudpubsubsource/README.md | 5 +---- docs/examples/cloudpubsubsource/event-display.yaml | 2 +- docs/examples/cloudschedulersource/README.md | 5 +---- docs/examples/cloudstoragesource/README.md | 5 +---- 5 files changed, 5 insertions(+), 17 deletions(-) diff --git a/docs/examples/cloudauditlogssource/README.md b/docs/examples/cloudauditlogssource/README.md index 0a3afa4ac0..c91bdd5ca7 100644 --- a/docs/examples/cloudauditlogssource/README.md +++ b/docs/examples/cloudauditlogssource/README.md @@ -55,10 +55,7 @@ Create a GCP PubSub Topic: We will verify that the published event was sent by looking at the logs of the service that this CloudAuditLogsSource sinks to. -1. We need to wait for the downstream pods to get started and receive our event, - wait 60 seconds. - - - You can check the status of the downstream pods with: +1. You can check the status of the downstream pods with: ```shell kubectl get pods --selector app=event-display diff --git a/docs/examples/cloudpubsubsource/README.md b/docs/examples/cloudpubsubsource/README.md index 83e1b88d7d..4ff7616518 100644 --- a/docs/examples/cloudpubsubsource/README.md +++ b/docs/examples/cloudpubsubsource/README.md @@ -48,10 +48,7 @@ gcloud pubsub topics publish testing --message='{"Hello": "world"}' We will verify that the published event was sent by looking at the logs of the service that this CloudPubSubSource sinks to. -1. We need to wait for the downstream pods to get started and receive our event, - wait 60 seconds. - - - You can check the status of the downstream pods with: +1. You can check the status of the downstream pods with: ```shell kubectl get pods --selector app=event-display diff --git a/docs/examples/cloudpubsubsource/event-display.yaml b/docs/examples/cloudpubsubsource/event-display.yaml index 89e01e9e15..8a165b141d 100644 --- a/docs/examples/cloudpubsubsource/event-display.yaml +++ b/docs/examples/cloudpubsubsource/event-display.yaml @@ -1,4 +1,4 @@ -# Copyright 2019 Google LLC +# Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/docs/examples/cloudschedulersource/README.md b/docs/examples/cloudschedulersource/README.md index 85cb9a461b..1f8c3f55b7 100644 --- a/docs/examples/cloudschedulersource/README.md +++ b/docs/examples/cloudschedulersource/README.md @@ -38,10 +38,7 @@ events from [Google Cloud Scheduler](https://cloud.google.com/scheduler/). We will verify that the published event was sent by looking at the logs of the service that this Scheduler job sinks to. -1. We need to wait for the downstream pods to get started and receive our event, - wait 60 seconds. - - - You can check the status of the downstream pods with: +1. You can check the status of the downstream pods with: ```shell kubectl get pods --selector app=event-display diff --git a/docs/examples/cloudstoragesource/README.md b/docs/examples/cloudstoragesource/README.md index 18a6f0abed..8063165a31 100644 --- a/docs/examples/cloudstoragesource/README.md +++ b/docs/examples/cloudstoragesource/README.md @@ -110,10 +110,7 @@ gsutil cp cloudstoragesource.yaml gs://$BUCKET/testfilehere' Verify that the published message was sent by looking at the logs of the service that this Storage notification sinks to. -1. To ensure the downstream pods to get started and receive our event, wait 60 - seconds. - - You can check the status of the downstream pods with: +1. You can check the status of the downstream pods with: ```shell kubectl get pods --selector app=event-display From 999c6a0282ab567897c573849aaf995734867682 Mon Sep 17 00:00:00 2001 From: XiyueYu Date: Tue, 21 Jan 2020 16:22:29 -0800 Subject: [PATCH 4/5] deleted what's next part --- docs/examples/cloudauditlogssource/README.md | 7 ------- docs/examples/cloudpubsubsource/README.md | 7 ------- docs/examples/cloudschedulersource/README.md | 7 ------- docs/examples/cloudstoragesource/README.md | 7 ------- 4 files changed, 28 deletions(-) diff --git a/docs/examples/cloudauditlogssource/README.md b/docs/examples/cloudauditlogssource/README.md index c91bdd5ca7..de83b683a2 100644 --- a/docs/examples/cloudauditlogssource/README.md +++ b/docs/examples/cloudauditlogssource/README.md @@ -148,13 +148,6 @@ Data, } ``` -## What's Next - -1. For integrating with Cloud Pub/Sub, see the [PubSub example](../../examples/cloudpubsubsource/README.md). -1. For integrating with Cloud Storage see the [Storage example](../../examples/cloudstoragesource/README.md). -1. For integrating with Cloud Scheduler see the [Scheduler example](../../examples/cloudschedulersource/README.md). -1. For more information about CloudEvents, see the [HTTP transport bindings documentation](https://github.com/cloudevents/spec). - ## Cleaning Up 1. Delete the `CloudAuditLogsSource` diff --git a/docs/examples/cloudpubsubsource/README.md b/docs/examples/cloudpubsubsource/README.md index 4ff7616518..e369be73fb 100644 --- a/docs/examples/cloudpubsubsource/README.md +++ b/docs/examples/cloudpubsubsource/README.md @@ -80,13 +80,6 @@ Data, {"Hello": "world"} ``` -## What's Next - -1. For integrating with Cloud Storage see the [Storage example](../../examples/cloudstoragesource/README.md). -1. For integrating with Cloud Scheduler see the [Scheduler example](../../examples/cloudschedulersource/README.md). -1. For integrating with Cloud Audit Logs see the [Cloud Audit Logs example](../../examples/cloudauditlogssource/README.md). -1. For more information about CloudEvents, see the [HTTP transport bindings documentation](https://github.com/cloudevents/spec). - ## Cleaning Up 1. Delete the `CloudPubSubSource` diff --git a/docs/examples/cloudschedulersource/README.md b/docs/examples/cloudschedulersource/README.md index 1f8c3f55b7..ec646c7b28 100644 --- a/docs/examples/cloudschedulersource/README.md +++ b/docs/examples/cloudschedulersource/README.md @@ -71,13 +71,6 @@ Data, my test data ``` -## What's Next - -1. For integrating with Cloud Pub/Sub, see the [PubSub example](../../examples/cloudpubsubsource/README.md). -1. For integrating with Cloud Storage see the [Storage example](../../examples/cloudstoragesource/README.md). -1. For integrating with Cloud Audit Logs see the [Cloud Audit Logs example](../../examples/cloudauditlogssource/README.md). -1. For more information about CloudEvents, see the [HTTP transport bindings documentation](https://github.com/cloudevents/spec). - ## Cleaning Up 1. Delete the `CloudSchedulerSource` diff --git a/docs/examples/cloudstoragesource/README.md b/docs/examples/cloudstoragesource/README.md index 8063165a31..5c51bb090c 100644 --- a/docs/examples/cloudstoragesource/README.md +++ b/docs/examples/cloudstoragesource/README.md @@ -159,13 +159,6 @@ Data, } ``` -## What's Next - -1. For integrating with Cloud Pub/Sub, see the [PubSub example](../../examples/cloudpubsubsource/README.md). -1. For integrating with Cloud Scheduler see the [Scheduler example](../../examples/cloudschedulersource/README.md). -1. For integrating with Cloud Audit Logs see the [Cloud Audit Logs example](../../examples/cloudauditlogssource/README.md). -1. For more information about CloudEvents, see the [HTTP transport bindings documentation](https://github.com/cloudevents/spec). - ## Cleaning Up 1. Delete the `CloudStorageSource` From a5010f12fda985d9197df0b3a938ec7314a8b44c Mon Sep 17 00:00:00 2001 From: XiyueYu Date: Wed, 22 Jan 2020 10:42:10 -0800 Subject: [PATCH 5/5] modified the comments --- docs/examples/cloudauditlogssource/README.md | 10 +++++++++- docs/examples/cloudpubsubsource/README.md | 15 ++++++++++----- docs/examples/cloudschedulersource/README.md | 10 +++++++++- docs/examples/cloudstoragesource/README.md | 10 +++++++++- 4 files changed, 37 insertions(+), 8 deletions(-) diff --git a/docs/examples/cloudauditlogssource/README.md b/docs/examples/cloudauditlogssource/README.md index de83b683a2..745a21bab7 100644 --- a/docs/examples/cloudauditlogssource/README.md +++ b/docs/examples/cloudauditlogssource/README.md @@ -55,7 +55,8 @@ Create a GCP PubSub Topic: We will verify that the published event was sent by looking at the logs of the service that this CloudAuditLogsSource sinks to. -1. You can check the status of the downstream pods with: +1. We need to wait for the downstream pods to get started and receive our event, + wait 60 seconds. You can check the status of the downstream pods with: ```shell kubectl get pods --selector app=event-display @@ -148,6 +149,13 @@ Data, } ``` +## What's Next + +1. For integrating with Cloud Pub/Sub, see the [PubSub example](../../examples/cloudpubsubsource/README.md). +1. For integrating with Cloud Storage see the [Storage example](../../examples/cloudstoragesource/README.md). +1. For integrating with Cloud Scheduler see the [Scheduler example](../../examples/cloudschedulersource/README.md). +1. For more information about CloudEvents, see the [HTTP transport bindings documentation](https://github.com/cloudevents/spec). + ## Cleaning Up 1. Delete the `CloudAuditLogsSource` diff --git a/docs/examples/cloudpubsubsource/README.md b/docs/examples/cloudpubsubsource/README.md index e369be73fb..b14bb78f8b 100644 --- a/docs/examples/cloudpubsubsource/README.md +++ b/docs/examples/cloudpubsubsource/README.md @@ -2,10 +2,7 @@ ## Overview -This sample shows how to configure the CloudPubSubSource. -This source is most useful as a bridge from other GCP services, -such as [Cloud Storage](https://cloud.google.com/storage/docs/pubsub-notifications), -[Cloud Scheduler](https://cloud.google.com/scheduler/docs/creating#). +This sample shows how to configure the CloudPubSubSource. CloudPubSubSource fires a new event each time a message is published on a [Google Cloud Platform PubSub topic](https://cloud.google.com/pubsub/). ## Prerequisites @@ -48,7 +45,8 @@ gcloud pubsub topics publish testing --message='{"Hello": "world"}' We will verify that the published event was sent by looking at the logs of the service that this CloudPubSubSource sinks to. -1. You can check the status of the downstream pods with: +1. We need to wait for the downstream pods to get started and receive our event, + wait 60 seconds. You can check the status of the downstream pods with: ```shell kubectl get pods --selector app=event-display @@ -80,6 +78,13 @@ Data, {"Hello": "world"} ``` +## What's Next + +1. For integrating with Cloud Storage see the [Storage example](../../examples/cloudstoragesource/README.md). +1. For integrating with Cloud Scheduler see the [Scheduler example](../../examples/cloudschedulersource/README.md). +1. For integrating with Cloud Audit Logs see the [Cloud Audit Logs example](../../examples/cloudauditlogssource/README.md). +1. For more information about CloudEvents, see the [HTTP transport bindings documentation](https://github.com/cloudevents/spec). + ## Cleaning Up 1. Delete the `CloudPubSubSource` diff --git a/docs/examples/cloudschedulersource/README.md b/docs/examples/cloudschedulersource/README.md index ec646c7b28..13e1479cd0 100644 --- a/docs/examples/cloudschedulersource/README.md +++ b/docs/examples/cloudschedulersource/README.md @@ -38,7 +38,8 @@ events from [Google Cloud Scheduler](https://cloud.google.com/scheduler/). We will verify that the published event was sent by looking at the logs of the service that this Scheduler job sinks to. -1. You can check the status of the downstream pods with: +1. We need to wait for the downstream pods to get started and receive our event, + wait 60 seconds. You can check the status of the downstream pods with: ```shell kubectl get pods --selector app=event-display @@ -71,6 +72,13 @@ Data, my test data ``` +## What's Next + +1. For integrating with Cloud Pub/Sub, see the [PubSub example](../../examples/cloudpubsubsource/README.md). +1. For integrating with Cloud Storage see the [Storage example](../../examples/cloudstoragesource/README.md). +1. For integrating with Cloud Audit Logs see the [Cloud Audit Logs example](../../examples/cloudauditlogssource/README.md). +1. For more information about CloudEvents, see the [HTTP transport bindings documentation](https://github.com/cloudevents/spec). + ## Cleaning Up 1. Delete the `CloudSchedulerSource` diff --git a/docs/examples/cloudstoragesource/README.md b/docs/examples/cloudstoragesource/README.md index 5c51bb090c..ee1dc379d6 100644 --- a/docs/examples/cloudstoragesource/README.md +++ b/docs/examples/cloudstoragesource/README.md @@ -110,7 +110,8 @@ gsutil cp cloudstoragesource.yaml gs://$BUCKET/testfilehere' Verify that the published message was sent by looking at the logs of the service that this Storage notification sinks to. -1. You can check the status of the downstream pods with: +1. We need to wait for the downstream pods to get started and receive our event, + wait 60 seconds. You can check the status of the downstream pods with: ```shell kubectl get pods --selector app=event-display @@ -159,6 +160,13 @@ Data, } ``` +## What's Next + +1. For integrating with Cloud Pub/Sub, see the [PubSub example](../../examples/cloudpubsubsource/README.md). +1. For integrating with Cloud Scheduler see the [Scheduler example](../../examples/cloudschedulersource/README.md). +1. For integrating with Cloud Audit Logs see the [Cloud Audit Logs example](../../examples/cloudauditlogssource/README.md). +1. For more information about CloudEvents, see the [HTTP transport bindings documentation](https://github.com/cloudevents/spec). + ## Cleaning Up 1. Delete the `CloudStorageSource`