Skip to content

Commit a1e84a7

Browse files
Add webhook confirm-traffic-increase for manually approving traffic increase
Signed-off-by: Mayank Shah <[email protected]>
1 parent f2d121a commit a1e84a7

File tree

5 files changed

+26
-0
lines changed

5 files changed

+26
-0
lines changed

artifacts/flagger/crd.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -940,6 +940,7 @@ spec:
940940
- post-rollout
941941
- event
942942
- rollback
943+
- confirm-traffic-increase
943944
url:
944945
description: URL address of this webhook
945946
type: string

charts/flagger/crds/crd.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -940,6 +940,7 @@ spec:
940940
- post-rollout
941941
- event
942942
- rollback
943+
- confirm-traffic-increase
943944
url:
944945
description: URL address of this webhook
945946
type: string

pkg/apis/flagger/v1beta1/canary.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,8 @@ const (
314314
EventHook HookType = "event"
315315
// RollbackHook rollback canary analysis if webhook returns HTTP 200
316316
RollbackHook HookType = "rollback"
317+
// ConfirmTrafficIncreaseHook increases traffic weight if webhook returns HTTP 200
318+
ConfirmTrafficIncreaseHook = "confirm-traffic-increase"
317319
)
318320

319321
// CanaryWebhook holds the reference to external checks used for canary analysis

pkg/controller/scheduler.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,12 @@ func (c *Controller) advanceCanary(name string, namespace string) {
412412

413413
// strategy: Canary progressive traffic increase
414414
if c.nextStepWeight(cd, canaryWeight) > 0 {
415+
// implement ConfirmTrafficPromotionHook only if traffic is not mirrored
416+
if !mirrored {
417+
if promote := c.runConfirmTrafficPromotionHooks(cd); !promote {
418+
return
419+
}
420+
}
415421
c.runCanary(cd, canaryController, meshRouter, mirrored, canaryWeight, primaryWeight, maxWeight)
416422
}
417423

pkg/controller/scheduler_hooks.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,22 @@ import (
2323
"github.com/fluxcd/flagger/pkg/canary"
2424
)
2525

26+
func (c *Controller) runConfirmTrafficPromotionHooks(canary *flaggerv1.Canary) bool {
27+
for _, webhook := range canary.GetAnalysis().Webhooks {
28+
if webhook.Type == flaggerv1.ConfirmTrafficIncreaseHook {
29+
err := CallWebhook(canary.Name, canary.Namespace, flaggerv1.CanaryPhaseProgressing, webhook)
30+
if err != nil {
31+
c.recordEventWarningf(canary, "Halt %s.%s advancement waiting for traffic promotion approval %s",
32+
canary.Name, canary.Namespace, webhook.Name)
33+
c.alert(canary, "Canary traffic promotion is waiting for approval.", false, flaggerv1.SeverityWarn)
34+
return false
35+
}
36+
c.recordEventInfof(canary, "Confirm-traffic-promotion check %s passed", webhook.Name)
37+
}
38+
}
39+
return true
40+
}
41+
2642
func (c *Controller) runConfirmRolloutHooks(canary *flaggerv1.Canary, canaryController canary.Controller) bool {
2743
for _, webhook := range canary.GetAnalysis().Webhooks {
2844
if webhook.Type == flaggerv1.ConfirmRolloutHook {

0 commit comments

Comments
 (0)