From cb8ab7ff35dad5d01a2d53959ce9a8a5b700933a Mon Sep 17 00:00:00 2001 From: Jon Huhn Date: Thu, 23 Mar 2023 14:34:23 -0500 Subject: [PATCH] add missing create verb to AzureManagedCluster, AzureManagedMachinePool webhooks --- api/v1beta1/azuremanagedcluster_webhook.go | 2 +- api/v1beta1/azuremanagedmachinepool_webhook.go | 15 +++++++-------- .../azuremanagedmachinepool_webhook_test.go | 4 +--- config/webhook/manifests.yaml | 2 ++ 4 files changed, 11 insertions(+), 12 deletions(-) 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 65438dca9fd..e4167cf73c2 100644 --- a/api/v1beta1/azuremanagedmachinepool_webhook.go +++ b/api/v1beta1/azuremanagedmachinepool_webhook.go @@ -81,7 +81,7 @@ func (mw *azureManagedMachinePoolWebhook) Default(ctx context.Context, obj runti return nil } -//+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 (mw *azureManagedMachinePoolWebhook) ValidateCreate(ctx context.Context, obj runtime.Object) error { @@ -347,13 +347,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 2e2d65c6b1a..4bcc5c2c526 100644 --- a/api/v1beta1/azuremanagedmachinepool_webhook_test.go +++ b/api/v1beta1/azuremanagedmachinepool_webhook_test.go @@ -651,10 +651,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: