For the complete documentation index, see llms.txt. This page is also available as Markdown.

Google Cloud Run Traffic Shift

Route traffic to a specific Cloud Run revision using the Google Cloud Run Traffic Shift step.

The Google Cloud Run Traffic Shift step routes traffic to one or more Cloud Run revisions without redeploying. Use it after a Deploy step in a canary stage to gradually shift traffic to the new revision, and again to promote to 100% once validated.

What you will learn

  • How to configure the Metadata field to define a traffic distribution across Cloud Run revisions.

  • How to use LATEST to refer to the most recently deployed revision versus a named revision.

  • What the step outputs after a traffic shift and how to reference them in subsequent steps.

  • The gcloud command the step runs to apply the traffic distribution.


Before you begin

  • A Google Cloud Run Deploy step earlier in the same stage execution, which creates the new revision the Traffic Shift targets.

  • A Google Cloud Run infrastructure with a GCP connector and region. Go to Google Cloud Run infrastructure.


Step YAML

Route all traffic to the latest revision:

- name: Google Cloud Run Traffic Shift
  id: googleCloudRunTrafficShiftStep
  template:
    uses: googleCloudRunTrafficShiftStep
    with:
      metadata: '{"status":{"traffic":[{"revisionName":"LATEST","percent":100}]}}'

Split traffic 50% to the stable revision and 50% to the new revision:


Configure the step

The following fields appear on the Traffic Shift step. The Metadata field is the only required input; infrastructure fields are resolved from the stage context.

Metadata

The Metadata field defines the target traffic distribution as a JSON object. Harness passes this directly to gcloud run services update-traffic.

Field
Default value
Description

Metadata

{"status":{"traffic":[{"revisionName":"LATEST","percent":100}]}}

JSON object defining the target traffic split across revisions. Use LATEST to refer to the most recently deployed revision, or specify a revision name to pin to a specific revision.

To route 20% canary and 80% stable:

Infrastructure configuration

Field
Default value
Description

GCP Connector

Infrastructure connector

The GCP connector for authentication. Defaults to the connector in the infrastructure definition.

GCP Region

${{infra.region}}

The Cloud Run service region.

GCP Project

${{infra.project}}

The GCP project.

Command Timeout

10m

Maximum time the step is allowed to run.

Log Level

info

Log verbosity for the step.


Step outputs

Output key
Description

SERVICE

The Cloud Run service name.

REVISION_METADATA

The post-shift traffic state, saved as a JSON string.

INSTANCES

Instance count reported by Google Cloud Monitoring after the shift.

DEPLOYMENT_METADATA

Full deployment metadata for Harness instance tracking.


Advanced settings

  • Timeout duration: Maximum time the step is allowed to run before being terminated.

  • On failure: Define what happens if the step fails: retry, mark as success, or abort.

  • Strategy: Configure a looping strategy to run this step over a list of values.

  • Conditional execution: Run this step only when a specified condition is true.


How it runs

When the Traffic Shift step executes, the following sequence occurs:

  1. Authenticates with GCP using the configured connector. Runs gcloud auth activate-service-account --key-file sa_key.json for Service Account auth, or identifies the active account for Inherit from Delegate.

  2. Configures the gcloud environment: sets project and region.

  3. Saves SERVICE to step output.

  4. Runs gcloud run services update-traffic <service> --to-revisions=<revision>=<percent>[,<revision>=<percent>] using the distribution from the Metadata field. For a 50/50 canary shift the command is:

    Cloud Run confirms the result, for example: 50% my-svc-00003-abc / 50% LATEST (currently my-svc-00004-xyz).

  5. Runs gcloud run services describe <service> --format json to capture the post-shift traffic state.

  6. Saves the post-shift REVISION_METADATA to step output. For example:

  7. Performs instance sync using the Google Cloud Monitoring SDK. If data is found, waits an additional 60 seconds for a stable read.

  8. Publishes INSTANCES and DEPLOYMENT_METADATA to step output.

No Prepare Rollback step

There is no Prepare Rollback step. The Deploy step saves rollback data automatically. The Rollback step uses the state saved by the last successful deployment of the stage to restore traffic.


Next steps

Last updated

Was this helpful?