From c341cee232e659b1cea62412678fdb105d3e4796 Mon Sep 17 00:00:00 2001 From: Hans Rakers Date: Thu, 16 May 2024 16:24:30 +0200 Subject: [PATCH] feat: Validate network domain name if set --- api/v1beta3/cloudstackcluster_webhook.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/api/v1beta3/cloudstackcluster_webhook.go b/api/v1beta3/cloudstackcluster_webhook.go index 491defe0..f87de6f0 100644 --- a/api/v1beta3/cloudstackcluster_webhook.go +++ b/api/v1beta3/cloudstackcluster_webhook.go @@ -79,6 +79,12 @@ func (r *CloudStackCluster) ValidateCreate() (admission.Warnings, error) { field.NewPath("spec", "failureDomains", "ACSEndpoint"), "Name and Namespace are required")) } + if fdSpec.Domain != "" { + for _, errMsg := range validation.IsDNS1123Subdomain(fdSpec.Domain) { + errorList = append(errorList, field.Invalid( + field.NewPath("spec", "failureDomains", "domain"), fdSpec.Domain, errMsg)) + } + } } } @@ -155,7 +161,8 @@ func FailureDomainsEqual(fd1, fd2 CloudStackFailureDomainSpec) bool { fd1.Zone.ID == fd2.Zone.ID && fd1.Zone.Network.Name == fd2.Zone.Network.Name && fd1.Zone.Network.ID == fd2.Zone.Network.ID && - fd1.Zone.Network.Type == fd2.Zone.Network.Type + fd1.Zone.Network.Type == fd2.Zone.Network.Type && + fd1.Zone.Network.Domain == fd2.Zone.Network.Domain } // ValidateDelete implements webhook.Validator so a webhook will be registered for the type