Skip to content

Commit

Permalink
Fix: DNSPrefix error on existing cluster
Browse files Browse the repository at this point in the history
  • Loading branch information
mihaiandreiratoiu committed Dec 5, 2023
1 parent 0ee7ce5 commit a82e4e8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
3 changes: 2 additions & 1 deletion api/v1beta1/azuremanagedcontrolplane_default.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package v1beta1
import (
"encoding/base64"
"fmt"
"reflect"
"strings"

"golang.org/x/crypto/ssh"
Expand Down Expand Up @@ -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)
}
}
14 changes: 12 additions & 2 deletions api/v1beta1/azuremanagedcontrolplane_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit a82e4e8

Please sign in to comment.