diff --git a/api/v1beta1/azuremanagedcluster_webhook.go b/api/v1beta1/azuremanagedcluster_webhook.go index a6cbd98d43b..0db03ba4544 100644 --- a/api/v1beta1/azuremanagedcluster_webhook.go +++ b/api/v1beta1/azuremanagedcluster_webhook.go @@ -38,7 +38,7 @@ func (r *AzureManagedCluster) SetupWebhookWithManager(mgr ctrl.Manager) error { Complete() } -// +kubebuilder:webhook:verbs=update,path=/validate-infrastructure-cluster-x-k8s-io-v1beta1-azuremanagedcluster,mutating=false,failurePolicy=fail,groups=infrastructure.cluster.x-k8s.io,resources=azuremanagedclusters,versions=v1beta1,name=validation.azuremanagedclusters.infrastructure.cluster.x-k8s.io,sideEffects=None,admissionReviewVersions=v1;v1beta1 +// +kubebuilder:webhook:verbs=create;update,path=/validate-infrastructure-cluster-x-k8s-io-v1beta1-azuremanagedcluster,mutating=false,failurePolicy=fail,groups=infrastructure.cluster.x-k8s.io,resources=azuremanagedclusters,versions=v1beta1,name=validation.azuremanagedclusters.infrastructure.cluster.x-k8s.io,sideEffects=None,admissionReviewVersions=v1;v1beta1 var _ webhook.Validator = &AzureManagedCluster{} diff --git a/api/v1beta1/azuremanagedmachinepool_webhook.go b/api/v1beta1/azuremanagedmachinepool_webhook.go index 7eee9517b2e..52a3531bf38 100644 --- a/api/v1beta1/azuremanagedmachinepool_webhook.go +++ b/api/v1beta1/azuremanagedmachinepool_webhook.go @@ -59,7 +59,7 @@ func (m *AzureManagedMachinePool) Default(client client.Client) { } } -//+kubebuilder:webhook:verbs=update;delete,path=/validate-infrastructure-cluster-x-k8s-io-v1beta1-azuremanagedmachinepool,mutating=false,failurePolicy=fail,matchPolicy=Equivalent,groups=infrastructure.cluster.x-k8s.io,resources=azuremanagedmachinepools,versions=v1beta1,name=validation.azuremanagedmachinepools.infrastructure.cluster.x-k8s.io,sideEffects=None,admissionReviewVersions=v1;v1beta1 +//+kubebuilder:webhook:verbs=create;update;delete,path=/validate-infrastructure-cluster-x-k8s-io-v1beta1-azuremanagedmachinepool,mutating=false,failurePolicy=fail,matchPolicy=Equivalent,groups=infrastructure.cluster.x-k8s.io,resources=azuremanagedmachinepools,versions=v1beta1,name=validation.azuremanagedmachinepools.infrastructure.cluster.x-k8s.io,sideEffects=None,admissionReviewVersions=v1;v1beta1 // ValidateCreate implements webhook.Validator so a webhook will be registered for the type. func (m *AzureManagedMachinePool) ValidateCreate(client client.Client) error { @@ -310,13 +310,12 @@ func (m *AzureManagedMachinePool) validateOSType() error { } func (m *AzureManagedMachinePool) validateName() error { - if m.Spec.OSType != nil && *m.Spec.OSType == WindowsOS { - if len(m.Name) > 6 { - return field.Invalid( - field.NewPath("Name"), - m.Name, - "Windows agent pool name can not be longer than 6 characters.") - } + if m.Spec.OSType != nil && *m.Spec.OSType == WindowsOS && + m.Spec.Name != nil && len(*m.Spec.Name) > 6 { + return field.Invalid( + field.NewPath("Spec", "Name"), + m.Spec.Name, + "Windows agent pool name can not be longer than 6 characters.") } return nil diff --git a/api/v1beta1/azuremanagedmachinepool_webhook_test.go b/api/v1beta1/azuremanagedmachinepool_webhook_test.go index 5970397a4ca..263df698025 100644 --- a/api/v1beta1/azuremanagedmachinepool_webhook_test.go +++ b/api/v1beta1/azuremanagedmachinepool_webhook_test.go @@ -640,10 +640,8 @@ func TestAzureManagedMachinePool_ValidateCreate(t *testing.T) { { name: "Windows clusters with more than 6char names are not allowed", ammp: &AzureManagedMachinePool{ - ObjectMeta: metav1.ObjectMeta{ - Name: "pool0-name-too-long", - }, Spec: AzureManagedMachinePoolSpec{ + Name: pointer.String("pool0-name-too-long"), Mode: "User", OSType: pointer.String(WindowsOS), }, diff --git a/config/webhook/manifests.yaml b/config/webhook/manifests.yaml index 5b81638d0c3..90a8fe4a8c8 100644 --- a/config/webhook/manifests.yaml +++ b/config/webhook/manifests.yaml @@ -290,6 +290,7 @@ webhooks: apiVersions: - v1beta1 operations: + - CREATE - UPDATE resources: - azuremanagedclusters @@ -332,6 +333,7 @@ webhooks: apiVersions: - v1beta1 operations: + - CREATE - UPDATE - DELETE resources: