diff --git a/artifacts/flagger/crd.yaml b/artifacts/flagger/crd.yaml index 41c7ff87..6d3b918e 100644 --- a/artifacts/flagger/crd.yaml +++ b/artifacts/flagger/crd.yaml @@ -940,6 +940,7 @@ spec: - post-rollout - event - rollback + - confirm-traffic-increase url: description: URL address of this webhook type: string diff --git a/charts/flagger/crds/crd.yaml b/charts/flagger/crds/crd.yaml index 41c7ff87..6d3b918e 100644 --- a/charts/flagger/crds/crd.yaml +++ b/charts/flagger/crds/crd.yaml @@ -940,6 +940,7 @@ spec: - post-rollout - event - rollback + - confirm-traffic-increase url: description: URL address of this webhook type: string diff --git a/pkg/apis/flagger/v1beta1/canary.go b/pkg/apis/flagger/v1beta1/canary.go index 60644e66..a660095b 100644 --- a/pkg/apis/flagger/v1beta1/canary.go +++ b/pkg/apis/flagger/v1beta1/canary.go @@ -314,6 +314,8 @@ const ( EventHook HookType = "event" // RollbackHook rollback canary analysis if webhook returns HTTP 200 RollbackHook HookType = "rollback" + // ConfirmTrafficIncreaseHook increases traffic weight if webhook returns HTTP 200 + ConfirmTrafficIncreaseHook = "confirm-traffic-increase" ) // CanaryWebhook holds the reference to external checks used for canary analysis diff --git a/pkg/controller/scheduler.go b/pkg/controller/scheduler.go index 36b8759a..6537983a 100644 --- a/pkg/controller/scheduler.go +++ b/pkg/controller/scheduler.go @@ -412,6 +412,12 @@ func (c *Controller) advanceCanary(name string, namespace string) { // strategy: Canary progressive traffic increase if c.nextStepWeight(cd, canaryWeight) > 0 { + // run hook only if traffic is not mirrored + if !mirrored { + if promote := c.runConfirmTrafficIncreaseHooks(cd); !promote { + return + } + } c.runCanary(cd, canaryController, meshRouter, mirrored, canaryWeight, primaryWeight, maxWeight) } diff --git a/pkg/controller/scheduler_hooks.go b/pkg/controller/scheduler_hooks.go index d535cdd9..cb551630 100644 --- a/pkg/controller/scheduler_hooks.go +++ b/pkg/controller/scheduler_hooks.go @@ -23,6 +23,22 @@ import ( "github.com/fluxcd/flagger/pkg/canary" ) +func (c *Controller) runConfirmTrafficIncreaseHooks(canary *flaggerv1.Canary) bool { + for _, webhook := range canary.GetAnalysis().Webhooks { + if webhook.Type == flaggerv1.ConfirmTrafficIncreaseHook { + err := CallWebhook(canary.Name, canary.Namespace, flaggerv1.CanaryPhaseProgressing, webhook) + if err != nil { + c.recordEventWarningf(canary, "Halt %s.%s advancement waiting for traffic increase approval %s", + canary.Name, canary.Namespace, webhook.Name) + c.alert(canary, "Canary traffic increase is waiting for approval.", false, flaggerv1.SeverityWarn) + return false + } + c.recordEventInfof(canary, "Confirm-traffic-increase check %s passed", webhook.Name) + } + } + return true +} + func (c *Controller) runConfirmRolloutHooks(canary *flaggerv1.Canary, canaryController canary.Controller) bool { for _, webhook := range canary.GetAnalysis().Webhooks { if webhook.Type == flaggerv1.ConfirmRolloutHook {