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

Latest commit

 

History

History
139 lines (104 loc) · 4.57 KB

File metadata and controls

139 lines (104 loc) · 4.57 KB

CloudSchedulerSource Example

Overview

This sample shows how to Configure CloudSchedulerSource resource for receiving scheduled events from Google Cloud Scheduler.

Prerequisites

  1. Install Knative-GCP.

  2. Create with an App Engine application in your project. Refer to this guide for more details. You can change the APP_ENGINE_LOCATION, but please make sure you also update the spec.location in CloudSchedulerSource

    export APP_ENGINE_LOCATION=us-central
    gcloud app create --region=$APP_ENGINE_LOCATION
  3. Create a Service Account for the Data Plane

  4. Enable the Cloud Scheduler API on your project:

    gcloud services enable cloudscheduler.googleapis.com

Deployment

  1. Create a CloudSchedulerSource

    1. If you are in GKE and using Workload Identity, update serviceAccountName with the Kubernetes service account you created in Create a Service Account for the Data Plane, which is bound to the Pub/Sub enabled Google service account.

    2. If you are using standard Kubernetes secrets, but want to use a non-default one, update secret with your own secret.

    3. By default, the Scheduler will be created in the same project as your GKE cluster. However, if you are managing multiple projects, then you can specify spec.project, which is the Google Cloud Project that the Scheduler is created in.

    kubectl apply --filename cloudschedulersource.yaml
  2. Create a Service that the Scheduler notifications will sink into:

    kubectl apply --filename event-display.yaml

Verify

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:

    kubectl get pods --selector app=event-display

    You should see at least one.

  2. Inspect the logs of the Service:

    kubectl logs --selector app=event-display -c user-container --tail=200

You should see log lines similar to:

☁️  cloudevents.Event
Validation: valid
Context Attributes,
  specversion: 1.0
  type: google.cloud.scheduler.job.v1.executed
  source: //cloudscheduler.googleapis.com/projects/test-project/locations/us-central1/jobs/cre-scheduler-a7155fae-895c-4d11-b555-b2cd5ed97666
  id: 1313918157507406
  time: 2020-06-30T16:21:00.861Z
  dataschema: https://raw.githubusercontent.com/googleapis/google-cloudevents/master/proto/google/events/cloud/scheduler/v1/data.proto
  datacontenttype: application/json
Extensions,
  knativearrivaltime: 2020-06-30T16:21:01.401511767Z
  knsourcetrigger: link0.16512790926262466
  traceparent: 00-37bb197929fc15a684be311da682fce2-4af58d9f16415e4a-00
Data,
  {
    "custom_data": "c2NoZWR1bGVyIGN1c3RvbSBkYXRh" // base64 encoded "scheduler custom data"
  }

Troubleshooting

You may have issues receiving desired CloudEvent. Please use Authentication Mechanism Troubleshooting to check if it is due to an auth problem.

What's Next

  1. For more details on Cloud Pub/Sub formats refer to the Subscriber overview guide.
  2. For integrating with Cloud Pub/Sub, see the PubSub example.
  3. For integrating with Cloud Storage see the Storage example.
  4. For integrating with Cloud Audit Logs see the Cloud Audit Logs example.
  5. For integrating with Cloud Build see the Build example.
  6. For more information about CloudEvents, see the HTTP transport bindings documentation.

Cleaning Up

  1. Delete the CloudSchedulerSource

    kubectl delete -f ./cloudschedulersource.yaml
  2. Delete the Service

    kubectl delete -f ./event-display.yaml