Skip to content

Commit

Permalink
Merge pull request #1431 from fluxcd/suspend
Browse files Browse the repository at this point in the history
Add `spec.suspend` to allow suspending canary
  • Loading branch information
aryan9600 authored May 17, 2023
2 parents 4303f8e + 6384bfb commit 5a6e2d1
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 0 deletions.
7 changes: 7 additions & 0 deletions artifacts/flagger/crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ spec:
- name: Weight
type: string
jsonPath: .status.canaryWeight
- name: Suspended
type: boolean
jsonPath: .spec.suspend
priority: 1
- name: FailedChecks
type: string
jsonPath: .status.failedChecks
Expand Down Expand Up @@ -850,6 +854,9 @@ spec:
revertOnDeletion:
description: Revert mutated resources to original spec on deletion
type: boolean
suspend:
description: Suspend Canary disabling/pausing all canary runs
type: boolean
analysis:
description: Canary analysis for this canary
type: object
Expand Down
7 changes: 7 additions & 0 deletions charts/flagger/crds/crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ spec:
- name: Weight
type: string
jsonPath: .status.canaryWeight
- name: Suspended
type: boolean
jsonPath: .spec.suspend
priority: 1
- name: FailedChecks
type: string
jsonPath: .status.failedChecks
Expand Down Expand Up @@ -850,6 +854,9 @@ spec:
revertOnDeletion:
description: Revert mutated resources to original spec on deletion
type: boolean
suspend:
description: Suspend Canary disabling/pausing all canary runs
type: boolean
analysis:
description: Canary analysis for this canary
type: object
Expand Down
7 changes: 7 additions & 0 deletions docs/gitbook/usage/how-it-works.md
Original file line number Diff line number Diff line change
Expand Up @@ -379,3 +379,10 @@ On each run, Flagger calls the webhooks, checks the metrics and if the failed ch
stops the analysis and rolls back the canary.
If alerting is configured, Flagger will post the analysis result using the alert providers.

## Canary suspend

The `suspend` field can be set to true to suspend the Canary. If a Canary is suspended,
its reconciliation is completely paused. This means that changes to target workloads,
tracked ConfigMaps and Secrets don't trigger a Canary run and changes to resources generated
by Flagger are not corrected. If the Canary was suspended during an active Canary run,
then the run is paused without disturbing the workloads or the traffic weights.
7 changes: 7 additions & 0 deletions kustomize/base/flagger/crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ spec:
- name: Weight
type: string
jsonPath: .status.canaryWeight
- name: Suspended
type: boolean
jsonPath: .spec.suspend
priority: 1
- name: FailedChecks
type: string
jsonPath: .status.failedChecks
Expand Down Expand Up @@ -850,6 +854,9 @@ spec:
revertOnDeletion:
description: Revert mutated resources to original spec on deletion
type: boolean
suspend:
description: Suspend Canary disabling/pausing all canary runs
type: boolean
analysis:
description: Canary analysis for this canary
type: object
Expand Down
6 changes: 6 additions & 0 deletions pkg/apis/flagger/v1beta1/canary.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,12 @@ type CanarySpec struct {
// revert canary mutation on deletion of canary resource
// +optional
RevertOnDeletion bool `json:"revertOnDeletion,omitempty"`

// Suspend, if set to true will suspend the Canary, disabling any canary runs
// regardless of any changes to its target, services, etc. Note that if the
// Canary is suspended during an analysis, its paused until the Canary is unsuspended.
// +optional
Suspend bool `json:"suspend,omitempty"`
}

// CanaryService defines how ClusterIP services, service mesh or ingress routing objects are generated
Expand Down
9 changes: 9 additions & 0 deletions pkg/controller/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,14 @@ func (c *Controller) advanceCanary(name string, namespace string) {
return
}

if cd.Spec.Suspend {
msg := "skipping canary run as object is suspended"
c.logger.With("canary", fmt.Sprintf("%s.%s", name, namespace)).
Debug(msg)
c.recordEventInfof(cd, msg)
return
}

// override the global provider if one is specified in the canary spec
provider := c.meshProvider
if cd.Spec.Provider != "" {
Expand All @@ -172,6 +180,7 @@ func (c *Controller) advanceCanary(name string, namespace string) {

// init controller based on target kind
canaryController := c.canaryFactory.Controller(cd.Spec.TargetRef.Kind)

labelSelector, labelValue, ports, err := canaryController.GetMetadata(cd)
if err != nil {
c.recordEventWarningf(cd, "%v", err)
Expand Down

0 comments on commit 5a6e2d1

Please sign in to comment.