Skip to content

Commit 52f03fb

Browse files
authored
Merge pull request #3356 from nojnhuh/create-webhooks
[release-1.7] add missing create verb to AzureManagedCluster, AzureManagedMachinePool webhooks
2 parents 04e5f2e + 4a05a80 commit 52f03fb

File tree

4 files changed

+11
-12
lines changed

4 files changed

+11
-12
lines changed

config/webhook/manifests.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,7 @@ webhooks:
332332
apiVersions:
333333
- v1beta1
334334
operations:
335+
- CREATE
335336
- UPDATE
336337
resources:
337338
- azuremanagedclusters
@@ -374,6 +375,7 @@ webhooks:
374375
apiVersions:
375376
- v1beta1
376377
operations:
378+
- CREATE
377379
- UPDATE
378380
- DELETE
379381
resources:

exp/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

exp/api/v1beta1/azuremanagedmachinepool_webhook.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func (m *AzureManagedMachinePool) Default(client client.Client) {
5858
}
5959
}
6060

61-
//+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
61+
//+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
6262

6363
// ValidateCreate implements webhook.Validator so a webhook will be registered for the type.
6464
func (m *AzureManagedMachinePool) ValidateCreate(client client.Client) error {
@@ -297,13 +297,12 @@ func (m *AzureManagedMachinePool) validateOSType() error {
297297
}
298298

299299
func (m *AzureManagedMachinePool) validateName() error {
300-
if m.Spec.OSType != nil && *m.Spec.OSType == azure.WindowsOS {
301-
if len(m.Name) > 6 {
302-
return field.Invalid(
303-
field.NewPath("Name"),
304-
m.Name,
305-
"Windows agent pool name can not be longer than 6 characters.")
306-
}
300+
if m.Spec.OSType != nil && *m.Spec.OSType == azure.WindowsOS &&
301+
m.Spec.Name != nil && len(*m.Spec.Name) > 6 {
302+
return field.Invalid(
303+
field.NewPath("Spec", "Name"),
304+
m.Spec.Name,
305+
"Windows agent pool name can not be longer than 6 characters.")
307306
}
308307

309308
return nil

exp/api/v1beta1/azuremanagedmachinepool_webhook_test.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -619,10 +619,8 @@ func TestAzureManagedMachinePool_ValidateCreate(t *testing.T) {
619619
{
620620
name: "Windows clusters with more than 6char names are not allowed",
621621
ammp: &AzureManagedMachinePool{
622-
ObjectMeta: metav1.ObjectMeta{
623-
Name: "pool0-name-too-long",
624-
},
625622
Spec: AzureManagedMachinePoolSpec{
623+
Name: to.StringPtr("pool0-name-too-long"),
626624
Mode: "User",
627625
OSType: to.StringPtr(azure.WindowsOS),
628626
},

0 commit comments

Comments
 (0)