diff --git a/artifacts/flagger/crd.yaml b/artifacts/flagger/crd.yaml index ad4686100..4382929cf 100644 --- a/artifacts/flagger/crd.yaml +++ b/artifacts/flagger/crd.yaml @@ -1077,6 +1077,9 @@ spec: description: URL address of this webhook type: string format: url + retrylimit: + type: integer + description: Number of retry if Rollout hook failed timeout: description: Request timeout for this webhook type: string diff --git a/charts/flagger/crds/crd.yaml b/charts/flagger/crds/crd.yaml index ad4686100..4382929cf 100644 --- a/charts/flagger/crds/crd.yaml +++ b/charts/flagger/crds/crd.yaml @@ -1077,6 +1077,9 @@ spec: description: URL address of this webhook type: string format: url + retrylimit: + type: integer + description: Number of retry if Rollout hook failed timeout: description: Request timeout for this webhook type: string diff --git a/kustomize/base/flagger/crd.yaml b/kustomize/base/flagger/crd.yaml index ad4686100..4382929cf 100644 --- a/kustomize/base/flagger/crd.yaml +++ b/kustomize/base/flagger/crd.yaml @@ -1077,6 +1077,9 @@ spec: description: URL address of this webhook type: string format: url + retrylimit: + type: integer + description: Number of retry if Rollout hook failed timeout: description: Request timeout for this webhook type: string diff --git a/pkg/apis/flagger/v1beta1/canary.go b/pkg/apis/flagger/v1beta1/canary.go index 40d162d1c..d21f70d0d 100644 --- a/pkg/apis/flagger/v1beta1/canary.go +++ b/pkg/apis/flagger/v1beta1/canary.go @@ -390,6 +390,11 @@ type CanaryWebhook struct { // Metadata (key-value pairs) for this webhook // +optional Metadata *map[string]string `json:"metadata,omitempty"` + + // FailureThreshold for rollout hook + // +optional + WebhookRetries int `json:"webhookRetries,omitempty"` + } // CanaryWebhookPayload holds the deployment info and metadata sent to webhooks diff --git a/pkg/controller/scheduler.go b/pkg/controller/scheduler.go index d470d993d..096b9d469 100644 --- a/pkg/controller/scheduler.go +++ b/pkg/controller/scheduler.go @@ -430,6 +430,7 @@ func (c *Controller) advanceCanary(name string, namespace string) { return } } else { + c.runRolloutWebhooks(cd); if ok := c.runAnalysis(cd); !ok { if err := canaryController.SetStatusFailedChecks(cd, cd.Status.FailedChecks+1); err != nil { c.recordEventWarningf(cd, "%v", err) @@ -749,6 +750,22 @@ func (c *Controller) runAnalysis(canary *flaggerv1.Canary) bool { return true } +func (c *Controller) runRolloutWebhooks(canary *flaggerv1.Canary,retryLimit int) bool { + for _, webhook := range canary.GetAnalysis().Webhooks { + if webhook.Type == "" || webhook.Type == flaggerv1.RolloutHook { + if canary.Status.WebhookRetries >= retryLimit { + c.recordEventWarningf(canary, "Retries exceeded limit for webhook %s", webhook.Name) + return false + } + if err := CallWebhook(canary.Name, canary.Namespace, flaggerv1.CanaryPhaseProgressing, webhook); err != nil { + canary.Status.WebhookRetries++ + return false + } + } + } + return true +} + func (c *Controller) shouldSkipAnalysis(canary *flaggerv1.Canary, canaryController canary.Controller, meshRouter router.Interface, scalerReconciler canary.ScalerReconciler, err error, retriable bool) bool { if !canary.SkipAnalysis() { return false