Canary deployment
Progressively shift traffic to a new Google Cloud Function revision before completing the cutover.
Canary deployment deploys a new function revision without traffic, shifts an initial percentage of traffic to it, then shifts the remaining traffic to complete the cutover. Use this strategy when you want to validate a new revision against live traffic before committing fully.
What you will learn from this topic
Understand how Harness progressively shifts traffic to a new function revision before completing the cutover.
See how the deploy and traffic shift steps pass data to each other, and how Harness handles it if the deployment fails.
Before you begin
A Google Cloud Functions service: Go to Google Cloud Functions services to set up a service with a manifest and artifact source.
A Google Cloud Functions infrastructure definition: Go to Google Cloud Functions infrastructure to connect a Google Cloud account and configure authentication.
Canary strategy step sequence
When you select Canary, Harness adds the following steps to your stage execution:
Google Cloud Function Deploy: Deploys the new function revision with Skip Traffic set to
true, so the revision does not receive traffic yet.Google Cloud Function Traffic Shift Canary: Shifts an initial percentage of traffic, for example
10, to the newly deployed revision, using the function name, revision, and first-deployment flag from the deploy step's output.Google Cloud Function Traffic Shift Final: Shifts the remaining traffic to the new revision, completing the cutover to
100.
On rollback, Harness runs the Google Cloud Function Rollback step inside a Google Cloud Function Canary Rollback step group.
Stage YAML
A minimal canary stage looks like this.
This example runs on a delegate and deploys to every infrastructure definition in the environment:
This example runs on Harness Cloud and deploys to a single, specific infrastructure definition:
Configure the Google Cloud Function Deploy step
For the canary strategy, the deploy step sets Skip Traffic to true so the new revision does not receive traffic until the traffic shift steps run.
Skip Traffic
false
When true, the deployed revision does not receive traffic until a separate traffic shift step runs. Canary sets this to true.
Command Timeout
10m
Maximum time for the step to complete.
Log Level
info
Log verbosity for the step execution.
Configure the Google Cloud Function Traffic Shift Canary step
The canary traffic shift step reads the function name, revision, and first-deployment flag from the deploy step's output, and shifts an initial percentage of traffic to that revision for validation.
Cloud Function Name
${{stage.steps.googleCloudFunctionDeployStep.output.outputVariables.functionName}}
The function to shift traffic for. Automatically resolved from the deploy step output.
First Deployment
${{stage.steps.googleCloudFunctionDeployStep.output.outputVariables.isFirstDeployment}}
Whether this is the first deployment of the function. When true, the step skips the traffic shift. Automatically resolved from the deploy step output.
Target Revision
${{stage.steps.googleCloudFunctionDeployStep.output.outputVariables.revision}}
The revision to shift traffic to. Automatically resolved from the deploy step output.
Target Traffic Percent
—
The percentage of traffic to shift to the target revision. The canary step sets this to an initial value, for example 10.
Command Timeout
10m
Maximum time for the step to complete.
Log Level
info
Log verbosity for the step execution.
Configure the Google Cloud Function Traffic Shift Final step
The final traffic shift step uses the same inputs as the canary traffic shift step, but shifts the remaining traffic to complete the cutover.
Cloud Function Name
${{stage.steps.googleCloudFunctionDeployStep.output.outputVariables.functionName}}
The function to shift traffic for. Automatically resolved from the deploy step output.
First Deployment
${{stage.steps.googleCloudFunctionDeployStep.output.outputVariables.isFirstDeployment}}
Whether this is the first deployment of the function. When true, the step skips the traffic shift. Automatically resolved from the deploy step output.
Target Revision
${{stage.steps.googleCloudFunctionDeployStep.output.outputVariables.revision}}
The revision to shift traffic to. Automatically resolved from the deploy step output.
Target Traffic Percent
—
The percentage of traffic to shift to the target revision. The final step sets this to 100 to complete the cutover.
Command Timeout
10m
Maximum time for the step to complete.
Log Level
info
Log verbosity for the step execution.
Rollback behavior
When the stage failure strategy triggers rollback, the Google Cloud Function Rollback step inside the Google Cloud Function Canary Rollback step group runs automatically.
The rollback step receives the following inputs:
Cloud Function Name
${{rollback.data.FUNCTION_NAME}}
The function to roll back.
Previous Traffic Split
${{rollback.data.ACTIVE_CLOUD_RUN_REVISIONS}}
The revisions that were active before the deployment. Used to restore traffic during rollback.
Rollback behavior differs by deployment history:
Subsequent deployments: Harness restores the previous serving traffic split on the backing Cloud Run service. Previous Traffic Split holds the revision and traffic percentage that were active before the deployment, and the rollback step applies that split back to the service.
First deployment: There is no previous revision to restore traffic to, so Previous Traffic Split has nothing to roll back to.
Next steps
Go to Basic for a single-phase deployment without progressive traffic shifting.
Go to Blue-green for a zero-downtime traffic cutover deployment.
Go to Blank canvas to compose steps manually.
Last updated
Was this helpful?