Skip to content
This repository has been archived by the owner on Jun 19, 2022. It is now read-only.

Updated CloudPubSubSource docs #501

Merged
merged 5 commits into from
Jan 22, 2020
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion docs/examples/cloudauditlogssource/event-display.yaml
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
104 changes: 102 additions & 2 deletions docs/examples/cloudpubsubsource/README.md
Original file line number Diff line number Diff line change
@@ -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#).
capri-xiyue marked this conversation as resolved.
Show resolved Hide resolved
capri-xiyue marked this conversation as resolved.
Show resolved Hide resolved

## 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:
capri-xiyue marked this conversation as resolved.
Show resolved Hide resolved

```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
```
21 changes: 21 additions & 0 deletions docs/examples/cloudpubsubsource/cloudpubsubsource.yaml
Original file line number Diff line number Diff line change
@@ -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
48 changes: 48 additions & 0 deletions docs/examples/cloudpubsubsource/event-display.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Copyright 2019 Google LLC
capri-xiyue marked this conversation as resolved.
Show resolved Hide resolved
#
# 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
capri-xiyue marked this conversation as resolved.
Show resolved Hide resolved
ports:
- containerPort: 8080

---

apiVersion: v1
kind: Service
metadata:
name: event-display
spec:
selector:
app: event-display
ports:
- protocol: TCP
port: 80
targetPort: 8080