From a82e4e8f5d47e487c20f65db1e79db32cb8f40cf Mon Sep 17 00:00:00 2001 From: mihaiandreiratoiu Date: Thu, 23 Nov 2023 13:51:23 +0200 Subject: [PATCH] Fix: DNSPrefix error on existing cluster --- api/v1beta1/azuremanagedcontrolplane_default.go | 3 ++- api/v1beta1/azuremanagedcontrolplane_webhook.go | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/api/v1beta1/azuremanagedcontrolplane_default.go b/api/v1beta1/azuremanagedcontrolplane_default.go index f4b0cd4f4c6..b8def0f6322 100644 --- a/api/v1beta1/azuremanagedcontrolplane_default.go +++ b/api/v1beta1/azuremanagedcontrolplane_default.go @@ -19,6 +19,7 @@ package v1beta1 import ( "encoding/base64" "fmt" + "reflect" "strings" "golang.org/x/crypto/ssh" @@ -194,7 +195,7 @@ func (m *AzureManagedControlPlane) setDefaultOIDCIssuerProfile() { } func (m *AzureManagedControlPlane) setDefaultDNSPrefix() { - if m.Spec.DNSPrefix == nil { + if reflect.ValueOf(m.Spec.DNSPrefix).IsZero() { m.Spec.DNSPrefix = ptr.To(m.Name) } } diff --git a/api/v1beta1/azuremanagedcontrolplane_webhook.go b/api/v1beta1/azuremanagedcontrolplane_webhook.go index 1e5cc196caf..3a8c853da88 100644 --- a/api/v1beta1/azuremanagedcontrolplane_webhook.go +++ b/api/v1beta1/azuremanagedcontrolplane_webhook.go @@ -207,10 +207,20 @@ func (mw *azureManagedControlPlaneWebhook) ValidateUpdate(ctx context.Context, o allErrs = append(allErrs, err) } + oldDNSPrefix := old.Spec.DNSPrefix + newDNSPrefix := m.Spec.DNSPrefix + if reflect.ValueOf(oldDNSPrefix).IsZero() { + oldDNSPrefix = ptr.To(old.Name) + } + + if reflect.ValueOf(newDNSPrefix).IsZero() { + newDNSPrefix = ptr.To(m.Name) + } + if err := webhookutils.ValidateImmutable( field.NewPath("Spec", "DNSPrefix"), - m.Spec.DNSPrefix, - old.Spec.DNSPrefix, + oldDNSPrefix, + newDNSPrefix, ); err != nil { allErrs = append(allErrs, err) }