Skip to content

Commit 14cb33a

Browse files
committed
Use k8s 1.32 client libs
Signed-off-by: Tamal Saha <[email protected]>
1 parent a500b0c commit 14cb33a

File tree

8,037 files changed

+3563426
-287
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

8,037 files changed

+3563426
-287
lines changed

api/v1beta1/gcpcluster_webhook.go

Lines changed: 24 additions & 16 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,36 +35,44 @@ var clusterlog = logf.Log.WithName("gcpcluster-resource")
3335

3436
// SetupWebhookWithManager sets up and registers the webhook with the manager.
3537
func (c *GCPCluster) SetupWebhookWithManager(mgr ctrl.Manager) error {
38+
w := new(gcpClusterWebhook)
3639
return ctrl.NewWebhookManagedBy(mgr).
3740
For(c).
41+
WithValidator(w).
42+
WithDefaulter(w).
3843
Complete()
3944
}
4045

4146
// +kubebuilder:webhook:verbs=create;update,path=/validate-infrastructure-cluster-x-k8s-io-v1beta1-gcpcluster,mutating=false,failurePolicy=fail,matchPolicy=Equivalent,groups=infrastructure.cluster.x-k8s.io,resources=gcpclusters,versions=v1beta1,name=validation.gcpcluster.infrastructure.cluster.x-k8s.io,sideEffects=None,admissionReviewVersions=v1beta1
4247
// +kubebuilder:webhook:verbs=create;update,path=/mutate-infrastructure-cluster-x-k8s-io-v1beta1-gcpcluster,mutating=true,failurePolicy=fail,matchPolicy=Equivalent,groups=infrastructure.cluster.x-k8s.io,resources=gcpclusters,versions=v1beta1,name=default.gcpcluster.infrastructure.cluster.x-k8s.io,sideEffects=None,admissionReviewVersions=v1beta1
4348

49+
type gcpClusterWebhook struct{}
50+
4451
var (
45-
_ webhook.Validator = &GCPCluster{}
46-
_ webhook.Defaulter = &GCPCluster{}
52+
_ webhook.CustomValidator = &gcpClusterWebhook{}
53+
_ webhook.CustomDefaulter = &gcpClusterWebhook{}
4754
)
4855

49-
// Default implements webhook.Defaulter so a webhook will be registered for the type.
50-
func (c *GCPCluster) Default() {
51-
clusterlog.Info("default", "name", c.Name)
56+
// Default implements webhook.CustomDefaulter so a webhook will be registered for the type.
57+
func (_ *gcpClusterWebhook) Default(_ context.Context, _ runtime.Object) error {
58+
return nil
5259
}
5360

54-
// ValidateCreate implements webhook.Validator so a webhook will be registered for the type.
55-
func (c *GCPCluster) ValidateCreate() (admission.Warnings, error) {
56-
clusterlog.Info("validate create", "name", c.Name)
57-
61+
// ValidateCreate implements webhook.CustomValidator so a webhook will be registered for the type.
62+
func (_ *gcpClusterWebhook) ValidateCreate(_ context.Context, _ runtime.Object) (admission.Warnings, error) {
5863
return nil, nil
5964
}
6065

61-
// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type.
62-
func (c *GCPCluster) ValidateUpdate(oldRaw runtime.Object) (admission.Warnings, error) {
66+
// ValidateUpdate implements webhook.CustomValidator so a webhook will be registered for the type.
67+
func (_ *gcpClusterWebhook) ValidateUpdate(_ context.Context, oldObj, newObj runtime.Object) (admission.Warnings, error) {
68+
c, ok := newObj.(*GCPCluster)
69+
if !ok {
70+
return nil, fmt.Errorf("expected an GCPCluster object but got %T", c)
71+
}
72+
6373
clusterlog.Info("validate update", "name", c.Name)
6474
var allErrs field.ErrorList
65-
old := oldRaw.(*GCPCluster)
75+
old := oldObj.(*GCPCluster)
6676

6777
if !reflect.DeepEqual(c.Spec.Project, old.Spec.Project) {
6878
allErrs = append(allErrs,
@@ -113,9 +123,7 @@ func (c *GCPCluster) ValidateUpdate(oldRaw runtime.Object) (admission.Warnings,
113123
return nil, apierrors.NewInvalid(GroupVersion.WithKind("GCPCluster").GroupKind(), c.Name, allErrs)
114124
}
115125

116-
// ValidateDelete implements webhook.Validator so a webhook will be registered for the type.
117-
func (c *GCPCluster) ValidateDelete() (admission.Warnings, error) {
118-
clusterlog.Info("validate delete", "name", c.Name)
119-
126+
// ValidateDelete implements webhook.CustomValidator so a webhook will be registered for the type.
127+
func (_ *gcpClusterWebhook) ValidateDelete(_ context.Context, _ runtime.Object) (admission.Warnings, error) {
120128
return nil, nil
121129
}

api/v1beta1/gcpclustertemplate_webhook.go

Lines changed: 26 additions & 17 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
"fmt"
2122
"reflect"
2223

@@ -32,35 +33,44 @@ import (
3233
var gcpclustertemplatelog = logf.Log.WithName("gcpclustertemplate-resource")
3334

3435
func (r *GCPClusterTemplate) SetupWebhookWithManager(mgr ctrl.Manager) error {
36+
w := new(gcpClusterTemplateWebhook)
3537
return ctrl.NewWebhookManagedBy(mgr).
3638
For(r).
39+
WithValidator(w).
40+
WithDefaulter(w).
3741
Complete()
3842
}
3943

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

43-
var _ webhook.Defaulter = &GCPClusterTemplate{}
47+
type gcpClusterTemplateWebhook struct{}
4448

45-
// Default implements webhook.Defaulter so a webhook will be registered for the type.
46-
func (r *GCPClusterTemplate) Default() {
47-
gcpclustertemplatelog.Info("default", "name", r.Name)
48-
}
49-
50-
var _ webhook.Validator = &GCPClusterTemplate{}
49+
var (
50+
_ webhook.CustomDefaulter = &gcpClusterTemplateWebhook{}
51+
_ webhook.CustomValidator = &gcpClusterTemplateWebhook{}
52+
)
5153

52-
// ValidateCreate implements webhook.Validator so a webhook will be registered for the type.
53-
func (r *GCPClusterTemplate) ValidateCreate() (admission.Warnings, error) {
54-
gcpclustertemplatelog.Info("validate create", "name", r.Name)
54+
// Default implements webhook.CustomDefaulter so a webhook will be registered for the type.
55+
func (_ *gcpClusterTemplateWebhook) Default(_ context.Context, _ runtime.Object) error {
56+
return nil
57+
}
5558

59+
// ValidateCreate implements webhook.CustomValidator so a webhook will be registered for the type.
60+
func (_ *gcpClusterTemplateWebhook) ValidateCreate(_ context.Context, _ runtime.Object) (admission.Warnings, error) {
5661
return nil, nil
5762
}
5863

59-
// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type.
60-
func (r *GCPClusterTemplate) ValidateUpdate(oldRaw runtime.Object) (admission.Warnings, error) {
61-
old, ok := oldRaw.(*GCPClusterTemplate)
64+
// ValidateUpdate implements webhook.CustomValidator so a webhook will be registered for the type.
65+
func (_ *gcpClusterTemplateWebhook) ValidateUpdate(_ context.Context, oldObj, newObj runtime.Object) (admission.Warnings, error) {
66+
r, ok := newObj.(*GCPClusterTemplate)
67+
if !ok {
68+
return nil, fmt.Errorf("expected an GCPClusterTemplate object but got %T", r)
69+
}
70+
71+
old, ok := oldObj.(*GCPClusterTemplate)
6272
if !ok {
63-
return nil, apierrors.NewBadRequest(fmt.Sprintf("expected an GCPClusterTemplate but got a %T", oldRaw))
73+
return nil, apierrors.NewBadRequest(fmt.Sprintf("expected an GCPClusterTemplate but got a %T", oldObj))
6474
}
6575

6676
if !reflect.DeepEqual(r.Spec, old.Spec) {
@@ -69,8 +79,7 @@ func (r *GCPClusterTemplate) ValidateUpdate(oldRaw runtime.Object) (admission.Wa
6979
return nil, nil
7080
}
7181

72-
// ValidateDelete implements webhook.Validator so a webhook will be registered for the type.
73-
func (r *GCPClusterTemplate) ValidateDelete() (admission.Warnings, error) {
74-
gcpclustertemplatelog.Info("validate delete", "name", r.Name)
82+
// ValidateDelete implements webhook.CustomValidator so a webhook will be registered for the type.
83+
func (_ *gcpClusterTemplateWebhook) ValidateDelete(_ context.Context, _ runtime.Object) (admission.Warnings, error) {
7584
return nil, nil
7685
}

api/v1beta1/gcpmachine_webhook.go

Lines changed: 26 additions & 9 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
"fmt"
2122
"reflect"
2223
"strings"
@@ -37,18 +38,31 @@ import (
3738
var _ = logf.Log.WithName("gcpmachine-resource")
3839

3940
func (m *GCPMachine) SetupWebhookWithManager(mgr ctrl.Manager) error {
41+
w := new(gcpMachineWebhook)
4042
return ctrl.NewWebhookManagedBy(mgr).
4143
For(m).
44+
WithValidator(w).
45+
WithDefaulter(w).
4246
Complete()
4347
}
4448

4549
// +kubebuilder:webhook:verbs=create;update,path=/validate-infrastructure-cluster-x-k8s-io-v1beta1-gcpmachine,mutating=false,failurePolicy=fail,matchPolicy=Equivalent,groups=infrastructure.cluster.x-k8s.io,resources=gcpmachines,versions=v1beta1,name=validation.gcpmachine.infrastructure.cluster.x-k8s.io,sideEffects=None,admissionReviewVersions=v1beta1
4650
// +kubebuilder:webhook:verbs=create;update,path=/mutate-infrastructure-cluster-x-k8s-io-v1beta1-gcpmachine,mutating=true,failurePolicy=fail,matchPolicy=Equivalent,groups=infrastructure.cluster.x-k8s.io,resources=gcpmachines,versions=v1beta1,name=default.gcpmachine.infrastructure.cluster.x-k8s.io,sideEffects=None,admissionReviewVersions=v1beta1
4751

48-
var _ webhook.Validator = &GCPMachine{}
52+
type gcpMachineWebhook struct{}
53+
54+
var (
55+
_ webhook.CustomValidator = &gcpMachineWebhook{}
56+
_ webhook.CustomDefaulter = &gcpMachineWebhook{}
57+
)
4958

5059
// ValidateCreate implements webhook.Validator so a webhook will be registered for the type.
51-
func (m *GCPMachine) ValidateCreate() (admission.Warnings, error) {
60+
func (_ *gcpMachineWebhook) ValidateCreate(_ context.Context, obj runtime.Object) (admission.Warnings, error) {
61+
m, ok := obj.(*GCPMachine)
62+
if !ok {
63+
return nil, fmt.Errorf("expected an GCPMachine object but got %T", m)
64+
}
65+
5266
clusterlog.Info("validate create", "name", m.Name)
5367

5468
if err := validateConfidentialCompute(m.Spec); err != nil {
@@ -58,14 +72,19 @@ func (m *GCPMachine) ValidateCreate() (admission.Warnings, error) {
5872
}
5973

6074
// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type.
61-
func (m *GCPMachine) ValidateUpdate(old runtime.Object) (admission.Warnings, error) {
75+
func (_ *gcpMachineWebhook) ValidateUpdate(_ context.Context, oldObj, newObj runtime.Object) (admission.Warnings, error) {
76+
m, ok := newObj.(*GCPMachine)
77+
if !ok {
78+
return nil, fmt.Errorf("expected an GCPMachine object but got %T", m)
79+
}
80+
6281
newGCPMachine, err := runtime.DefaultUnstructuredConverter.ToUnstructured(m)
6382
if err != nil {
6483
return nil, apierrors.NewInvalid(GroupVersion.WithKind("GCPMachine").GroupKind(), m.Name, field.ErrorList{
6584
field.InternalError(nil, errors.Wrap(err, "failed to convert new GCPMachine to unstructured object")),
6685
})
6786
}
68-
oldGCPMachine, err := runtime.DefaultUnstructuredConverter.ToUnstructured(old)
87+
oldGCPMachine, err := runtime.DefaultUnstructuredConverter.ToUnstructured(oldObj)
6988
if err != nil {
7089
return nil, apierrors.NewInvalid(GroupVersion.WithKind("GCPMachine").GroupKind(), m.Name, field.ErrorList{
7190
field.InternalError(nil, errors.Wrap(err, "failed to convert old GCPMachine to unstructured object")),
@@ -97,15 +116,13 @@ func (m *GCPMachine) ValidateUpdate(old runtime.Object) (admission.Warnings, err
97116
}
98117

99118
// ValidateDelete implements webhook.Validator so a webhook will be registered for the type.
100-
func (m *GCPMachine) ValidateDelete() (admission.Warnings, error) {
101-
clusterlog.Info("validate delete", "name", m.Name)
102-
119+
func (_ *gcpMachineWebhook) ValidateDelete(_ context.Context, _ runtime.Object) (admission.Warnings, error) {
103120
return nil, nil
104121
}
105122

106123
// Default implements webhookutil.defaulter so a webhook will be registered for the type.
107-
func (m *GCPMachine) Default() {
108-
clusterlog.Info("default", "name", m.Name)
124+
func (_ *gcpMachineWebhook) Default(_ context.Context, _ runtime.Object) error {
125+
return nil
109126
}
110127

111128
func validateConfidentialCompute(spec GCPMachineSpec) error {

api/v1beta1/gcpmachinetemplate_webhook.go

Lines changed: 27 additions & 9 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
"github.com/pkg/errors"
@@ -36,29 +38,47 @@ import (
3638
var _ = logf.Log.WithName("gcpmachinetemplate-resource")
3739

3840
func (r *GCPMachineTemplate) SetupWebhookWithManager(mgr ctrl.Manager) error {
41+
w := new(gcpMachineTemplateWebhook)
3942
return ctrl.NewWebhookManagedBy(mgr).
4043
For(r).
44+
WithValidator(w).
45+
WithDefaulter(w).
4146
Complete()
4247
}
4348

44-
var _ webhook.Validator = &GCPMachineTemplate{}
49+
type gcpMachineTemplateWebhook struct{}
50+
51+
var (
52+
_ webhook.CustomValidator = &gcpMachineTemplateWebhook{}
53+
_ webhook.CustomDefaulter = &gcpMachineTemplateWebhook{}
54+
)
4555

4656
// ValidateCreate implements webhook.Validator so a webhook will be registered for the type.
47-
func (r *GCPMachineTemplate) ValidateCreate() (admission.Warnings, error) {
57+
func (_ *gcpMachineTemplateWebhook) ValidateCreate(_ context.Context, obj runtime.Object) (admission.Warnings, error) {
58+
r, ok := obj.(*GCPMachineTemplate)
59+
if !ok {
60+
return nil, fmt.Errorf("expected an GCPMachineTemplate object but got %T", r)
61+
}
62+
4863
clusterlog.Info("validate create", "name", r.Name)
4964

5065
return nil, validateConfidentialCompute(r.Spec.Template.Spec)
5166
}
5267

5368
// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type.
54-
func (r *GCPMachineTemplate) ValidateUpdate(old runtime.Object) (admission.Warnings, error) {
69+
func (_ *gcpMachineTemplateWebhook) ValidateUpdate(_ context.Context, oldObj, newObj runtime.Object) (admission.Warnings, error) {
70+
r, ok := newObj.(*GCPMachineTemplate)
71+
if !ok {
72+
return nil, fmt.Errorf("expected an GCPMachineTemplate object but got %T", r)
73+
}
74+
5575
newGCPMachineTemplate, err := runtime.DefaultUnstructuredConverter.ToUnstructured(r)
5676
if err != nil {
5777
return nil, apierrors.NewInvalid(GroupVersion.WithKind("GCPMachineTemplate").GroupKind(), r.Name, field.ErrorList{
5878
field.InternalError(nil, errors.Wrap(err, "failed to convert new GCPMachineTemplate to unstructured object")),
5979
})
6080
}
61-
oldGCPMachineTemplate, err := runtime.DefaultUnstructuredConverter.ToUnstructured(old)
81+
oldGCPMachineTemplate, err := runtime.DefaultUnstructuredConverter.ToUnstructured(oldObj)
6282
if err != nil {
6383
return nil, apierrors.NewInvalid(GroupVersion.WithKind("GCPMachineTemplate").GroupKind(), r.Name, field.ErrorList{
6484
field.InternalError(nil, errors.Wrap(err, "failed to convert old GCPMachineTemplate to unstructured object")),
@@ -90,13 +110,11 @@ func (r *GCPMachineTemplate) ValidateUpdate(old runtime.Object) (admission.Warni
90110
}
91111

92112
// ValidateDelete implements webhook.Validator so a webhook will be registered for the type.
93-
func (r *GCPMachineTemplate) ValidateDelete() (admission.Warnings, error) {
94-
clusterlog.Info("validate delete", "name", r.Name)
95-
113+
func (_ *gcpMachineTemplateWebhook) ValidateDelete(_ context.Context, _ runtime.Object) (admission.Warnings, error) {
96114
return nil, nil
97115
}
98116

99117
// Default implements webhookutil.defaulter so a webhook will be registered for the type.
100-
func (r *GCPMachineTemplate) Default() {
101-
clusterlog.Info("default", "name", r.Name)
118+
func (_ *gcpMachineTemplateWebhook) Default(_ context.Context, _ runtime.Object) error {
119+
return nil
102120
}

exp/api/v1beta1/gcpmanagedcluster_webhook.go

Lines changed: 25 additions & 10 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
"github.com/google/go-cmp/cmp"
2123
apierrors "k8s.io/apimachinery/pkg/api/errors"
2224
"k8s.io/apimachinery/pkg/runtime"
@@ -32,36 +34,51 @@ import (
3234
var gcpmanagedclusterlog = logf.Log.WithName("gcpmanagedcluster-resource")
3335

3436
func (r *GCPManagedCluster) SetupWebhookWithManager(mgr ctrl.Manager) error {
37+
w := new(gcpManagedClusterWebhook)
3538
return ctrl.NewWebhookManagedBy(mgr).
3639
For(r).
40+
WithValidator(w).
41+
WithDefaulter(w).
3742
Complete()
3843
}
3944

4045
//+kubebuilder:webhook:path=/mutate-infrastructure-cluster-x-k8s-io-v1beta1-gcpmanagedcluster,mutating=true,failurePolicy=fail,sideEffects=None,groups=infrastructure.cluster.x-k8s.io,resources=gcpmanagedclusters,verbs=create;update,versions=v1beta1,name=mgcpmanagedcluster.kb.io,admissionReviewVersions=v1
4146

42-
var _ webhook.Defaulter = &GCPManagedCluster{}
47+
type gcpManagedClusterWebhook struct{}
48+
49+
var _ webhook.CustomDefaulter = &gcpManagedClusterWebhook{}
4350

4451
// Default implements webhook.Defaulter so a webhook will be registered for the type.
45-
func (r *GCPManagedCluster) Default() {
46-
gcpmanagedclusterlog.Info("default", "name", r.Name)
52+
func (_ *gcpManagedClusterWebhook) Default(_ context.Context, _ runtime.Object) error {
53+
return nil
4754
}
4855

4956
//+kubebuilder:webhook:path=/validate-infrastructure-cluster-x-k8s-io-v1beta1-gcpmanagedcluster,mutating=false,failurePolicy=fail,sideEffects=None,groups=infrastructure.cluster.x-k8s.io,resources=gcpmanagedclusters,verbs=create;update,versions=v1beta1,name=vgcpmanagedcluster.kb.io,admissionReviewVersions=v1
5057

51-
var _ webhook.Validator = &GCPManagedCluster{}
58+
var _ webhook.CustomValidator = &gcpManagedClusterWebhook{}
5259

5360
// ValidateCreate implements webhook.Validator so a webhook will be registered for the type.
54-
func (r *GCPManagedCluster) ValidateCreate() (admission.Warnings, error) {
61+
func (_ *gcpManagedClusterWebhook) ValidateCreate(_ context.Context, obj runtime.Object) (admission.Warnings, error) {
62+
r, ok := obj.(*GCPManagedCluster)
63+
if !ok {
64+
return nil, fmt.Errorf("expected an GCPManagedCluster object but got %T", r)
65+
}
66+
5567
gcpmanagedclusterlog.Info("validate create", "name", r.Name)
5668

5769
return r.validate()
5870
}
5971

6072
// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type.
61-
func (r *GCPManagedCluster) ValidateUpdate(oldRaw runtime.Object) (admission.Warnings, error) {
73+
func (_ *gcpManagedClusterWebhook) ValidateUpdate(_ context.Context, oldObj, newObj runtime.Object) (admission.Warnings, error) {
74+
r, ok := newObj.(*GCPManagedCluster)
75+
if !ok {
76+
return nil, fmt.Errorf("expected an GCPManagedCluster object but got %T", r)
77+
}
78+
6279
gcpmanagedclusterlog.Info("validate update", "name", r.Name)
6380
var allErrs field.ErrorList
64-
old := oldRaw.(*GCPManagedCluster)
81+
old := oldObj.(*GCPManagedCluster)
6582

6683
if !cmp.Equal(r.Spec.Project, old.Spec.Project) {
6784
allErrs = append(allErrs,
@@ -92,9 +109,7 @@ func (r *GCPManagedCluster) ValidateUpdate(oldRaw runtime.Object) (admission.War
92109
}
93110

94111
// ValidateDelete implements webhook.Validator so a webhook will be registered for the type.
95-
func (r *GCPManagedCluster) ValidateDelete() (admission.Warnings, error) {
96-
gcpmanagedclusterlog.Info("validate delete", "name", r.Name)
97-
112+
func (_ *gcpManagedClusterWebhook) ValidateDelete(_ context.Context, _ runtime.Object) (admission.Warnings, error) {
98113
return nil, nil
99114
}
100115

0 commit comments

Comments
 (0)