Skip to content

Commit

Permalink
Add webhook confirm-traffic-increase for manually approving traffic…
Browse files Browse the repository at this point in the history
… increase

Signed-off-by: Mayank Shah <[email protected]>
  • Loading branch information
mayankshah1607 committed Mar 16, 2021
1 parent f2d121a commit a1e84a7
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions artifacts/flagger/crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -940,6 +940,7 @@ spec:
- post-rollout
- event
- rollback
- confirm-traffic-increase
url:
description: URL address of this webhook
type: string
Expand Down
1 change: 1 addition & 0 deletions charts/flagger/crds/crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -940,6 +940,7 @@ spec:
- post-rollout
- event
- rollback
- confirm-traffic-increase
url:
description: URL address of this webhook
type: string
Expand Down
2 changes: 2 additions & 0 deletions pkg/apis/flagger/v1beta1/canary.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions pkg/controller/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,12 @@ func (c *Controller) advanceCanary(name string, namespace string) {

// strategy: Canary progressive traffic increase
if c.nextStepWeight(cd, canaryWeight) > 0 {
// implement ConfirmTrafficPromotionHook only if traffic is not mirrored
if !mirrored {
if promote := c.runConfirmTrafficPromotionHooks(cd); !promote {
return
}
}
c.runCanary(cd, canaryController, meshRouter, mirrored, canaryWeight, primaryWeight, maxWeight)
}

Expand Down
16 changes: 16 additions & 0 deletions pkg/controller/scheduler_hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,22 @@ import (
"github.com/fluxcd/flagger/pkg/canary"
)

func (c *Controller) runConfirmTrafficPromotionHooks(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 promotion approval %s",
canary.Name, canary.Namespace, webhook.Name)
c.alert(canary, "Canary traffic promotion is waiting for approval.", false, flaggerv1.SeverityWarn)
return false
}
c.recordEventInfof(canary, "Confirm-traffic-promotion 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 {
Expand Down

0 comments on commit a1e84a7

Please sign in to comment.