Skip to content

Commit

Permalink
api/vmalert: fixes validation for vmalert
Browse files Browse the repository at this point in the history
for notifier can be definied url or selector for auto-discovery. This commit fixes regression
  • Loading branch information
f41gh7 committed Nov 11, 2022
1 parent 0b14038 commit a065223
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions api/v1beta1/vmalert_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down
8 changes: 4 additions & 4 deletions api/victoriametrics/v1beta1/vmalert_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down

0 comments on commit a065223

Please sign in to comment.