From a06522366a7de4e1685c0d08820a1635ed879ee7 Mon Sep 17 00:00:00 2001 From: f41gh7 Date: Fri, 11 Nov 2022 13:02:33 +0100 Subject: [PATCH] api/vmalert: fixes validation for vmalert for notifier can be definied url or selector for auto-discovery. This commit fixes regression --- api/v1beta1/vmalert_webhook.go | 8 ++++---- api/victoriametrics/v1beta1/vmalert_webhook.go | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/api/v1beta1/vmalert_webhook.go b/api/v1beta1/vmalert_webhook.go index df275ab2..5b58831e 100644 --- a/api/v1beta1/vmalert_webhook.go +++ b/api/v1beta1/vmalert_webhook.go @@ -32,13 +32,13 @@ func (r *VMAlert) sanityCheck() error { } if r.Spec.Notifier != nil { - if r.Spec.Notifier.URL == "" { - return fmt.Errorf("spec.notifier.url cannot be empty") + if r.Spec.Notifier.URL == "" && r.Spec.Notifier.Selector == nil { + return fmt.Errorf("spec.notifier.url and spec.notifier.selector cannot be empty at the same time, provide at least one setting") } } for idx, nt := range r.Spec.Notifiers { - if nt.URL == "" { - return fmt.Errorf("notifier.url at idx: %d cannot be empty", idx) + if nt.URL == "" && nt.Selector == nil { + return fmt.Errorf("notifier.url is empty and selector is not set, provide at least once for spec.notifiers at idx: %d", idx) } } diff --git a/api/victoriametrics/v1beta1/vmalert_webhook.go b/api/victoriametrics/v1beta1/vmalert_webhook.go index df275ab2..9f014430 100644 --- a/api/victoriametrics/v1beta1/vmalert_webhook.go +++ b/api/victoriametrics/v1beta1/vmalert_webhook.go @@ -32,13 +32,13 @@ func (r *VMAlert) sanityCheck() error { } if r.Spec.Notifier != nil { - if r.Spec.Notifier.URL == "" { - return fmt.Errorf("spec.notifier.url cannot be empty") + if r.Spec.Notifier.URL == "" && r.Spec.Notifier.Selector == nil { + return fmt.Errorf("spec.notifier.url and spec.notifier.selector cannot be empty at the same time, provide at least one setting") } } for idx, nt := range r.Spec.Notifiers { - if nt.URL == "" { - return fmt.Errorf("notifier.url at idx: %d cannot be empty", idx) + if nt.URL == "" && nt.Selector == nil { + return fmt.Errorf("notifier.url is empty and selector is not set, provide at least one for spec.notifiers at idx: %d", idx) } }