Skip to content

Commit

Permalink
Merge pull request #3356 from nojnhuh/create-webhooks
Browse files Browse the repository at this point in the history
[release-1.7] add missing create verb to AzureManagedCluster, AzureManagedMachinePool webhooks
  • Loading branch information
k8s-ci-robot authored Mar 24, 2023
2 parents 04e5f2e + 4a05a80 commit 52f03fb
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 12 deletions.
2 changes: 2 additions & 0 deletions config/webhook/manifests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@ webhooks:
apiVersions:
- v1beta1
operations:
- CREATE
- UPDATE
resources:
- azuremanagedclusters
Expand Down Expand Up @@ -374,6 +375,7 @@ webhooks:
apiVersions:
- v1beta1
operations:
- CREATE
- UPDATE
- DELETE
resources:
Expand Down
2 changes: 1 addition & 1 deletion exp/api/v1beta1/azuremanagedcluster_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}

Expand Down
15 changes: 7 additions & 8 deletions exp/api/v1beta1/azuremanagedmachinepool_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,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 {
Expand Down Expand Up @@ -297,13 +297,12 @@ func (m *AzureManagedMachinePool) validateOSType() error {
}

func (m *AzureManagedMachinePool) validateName() error {
if m.Spec.OSType != nil && *m.Spec.OSType == azure.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 == azure.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
Expand Down
4 changes: 1 addition & 3 deletions exp/api/v1beta1/azuremanagedmachinepool_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -619,10 +619,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: to.StringPtr("pool0-name-too-long"),
Mode: "User",
OSType: to.StringPtr(azure.WindowsOS),
},
Expand Down

0 comments on commit 52f03fb

Please sign in to comment.