Skip to content

Latest commit

 

History

History
110 lines (80 loc) · 3.16 KB

File metadata and controls

110 lines (80 loc) · 3.16 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. Note that your project needs to be created with an App Engine application. Refer to this guide for more details.

  2. Create a Pub/Sub enabled Service Account

  3. 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 serviceAccount with the Pub/Sub enabled service account you created in Create a Pub/Sub enabled Service Account.

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

    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

You should see log lines similar to:

☁️  cloudevents.Event
Validation: valid
Context Attributes,
  specversion: 1.0
  type: com.google.cloud.scheduler.job.execute
  source: //cloudscheduler.googleapis.com/projects/knative-gcp/locations/us-east4/schedulers/scheduler-test
  subject: jobs/cre-scheduler-bfc82b00-11fd-42ec-b21a-011dddc2170b
  id: 714614529367848
  time: 2019-08-28T22:29:00.979Z
  datacontenttype: application/octet-stream
Extensions,
  knativecemode: binary
Data,
  my test data

What's Next

  1. For integrating with Cloud Pub/Sub, see the PubSub example.
  2. For integrating with Cloud Storage see the Storage example.
  3. For integrating with Cloud Audit Logs see the Cloud Audit Logs example.
  4. 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