github.com/argoproj/argo-events@v1.9.1/docs/eventsources/setup/gcp-pub-sub.md (about) 1 # GCP Pub/Sub 2 3 GCP Pub/Sub event-source subscribes to messages published by GCP publisher and helps sensor trigger workloads. 4 5 ## Event Structure 6 7 The structure of an event dispatched by the event-source over the eventbus looks like following, 8 9 ```js 10 { 11 "context": { 12 "type": "type_of_event_source", 13 "specversion": "cloud_events_version", 14 "source": "name_of_the_event_source", 15 "id": "unique_event_id", 16 "time": "event_time", 17 "datacontenttype": "type_of_data", 18 "subject": "name_of_the_configuration_within_event_source" 19 }, 20 "data": { 21 "id": "message id", 22 // Attributes represents the key-value pairs the current message 23 // is labelled with. 24 "attributes": "key-values", 25 "publishTime": "// The time at which the message was published", 26 "body": "body refers to the message data", 27 } 28 } 29 ``` 30 31 ## Specification 32 33 GCP Pub/Sub event-source specification is available [here](https://github.com/argoproj/argo-events/blob/stable/api/event-source.md#pubsubeventsource). 34 35 ## Setup 36 37 1. Fetch the project credentials JSON file from GCP console. 38 39 If you use Workload Identity, you can skip this and next steps. 40 41 1. Create a K8s secret called `gcp-credentials` to store the credentials file. 42 43 apiVersion: v1 44 data: 45 key.json: <YOUR_CREDENTIALS_STRING_FROM_JSON_FILE> 46 kind: Secret 47 metadata: 48 name: gcp-credentials 49 namespace: argo-events 50 type: Opaque 51 52 1. Create the event source by running the following command. 53 54 kubectl apply -n argo-events -f https://raw.githubusercontent.com/argoproj/argo-events/stable/examples/event-sources/gcp-pubsub.yaml 55 56 If you use Workload Identity, omit `credentialSecret` field. Instead don't forget to configure appropriate service account (see [example](https://github.com/argoproj/argo-events/blob/stable/examples/event-sources/gcp-pubsub.yaml)). 57 58 1. Inspect the event-source pod logs to make sure it was able to subscribe to the topic. 59 60 1. Create the sensor by running the following command. 61 62 kubectl apply -n argo-events -f https://raw.githubusercontent.com/argoproj/argo-events/stable/examples/sensors/gcp-pubsub.yaml 63 64 1. Publish a message from GCP Pub/Sub console. 65 66 1. Once a message is published, an argo workflow will be triggered. Run `argo list` to find the workflow. 67 68 ## Subscription, topic and service account preparation 69 70 You can use existing subscriptions/topics, or let Argo Events create them. 71 72 Here's the table of which fields are required in the configuration file and what permissions are needed for service account. 73 74 | Actions | Required configuration fields | Necessary permissions for service account | Example role | 75 | :----------------------------------------- | :------------------------------------------------------ | :----------------------------------------------------------------------------------------------------------- | :--------------------------------------------------- | 76 | Use existing subscription | Existing `SubscriptionID` | `pubsub.subscriptions.consume` for the subscription | `roles/pubsub.subscriber` | 77 | Use existing subscription and verify topic | Existing `SubscriptionID` and its `Topic` | Above +<br>`pubsub.subscriptions.get` for the subscription | `roles/pubsub.subscriber`<br>+ `roles/pubsub.viewer` | 78 | Create subscription for existing topic | Existing `Topic`<br>(`SubscriptionID` is optional†) | Above +<br>`pubsub.subscriptions.create` for the project<br>`pubsub.topics.attachSubscription` for the topic | `roles/pubsub.subscriber`<br>+ `roles/pubsub.editor` | 79 | Create topic and subscription | Non-existing `Topic`<br>(`SubscriptionID` is optional†) | Above +<br>`pubsub.topic.create` for the project | `roles/pubsub.subscriber`<br>+ `roles/pubsub.editor` | 80 81 † _If you omit `SubscriptionID`, a generated hash value is used._ 82 83 For more details about access control, refer to GCP documents: 84 85 - [Access control | Cloud Pub/Sub Documentation | Google Cloud ⧉](https://cloud.google.com/pubsub/docs/access-control#testing_permissions) 86 87 ## Troubleshoot 88 89 Please read the [FAQ](https://argoproj.github.io/argo-events/FAQ/).