Skip to content

Commit

Permalink
add vmauth EmbeddedIngress sanity check
Browse files Browse the repository at this point in the history
  • Loading branch information
Haleygo committed Nov 23, 2023
1 parent 4ca1b9e commit 9a481f2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
5 changes: 4 additions & 1 deletion api/v1beta1/vmauth_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,16 @@ func (r *VMAuth) SetupWebhookWithManager(mgr ctrl.Manager) error {
var _ webhook.Validator = &VMAuth{}

func (cr *VMAuth) sanityCheck() error {

if cr.Spec.Ingress != nil {
// check ingress
// TlsHosts and TlsSecretName are both needed if one of them is used
ing := cr.Spec.Ingress
if len(ing.TlsHosts) > 0 && ing.TlsSecretName == "" {
return fmt.Errorf("spec.ingress.tlsSecretName cannot be empty with non-empty spec.ingress.tlsHosts")
}
if ing.TlsSecretName != "" && len(ing.TlsHosts) == 0 {
return fmt.Errorf("spec.ingress.tlsHosts cannot be empty with non-empty spec.ingress.tlsSecretName")
}
}
return nil
}
Expand Down
5 changes: 4 additions & 1 deletion api/victoriametrics/v1beta1/vmauth_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,16 @@ func (r *VMAuth) SetupWebhookWithManager(mgr ctrl.Manager) error {
var _ webhook.Validator = &VMAuth{}

func (cr *VMAuth) sanityCheck() error {

if cr.Spec.Ingress != nil {
// check ingress
// TlsHosts and TlsSecretName are both needed if one of them is used
ing := cr.Spec.Ingress
if len(ing.TlsHosts) > 0 && ing.TlsSecretName == "" {
return fmt.Errorf("spec.ingress.tlsSecretName cannot be empty with non-empty spec.ingress.tlsHosts")
}
if ing.TlsSecretName != "" && len(ing.TlsHosts) == 0 {
return fmt.Errorf("spec.ingress.tlsHosts cannot be empty with non-empty spec.ingress.tlsSecretName")
}
}
return nil
}
Expand Down

0 comments on commit 9a481f2

Please sign in to comment.