Skip to content

Commit 48a7a57

Browse files
authored
Merge pull request #3352 from nojnhuh/create-webhooks
add missing create verb to AzureManagedCluster, AzureManagedMachinePool webhooks
2 parents b9bc235 + cb8ab7f commit 48a7a57

File tree

4 files changed

+11
-12
lines changed

4 files changed

+11
-12
lines changed

api/v1beta1/azuremanagedcluster_webhook.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func (r *AzureManagedCluster) SetupWebhookWithManager(mgr ctrl.Manager) error {
3838
Complete()
3939
}
4040

41-
// +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
41+
// +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
4242

4343
var _ webhook.Validator = &AzureManagedCluster{}
4444

api/v1beta1/azuremanagedmachinepool_webhook.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ func (mw *azureManagedMachinePoolWebhook) Default(ctx context.Context, obj runti
8181
return nil
8282
}
8383

84-
//+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
84+
//+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
8585

8686
// ValidateCreate implements webhook.Validator so a webhook will be registered for the type.
8787
func (mw *azureManagedMachinePoolWebhook) ValidateCreate(ctx context.Context, obj runtime.Object) error {
@@ -347,13 +347,12 @@ func (m *AzureManagedMachinePool) validateOSType() error {
347347
}
348348

349349
func (m *AzureManagedMachinePool) validateName() error {
350-
if m.Spec.OSType != nil && *m.Spec.OSType == WindowsOS {
351-
if len(m.Name) > 6 {
352-
return field.Invalid(
353-
field.NewPath("Name"),
354-
m.Name,
355-
"Windows agent pool name can not be longer than 6 characters.")
356-
}
350+
if m.Spec.OSType != nil && *m.Spec.OSType == WindowsOS &&
351+
m.Spec.Name != nil && len(*m.Spec.Name) > 6 {
352+
return field.Invalid(
353+
field.NewPath("Spec", "Name"),
354+
m.Spec.Name,
355+
"Windows agent pool name can not be longer than 6 characters.")
357356
}
358357

359358
return nil

api/v1beta1/azuremanagedmachinepool_webhook_test.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -651,10 +651,8 @@ func TestAzureManagedMachinePool_ValidateCreate(t *testing.T) {
651651
{
652652
name: "Windows clusters with more than 6char names are not allowed",
653653
ammp: &AzureManagedMachinePool{
654-
ObjectMeta: metav1.ObjectMeta{
655-
Name: "pool0-name-too-long",
656-
},
657654
Spec: AzureManagedMachinePoolSpec{
655+
Name: pointer.String("pool0-name-too-long"),
658656
Mode: "User",
659657
OSType: pointer.String(WindowsOS),
660658
},

config/webhook/manifests.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,7 @@ webhooks:
290290
apiVersions:
291291
- v1beta1
292292
operations:
293+
- CREATE
293294
- UPDATE
294295
resources:
295296
- azuremanagedclusters
@@ -332,6 +333,7 @@ webhooks:
332333
apiVersions:
333334
- v1beta1
334335
operations:
336+
- CREATE
335337
- UPDATE
336338
- DELETE
337339
resources:

0 commit comments

Comments
 (0)