Skip to content

Commit e72b348

Browse files
committed
Merge pull request #126 from spectrocloud/PCP-5293
PCP-5293 Upgrade controller-runtime version to v0.20.4
1 parent b5679ce commit e72b348

File tree

8 files changed

+380
-322
lines changed

8 files changed

+380
-322
lines changed

api/v1beta1/azurecluster_webhook.go

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ limitations under the License.
1717
package v1beta1
1818

1919
import (
20+
"context"
21+
"fmt"
2022
"reflect"
2123

2224
apierrors "k8s.io/apimachinery/pkg/api/errors"
@@ -33,27 +35,43 @@ import (
3335
func (c *AzureCluster) SetupWebhookWithManager(mgr ctrl.Manager) error {
3436
return ctrl.NewWebhookManagedBy(mgr).
3537
For(c).
38+
WithDefaulter(c). // registers webhook.CustomDefaulter
39+
WithValidator(c). // registers webhook.CustomValidator
3640
Complete()
3741
}
3842

3943
// +kubebuilder:webhook:verbs=create;update,path=/validate-infrastructure-cluster-x-k8s-io-v1beta1-azurecluster,mutating=false,failurePolicy=fail,matchPolicy=Equivalent,groups=infrastructure.cluster.x-k8s.io,resources=azureclusters,versions=v1beta1,name=validation.azurecluster.infrastructure.cluster.x-k8s.io,sideEffects=None,admissionReviewVersions=v1;v1beta1
4044
// +kubebuilder:webhook:verbs=create;update,path=/mutate-infrastructure-cluster-x-k8s-io-v1beta1-azurecluster,mutating=true,failurePolicy=fail,matchPolicy=Equivalent,groups=infrastructure.cluster.x-k8s.io,resources=azureclusters,versions=v1beta1,name=default.azurecluster.infrastructure.cluster.x-k8s.io,sideEffects=None,admissionReviewVersions=v1;v1beta1
4145

42-
var _ webhook.Validator = &AzureCluster{}
43-
var _ webhook.Defaulter = &AzureCluster{}
46+
var _ webhook.CustomValidator = &AzureCluster{}
47+
var _ webhook.CustomDefaulter = &AzureCluster{}
4448

4549
// Default implements webhook.Defaulter so a webhook will be registered for the type.
46-
func (c *AzureCluster) Default() {
50+
func (c *AzureCluster) Default(ctx context.Context, obj runtime.Object) error {
51+
c, ok := obj.(*AzureCluster)
52+
if !ok {
53+
return fmt.Errorf("expected *AzureCluster, got %T", obj)
54+
}
4755
c.setDefaults()
56+
return nil
4857
}
4958

5059
// ValidateCreate implements webhook.Validator so a webhook will be registered for the type.
51-
func (c *AzureCluster) ValidateCreate() (admission.Warnings, error) {
60+
func (c *AzureCluster) ValidateCreate(ctx context.Context, obj runtime.Object) (warnings admission.Warnings, err error) {
61+
c, ok := obj.(*AzureCluster)
62+
if !ok {
63+
return nil, fmt.Errorf("expected *AzureCluster, got %T", obj)
64+
}
5265
return c.validateCluster(nil)
5366
}
5467

5568
// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type.
56-
func (c *AzureCluster) ValidateUpdate(oldRaw runtime.Object) (admission.Warnings, error) {
69+
func (c *AzureCluster) ValidateUpdate(ctx context.Context, oldRaw runtime.Object, newRaw runtime.Object) (warnings admission.Warnings, err error) {
70+
c, ok := newRaw.(*AzureCluster)
71+
if !ok {
72+
return nil, fmt.Errorf("expected *AzureCluster, got %T", newRaw)
73+
}
74+
5775
var allErrs field.ErrorList
5876
old := oldRaw.(*AzureCluster)
5977

@@ -196,6 +214,6 @@ func (c *AzureCluster) validateSubnetUpdate(old *AzureCluster) field.ErrorList {
196214
}
197215

198216
// ValidateDelete implements webhook.Validator so a webhook will be registered for the type.
199-
func (c *AzureCluster) ValidateDelete() (admission.Warnings, error) {
217+
func (c *AzureCluster) ValidateDelete(ctx context.Context, obj runtime.Object) (warnings admission.Warnings, err error) {
200218
return nil, nil
201219
}

api/v1beta1/azureclusteridentity_webhook.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ limitations under the License.
1717
package v1beta1
1818

1919
import (
20+
"context"
21+
2022
apierrors "k8s.io/apimachinery/pkg/api/errors"
2123
"k8s.io/apimachinery/pkg/runtime"
2224
"k8s.io/apimachinery/pkg/util/validation/field"
@@ -31,20 +33,21 @@ import (
3133
func (c *AzureClusterIdentity) SetupWebhookWithManager(mgr ctrl.Manager) error {
3234
return ctrl.NewWebhookManagedBy(mgr).
3335
For(c).
36+
WithValidator(c). // registers webhook.CustomValidator
3437
Complete()
3538
}
3639

3740
// +kubebuilder:webhook:verbs=create;update,path=/validate-infrastructure-cluster-x-k8s-io-v1beta1-azureclusteridentity,mutating=false,failurePolicy=fail,matchPolicy=Equivalent,groups=infrastructure.cluster.x-k8s.io,resources=azureclusteridentities,versions=v1beta1,name=validation.azureclusteridentity.infrastructure.cluster.x-k8s.io,sideEffects=None,admissionReviewVersions=v1;v1beta1
3841

39-
var _ webhook.Validator = &AzureClusterIdentity{}
42+
var _ webhook.CustomValidator = &AzureClusterIdentity{}
4043

4144
// ValidateCreate implements webhook.Validator so a webhook will be registered for the type.
42-
func (c *AzureClusterIdentity) ValidateCreate() (admission.Warnings, error) {
45+
func (c *AzureClusterIdentity) ValidateCreate(ctx context.Context, obj runtime.Object) (warnings admission.Warnings, err error) {
4346
return c.validateClusterIdentity()
4447
}
4548

4649
// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type.
47-
func (c *AzureClusterIdentity) ValidateUpdate(oldRaw runtime.Object) (admission.Warnings, error) {
50+
func (c *AzureClusterIdentity) ValidateUpdate(ctx context.Context, oldRaw runtime.Object, newRaw runtime.Object) (warnings admission.Warnings, err error) {
4851
var allErrs field.ErrorList
4952
old := oldRaw.(*AzureClusterIdentity)
5053
if err := webhookutils.ValidateImmutable(
@@ -60,6 +63,6 @@ func (c *AzureClusterIdentity) ValidateUpdate(oldRaw runtime.Object) (admission.
6063
}
6164

6265
// ValidateDelete implements webhook.Validator so a webhook will be registered for the type.
63-
func (c *AzureClusterIdentity) ValidateDelete() (admission.Warnings, error) {
66+
func (c *AzureClusterIdentity) ValidateDelete(ctx context.Context, obj runtime.Object) (warnings admission.Warnings, err error) {
6467
return nil, nil
6568
}

api/v1beta1/azureclustertemplate_webhook.go

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ limitations under the License.
1717
package v1beta1
1818

1919
import (
20+
"context"
21+
"fmt"
2022
"reflect"
2123

2224
apierrors "k8s.io/apimachinery/pkg/api/errors"
@@ -34,28 +36,44 @@ const AzureClusterTemplateImmutableMsg = "AzureClusterTemplate spec.template.spe
3436
func (c *AzureClusterTemplate) SetupWebhookWithManager(mgr ctrl.Manager) error {
3537
return ctrl.NewWebhookManagedBy(mgr).
3638
For(c).
39+
WithDefaulter(c). // registers webhook.CustomDefaulter
40+
WithValidator(c). // registers webhook.CustomValidator
3741
Complete()
3842
}
3943

4044
// +kubebuilder:webhook:verbs=create;update,path=/validate-infrastructure-cluster-x-k8s-io-v1beta1-azureclustertemplate,mutating=false,failurePolicy=fail,matchPolicy=Equivalent,groups=infrastructure.cluster.x-k8s.io,resources=azureclustertemplates,versions=v1beta1,name=validation.azureclustertemplate.infrastructure.cluster.x-k8s.io,sideEffects=None,admissionReviewVersions=v1;v1beta1
4145
// +kubebuilder:webhook:verbs=create;update,path=/mutate-infrastructure-cluster-x-k8s-io-v1beta1-azureclustertemplate,mutating=true,failurePolicy=fail,matchPolicy=Equivalent,groups=infrastructure.cluster.x-k8s.io,resources=azureclustertemplates,versions=v1beta1,name=default.azureclustertemplate.infrastructure.cluster.x-k8s.io,sideEffects=None,admissionReviewVersions=v1;v1beta1
4246

43-
var _ webhook.Defaulter = &AzureClusterTemplate{}
47+
var _ webhook.CustomDefaulter = &AzureClusterTemplate{}
4448

4549
// Default implements webhook.Defaulter so a webhook will be registered for the type.
46-
func (c *AzureClusterTemplate) Default() {
50+
func (c *AzureClusterTemplate) Default(ctx context.Context, obj runtime.Object) error {
51+
c, ok := obj.(*AzureClusterTemplate)
52+
if !ok {
53+
return fmt.Errorf("expected *AzureClusterTemplate, got %T", obj)
54+
}
4755
c.setDefaults()
56+
return nil
4857
}
4958

50-
var _ webhook.Validator = &AzureClusterTemplate{}
59+
var _ webhook.CustomValidator = &AzureClusterTemplate{}
5160

5261
// ValidateCreate implements webhook.Validator so a webhook will be registered for the type.
53-
func (c *AzureClusterTemplate) ValidateCreate() (admission.Warnings, error) {
62+
func (c *AzureClusterTemplate) ValidateCreate(ctx context.Context, obj runtime.Object) (warnings admission.Warnings, err error) {
63+
c, ok := obj.(*AzureClusterTemplate)
64+
if !ok {
65+
return nil, fmt.Errorf("expected *AzureClusterTemplate, got %T", obj)
66+
}
5467
return c.validateClusterTemplate()
5568
}
5669

5770
// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type.
58-
func (c *AzureClusterTemplate) ValidateUpdate(oldRaw runtime.Object) (admission.Warnings, error) {
71+
func (c *AzureClusterTemplate) ValidateUpdate(ctx context.Context, oldRaw runtime.Object, newRaw runtime.Object) (warnings admission.Warnings, err error) {
72+
c, ok := newRaw.(*AzureClusterTemplate)
73+
if !ok {
74+
return nil, fmt.Errorf("expected *AzureClusterTemplate, got %T", newRaw)
75+
}
76+
5977
var allErrs field.ErrorList
6078
old := oldRaw.(*AzureClusterTemplate)
6179
if !reflect.DeepEqual(c.Spec.Template.Spec, old.Spec.Template.Spec) {
@@ -71,6 +89,6 @@ func (c *AzureClusterTemplate) ValidateUpdate(oldRaw runtime.Object) (admission.
7189
}
7290

7391
// ValidateDelete implements webhook.Validator so a webhook will be registered for the type.
74-
func (c *AzureClusterTemplate) ValidateDelete() (admission.Warnings, error) {
92+
func (c *AzureClusterTemplate) ValidateDelete(ctx context.Context, obj runtime.Object) (warnings admission.Warnings, err error) {
7593
return nil, nil
7694
}

api/v1beta1/azuremanagedcluster_webhook.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
package v1beta1
1818

1919
import (
20+
"context"
2021
"k8s.io/apimachinery/pkg/runtime"
2122
ctrl "sigs.k8s.io/controller-runtime"
2223
"sigs.k8s.io/controller-runtime/pkg/webhook"
@@ -27,24 +28,25 @@ import (
2728
func (r *AzureManagedCluster) SetupWebhookWithManager(mgr ctrl.Manager) error {
2829
return ctrl.NewWebhookManagedBy(mgr).
2930
For(r).
31+
WithValidator(r). // registers webhook.CustomValidator
3032
Complete()
3133
}
3234

3335
// +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
3436

35-
var _ webhook.Validator = &AzureManagedCluster{}
37+
var _ webhook.CustomValidator = &AzureManagedCluster{}
3638

3739
// ValidateCreate implements webhook.Validator so a webhook will be registered for the type.
38-
func (r *AzureManagedCluster) ValidateCreate() (admission.Warnings, error) {
40+
func (r *AzureManagedCluster) ValidateCreate(ctx context.Context, obj runtime.Object) (warnings admission.Warnings, err error) {
3941
return nil, nil
4042
}
4143

4244
// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type.
43-
func (r *AzureManagedCluster) ValidateUpdate(_ runtime.Object) (admission.Warnings, error) {
45+
func (r *AzureManagedCluster) ValidateUpdate(ctx context.Context, oldObj runtime.Object, newObj runtime.Object) (warnings admission.Warnings, err error) {
4446
return nil, nil
4547
}
4648

4749
// ValidateDelete implements webhook.Validator so a webhook will be registered for the type.
48-
func (r *AzureManagedCluster) ValidateDelete() (admission.Warnings, error) {
50+
func (r *AzureManagedCluster) ValidateDelete(ctx context.Context, obj runtime.Object) (warnings admission.Warnings, err error) {
4951
return nil, nil
5052
}

api/v1beta1/azuremanagedclustertemplate_webhook.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
package v1beta1
1818

1919
import (
20+
"context"
2021
"k8s.io/apimachinery/pkg/runtime"
2122
ctrl "sigs.k8s.io/controller-runtime"
2223
"sigs.k8s.io/controller-runtime/pkg/webhook"
@@ -27,24 +28,25 @@ import (
2728
func (r *AzureManagedClusterTemplate) SetupWebhookWithManager(mgr ctrl.Manager) error {
2829
return ctrl.NewWebhookManagedBy(mgr).
2930
For(r).
31+
WithValidator(r). // registers webhook.CustomValidator
3032
Complete()
3133
}
3234

3335
// +kubebuilder:webhook:verbs=update,path=/validate-infrastructure-cluster-x-k8s-io-v1beta1-azuremanagedclustertemplate,mutating=false,failurePolicy=fail,groups=infrastructure.cluster.x-k8s.io,resources=azuremanagedclustertemplates,versions=v1beta1,name=validation.azuremanagedclustertemplates.infrastructure.cluster.x-k8s.io,sideEffects=None,admissionReviewVersions=v1;v1beta1
3436

35-
var _ webhook.Validator = &AzureManagedClusterTemplate{}
37+
var _ webhook.CustomValidator = &AzureManagedClusterTemplate{}
3638

3739
// ValidateCreate implements webhook.Validator so a webhook will be registered for the type.
38-
func (r *AzureManagedClusterTemplate) ValidateCreate() (admission.Warnings, error) {
40+
func (r *AzureManagedClusterTemplate) ValidateCreate(ctx context.Context, obj runtime.Object) (warnings admission.Warnings, err error) {
3941
return nil, nil
4042
}
4143

4244
// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type.
43-
func (r *AzureManagedClusterTemplate) ValidateUpdate(_ runtime.Object) (admission.Warnings, error) {
45+
func (r *AzureManagedClusterTemplate) ValidateUpdate(ctx context.Context, oldObj runtime.Object, newObj runtime.Object) (warnings admission.Warnings, err error) {
4446
return nil, nil
4547
}
4648

4749
// ValidateDelete implements webhook.Validator so a webhook will be registered for the type.
48-
func (r *AzureManagedClusterTemplate) ValidateDelete() (admission.Warnings, error) {
50+
func (r *AzureManagedClusterTemplate) ValidateDelete(ctx context.Context, obj runtime.Object) (warnings admission.Warnings, err error) {
4951
return nil, nil
5052
}

exp/api/v1beta1/azuremachinepoolmachine_webhook.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ limitations under the License.
1717
package v1beta1
1818

1919
import (
20+
"context"
21+
2022
"github.com/pkg/errors"
2123
"k8s.io/apimachinery/pkg/runtime"
2224
ctrl "sigs.k8s.io/controller-runtime"
@@ -28,20 +30,21 @@ import (
2830
func (ampm *AzureMachinePoolMachine) SetupWebhookWithManager(mgr ctrl.Manager) error {
2931
return ctrl.NewWebhookManagedBy(mgr).
3032
For(ampm).
33+
WithValidator(ampm). // registers webhook.CustomValidator
3134
Complete()
3235
}
3336

3437
// +kubebuilder:webhook:verbs=create;update,path=/validate-infrastructure-cluster-x-k8s-io-v1beta1-azuremachinepoolmachine,mutating=false,failurePolicy=fail,groups=infrastructure.cluster.x-k8s.io,resources=azuremachinepoolmachines,versions=v1beta1,name=azuremachinepoolmachine.kb.io,sideEffects=None,admissionReviewVersions=v1;v1beta1
3538

36-
var _ webhook.Validator = &AzureMachinePoolMachine{}
39+
var _ webhook.CustomValidator = &AzureMachinePoolMachine{}
3740

3841
// ValidateCreate implements webhook.Validator so a webhook will be registered for the type.
39-
func (ampm *AzureMachinePoolMachine) ValidateCreate() (admission.Warnings, error) {
42+
func (ampm *AzureMachinePoolMachine) ValidateCreate(ctx context.Context, obj runtime.Object) (warnings admission.Warnings, err error) {
4043
return nil, nil
4144
}
4245

4346
// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type.
44-
func (ampm *AzureMachinePoolMachine) ValidateUpdate(old runtime.Object) (admission.Warnings, error) {
47+
func (ampm *AzureMachinePoolMachine) ValidateUpdate(ctx context.Context, old runtime.Object, new runtime.Object) (warnings admission.Warnings, err error) {
4548
oldMachine, ok := old.(*AzureMachinePoolMachine)
4649
if !ok {
4750
return nil, errors.New("expected and AzureMachinePoolMachine")
@@ -55,6 +58,6 @@ func (ampm *AzureMachinePoolMachine) ValidateUpdate(old runtime.Object) (admissi
5558
}
5659

5760
// ValidateDelete implements webhook.Validator so a webhook will be registered for the type.
58-
func (ampm *AzureMachinePoolMachine) ValidateDelete() (admission.Warnings, error) {
61+
func (ampm *AzureMachinePoolMachine) ValidateDelete(ctx context.Context, obj runtime.Object) (warnings admission.Warnings, err error) {
5962
return nil, nil
6063
}

0 commit comments

Comments
 (0)