Skip to content

Commit 8167d6d

Browse files
furkatgofurov7Ankitasw
authored andcommitted
Bump CAPI to v1.5.0
Signed-off-by: Furkat Gofurov <[email protected]>
1 parent d04e95c commit 8167d6d

40 files changed

+388
-292
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ kubeconfig
3939
# vscode
4040
.vscode
4141

42+
# go.work files
43+
go.work
44+
go.work.sum
45+
4246
# goland
4347
.idea
4448

api/v1beta2/awscluster_webhook.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
"k8s.io/apimachinery/pkg/util/validation/field"
2727
ctrl "sigs.k8s.io/controller-runtime"
2828
"sigs.k8s.io/controller-runtime/pkg/webhook"
29+
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
2930

3031
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
3132
"sigs.k8s.io/cluster-api/util/annotations"
@@ -49,7 +50,7 @@ var (
4950
)
5051

5152
// ValidateCreate implements webhook.Validator so a webhook will be registered for the type.
52-
func (r *AWSCluster) ValidateCreate() error {
53+
func (r *AWSCluster) ValidateCreate() (admission.Warnings, error) {
5354
var allErrs field.ErrorList
5455

5556
allErrs = append(allErrs, r.Spec.Bastion.Validate()...)
@@ -59,23 +60,23 @@ func (r *AWSCluster) ValidateCreate() error {
5960
allErrs = append(allErrs, r.validateNetwork()...)
6061
allErrs = append(allErrs, r.validateControlPlaneLBIngressRules()...)
6162

62-
return aggregateObjErrors(r.GroupVersionKind().GroupKind(), r.Name, allErrs)
63+
return nil, aggregateObjErrors(r.GroupVersionKind().GroupKind(), r.Name, allErrs)
6364
}
6465

6566
// ValidateDelete implements webhook.Validator so a webhook will be registered for the type.
66-
func (r *AWSCluster) ValidateDelete() error {
67-
return nil
67+
func (r *AWSCluster) ValidateDelete() (admission.Warnings, error) {
68+
return nil, nil
6869
}
6970

7071
// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type.
71-
func (r *AWSCluster) ValidateUpdate(old runtime.Object) error {
72+
func (r *AWSCluster) ValidateUpdate(old runtime.Object) (admission.Warnings, error) {
7273
var allErrs field.ErrorList
7374

7475
allErrs = append(allErrs, r.validateGCTasksAnnotation()...)
7576

7677
oldC, ok := old.(*AWSCluster)
7778
if !ok {
78-
return apierrors.NewBadRequest(fmt.Sprintf("expected an AWSCluster but got a %T", old))
79+
return nil, apierrors.NewBadRequest(fmt.Sprintf("expected an AWSCluster but got a %T", old))
7980
}
8081

8182
if r.Spec.Region != oldC.Spec.Region {
@@ -170,7 +171,7 @@ func (r *AWSCluster) ValidateUpdate(old runtime.Object) error {
170171
allErrs = append(allErrs, r.Spec.AdditionalTags.Validate()...)
171172
allErrs = append(allErrs, r.Spec.S3Bucket.Validate()...)
172173

173-
return aggregateObjErrors(r.GroupVersionKind().GroupKind(), r.Name, allErrs)
174+
return nil, aggregateObjErrors(r.GroupVersionKind().GroupKind(), r.Name, allErrs)
174175
}
175176

176177
// Default satisfies the defaulting webhook interface.

api/v1beta2/awsclustercontrolleridentity_webhook.go

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
"k8s.io/apimachinery/pkg/util/validation/field"
2828
ctrl "sigs.k8s.io/controller-runtime"
2929
"sigs.k8s.io/controller-runtime/pkg/webhook"
30+
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
3031
)
3132

3233
// log is for logging in this package.
@@ -47,54 +48,54 @@ var (
4748
)
4849

4950
// ValidateCreate will do any extra validation when creating an AWSClusterControllerIdentity.
50-
func (r *AWSClusterControllerIdentity) ValidateCreate() error {
51+
func (r *AWSClusterControllerIdentity) ValidateCreate() (admission.Warnings, error) {
5152
// Ensures AWSClusterControllerIdentity being singleton by only allowing "default" as name
5253
if r.Name != AWSClusterControllerIdentityName {
53-
return field.Invalid(field.NewPath("name"),
54+
return nil, field.Invalid(field.NewPath("name"),
5455
r.Name, "AWSClusterControllerIdentity is a singleton and only acceptable name is default")
5556
}
5657

5758
// Validate selector parses as Selector if AllowedNameSpaces is populated
5859
if r.Spec.AllowedNamespaces != nil {
5960
_, err := metav1.LabelSelectorAsSelector(&r.Spec.AllowedNamespaces.Selector)
6061
if err != nil {
61-
return field.Invalid(field.NewPath("spec", "allowedNamespaces", "selector"), r.Spec.AllowedNamespaces.Selector, err.Error())
62+
return nil, field.Invalid(field.NewPath("spec", "allowedNamespaces", "selector"), r.Spec.AllowedNamespaces.Selector, err.Error())
6263
}
6364
}
6465

65-
return nil
66+
return nil, nil
6667
}
6768

6869
// ValidateDelete allows you to add any extra validation when deleting an AWSClusterControllerIdentity.
69-
func (r *AWSClusterControllerIdentity) ValidateDelete() error {
70-
return nil
70+
func (r *AWSClusterControllerIdentity) ValidateDelete() (admission.Warnings, error) {
71+
return nil, nil
7172
}
7273

7374
// ValidateUpdate will do any extra validation when updating an AWSClusterControllerIdentity.
74-
func (r *AWSClusterControllerIdentity) ValidateUpdate(old runtime.Object) error {
75+
func (r *AWSClusterControllerIdentity) ValidateUpdate(old runtime.Object) (admission.Warnings, error) {
7576
oldP, ok := old.(*AWSClusterControllerIdentity)
7677
if !ok {
77-
return apierrors.NewBadRequest(fmt.Sprintf("expected an AWSClusterControllerIdentity but got a %T", old))
78+
return nil, apierrors.NewBadRequest(fmt.Sprintf("expected an AWSClusterControllerIdentity but got a %T", old))
7879
}
7980

8081
if !cmp.Equal(r.Spec, oldP.Spec) {
81-
return errors.New("AWSClusterControllerIdentity is immutable")
82+
return nil, errors.New("AWSClusterControllerIdentity is immutable")
8283
}
8384

8485
if r.Name != oldP.Name {
85-
return field.Invalid(field.NewPath("name"),
86+
return nil, field.Invalid(field.NewPath("name"),
8687
r.Name, "AWSClusterControllerIdentity is a singleton and only acceptable name is default")
8788
}
8889

8990
// Validate selector parses as Selector if AllowedNameSpaces is not nil
9091
if r.Spec.AllowedNamespaces != nil {
9192
_, err := metav1.LabelSelectorAsSelector(&r.Spec.AllowedNamespaces.Selector)
9293
if err != nil {
93-
return field.Invalid(field.NewPath("spec", "allowedNamespaces", "selectors"), r.Spec.AllowedNamespaces.Selector, err.Error())
94+
return nil, field.Invalid(field.NewPath("spec", "allowedNamespaces", "selectors"), r.Spec.AllowedNamespaces.Selector, err.Error())
9495
}
9596
}
9697

97-
return nil
98+
return nil, nil
9899
}
99100

100101
// Default will set default values for the AWSClusterControllerIdentity.

api/v1beta2/awsclusterroleidentity_webhook.go

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"k8s.io/apimachinery/pkg/util/validation/field"
2626
ctrl "sigs.k8s.io/controller-runtime"
2727
"sigs.k8s.io/controller-runtime/pkg/webhook"
28+
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
2829
)
2930

3031
// log is for logging in this package.
@@ -45,50 +46,50 @@ var (
4546
)
4647

4748
// ValidateCreate will do any extra validation when creating an AWSClusterRoleIdentity.
48-
func (r *AWSClusterRoleIdentity) ValidateCreate() error {
49+
func (r *AWSClusterRoleIdentity) ValidateCreate() (admission.Warnings, error) {
4950
if r.Spec.SourceIdentityRef == nil {
50-
return field.Invalid(field.NewPath("spec", "sourceIdentityRef"),
51+
return nil, field.Invalid(field.NewPath("spec", "sourceIdentityRef"),
5152
r.Spec.SourceIdentityRef, "field cannot be set to nil")
5253
}
5354

5455
// Validate selector parses as Selector
5556
if r.Spec.AllowedNamespaces != nil {
5657
_, err := metav1.LabelSelectorAsSelector(&r.Spec.AllowedNamespaces.Selector)
5758
if err != nil {
58-
return field.Invalid(field.NewPath("spec", "allowedNamespaces", "selector"), r.Spec.AllowedNamespaces.Selector, err.Error())
59+
return nil, field.Invalid(field.NewPath("spec", "allowedNamespaces", "selector"), r.Spec.AllowedNamespaces.Selector, err.Error())
5960
}
6061
}
6162

62-
return nil
63+
return nil, nil
6364
}
6465

6566
// ValidateDelete allows you to add any extra validation when deleting an AWSClusterRoleIdentity.
66-
func (r *AWSClusterRoleIdentity) ValidateDelete() error {
67-
return nil
67+
func (r *AWSClusterRoleIdentity) ValidateDelete() (admission.Warnings, error) {
68+
return nil, nil
6869
}
6970

7071
// ValidateUpdate will do any extra validation when updating an AWSClusterRoleIdentity.
71-
func (r *AWSClusterRoleIdentity) ValidateUpdate(old runtime.Object) error {
72+
func (r *AWSClusterRoleIdentity) ValidateUpdate(old runtime.Object) (admission.Warnings, error) {
7273
oldP, ok := old.(*AWSClusterRoleIdentity)
7374
if !ok {
74-
return apierrors.NewBadRequest(fmt.Sprintf("expected an AWSClusterRoleIdentity but got a %T", old))
75+
return nil, apierrors.NewBadRequest(fmt.Sprintf("expected an AWSClusterRoleIdentity but got a %T", old))
7576
}
7677

7778
// If a SourceIdentityRef is set, do not allow removal of it.
7879
if oldP.Spec.SourceIdentityRef != nil && r.Spec.SourceIdentityRef == nil {
79-
return field.Invalid(field.NewPath("spec", "sourceIdentityRef"),
80+
return nil, field.Invalid(field.NewPath("spec", "sourceIdentityRef"),
8081
r.Spec.SourceIdentityRef, "field cannot be set to nil")
8182
}
8283

8384
// Validate selector parses as Selector
8485
if r.Spec.AllowedNamespaces != nil {
8586
_, err := metav1.LabelSelectorAsSelector(&r.Spec.AllowedNamespaces.Selector)
8687
if err != nil {
87-
return field.Invalid(field.NewPath("spec", "allowedNamespaces", "selector"), r.Spec.AllowedNamespaces.Selector, err.Error())
88+
return nil, field.Invalid(field.NewPath("spec", "allowedNamespaces", "selector"), r.Spec.AllowedNamespaces.Selector, err.Error())
8889
}
8990
}
9091

91-
return nil
92+
return nil, nil
9293
}
9394

9495
// Default will set default values for the AWSClusterRoleIdentity.

api/v1beta2/awsclusterstaticidentity_webhook.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"k8s.io/apimachinery/pkg/util/validation/field"
2626
ctrl "sigs.k8s.io/controller-runtime"
2727
"sigs.k8s.io/controller-runtime/pkg/webhook"
28+
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
2829
)
2930

3031
// log is for logging in this package.
@@ -45,44 +46,44 @@ var (
4546
)
4647

4748
// ValidateCreate implements webhook.Validator so a webhook will be registered for the type.
48-
func (r *AWSClusterStaticIdentity) ValidateCreate() error {
49+
func (r *AWSClusterStaticIdentity) ValidateCreate() (admission.Warnings, error) {
4950
// Validate selector parses as Selector
5051
if r.Spec.AllowedNamespaces != nil {
5152
_, err := metav1.LabelSelectorAsSelector(&r.Spec.AllowedNamespaces.Selector)
5253
if err != nil {
53-
return field.Invalid(field.NewPath("spec", "allowedNamespaces", "selector"), r.Spec.AllowedNamespaces.Selector, err.Error())
54+
return nil, field.Invalid(field.NewPath("spec", "allowedNamespaces", "selector"), r.Spec.AllowedNamespaces.Selector, err.Error())
5455
}
5556
}
5657

57-
return nil
58+
return nil, nil
5859
}
5960

6061
// ValidateDelete implements webhook.Validator so a webhook will be registered for the type.
61-
func (r *AWSClusterStaticIdentity) ValidateDelete() error {
62-
return nil
62+
func (r *AWSClusterStaticIdentity) ValidateDelete() (admission.Warnings, error) {
63+
return nil, nil
6364
}
6465

6566
// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type.
66-
func (r *AWSClusterStaticIdentity) ValidateUpdate(old runtime.Object) error {
67+
func (r *AWSClusterStaticIdentity) ValidateUpdate(old runtime.Object) (admission.Warnings, error) {
6768
oldP, ok := old.(*AWSClusterStaticIdentity)
6869
if !ok {
69-
return apierrors.NewBadRequest(fmt.Sprintf("expected an AWSClusterStaticIdentity but got a %T", old))
70+
return nil, apierrors.NewBadRequest(fmt.Sprintf("expected an AWSClusterStaticIdentity but got a %T", old))
7071
}
7172

7273
if oldP.Spec.SecretRef != r.Spec.SecretRef {
73-
return field.Invalid(field.NewPath("spec", "secretRef"),
74+
return nil, field.Invalid(field.NewPath("spec", "secretRef"),
7475
r.Spec.SecretRef, "field cannot be updated")
7576
}
7677

7778
// Validate selector parses as Selector
7879
if r.Spec.AllowedNamespaces != nil {
7980
_, err := metav1.LabelSelectorAsSelector(&r.Spec.AllowedNamespaces.Selector)
8081
if err != nil {
81-
return field.Invalid(field.NewPath("spec", "allowedNamespaces", "selector"), r.Spec.AllowedNamespaces.Selector, err.Error())
82+
return nil, field.Invalid(field.NewPath("spec", "allowedNamespaces", "selector"), r.Spec.AllowedNamespaces.Selector, err.Error())
8283
}
8384
}
8485

85-
return nil
86+
return nil, nil
8687
}
8788

8889
// Default should return the default AWSClusterStaticIdentity.

api/v1beta2/awsclustertemplate_webhook.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"k8s.io/apimachinery/pkg/util/validation/field"
2424
ctrl "sigs.k8s.io/controller-runtime"
2525
"sigs.k8s.io/controller-runtime/pkg/webhook"
26+
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
2627
)
2728

2829
func (r *AWSClusterTemplate) SetupWebhookWithManager(mgr ctrl.Manager) error {
@@ -43,26 +44,26 @@ func (r *AWSClusterTemplate) Default() {
4344
}
4445

4546
// ValidateCreate implements webhook.Validator so a webhook will be registered for the type.
46-
func (r *AWSClusterTemplate) ValidateCreate() error {
47+
func (r *AWSClusterTemplate) ValidateCreate() (admission.Warnings, error) {
4748
var allErrs field.ErrorList
4849

4950
allErrs = append(allErrs, r.Spec.Template.Spec.Bastion.Validate()...)
5051
allErrs = append(allErrs, validateSSHKeyName(r.Spec.Template.Spec.SSHKeyName)...)
5152

52-
return aggregateObjErrors(r.GroupVersionKind().GroupKind(), r.Name, allErrs)
53+
return nil, aggregateObjErrors(r.GroupVersionKind().GroupKind(), r.Name, allErrs)
5354
}
5455

5556
// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type.
56-
func (r *AWSClusterTemplate) ValidateUpdate(oldRaw runtime.Object) error {
57+
func (r *AWSClusterTemplate) ValidateUpdate(oldRaw runtime.Object) (admission.Warnings, error) {
5758
old := oldRaw.(*AWSClusterTemplate)
5859

5960
if !cmp.Equal(r.Spec, old.Spec) {
60-
return apierrors.NewBadRequest("AWSClusterTemplate.Spec is immutable")
61+
return nil, apierrors.NewBadRequest("AWSClusterTemplate.Spec is immutable")
6162
}
62-
return nil
63+
return nil, nil
6364
}
6465

6566
// ValidateDelete implements webhook.Validator so a webhook will be registered for the type.
66-
func (r *AWSClusterTemplate) ValidateDelete() error {
67-
return nil
67+
func (r *AWSClusterTemplate) ValidateDelete() (admission.Warnings, error) {
68+
return nil, nil
6869
}

api/v1beta2/awsmachine_webhook.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"k8s.io/apimachinery/pkg/util/validation/field"
2525
ctrl "sigs.k8s.io/controller-runtime"
2626
"sigs.k8s.io/controller-runtime/pkg/webhook"
27+
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
2728

2829
"sigs.k8s.io/cluster-api-provider-aws/v2/feature"
2930
)
@@ -46,7 +47,7 @@ var (
4647
)
4748

4849
// ValidateCreate implements webhook.Validator so a webhook will be registered for the type.
49-
func (r *AWSMachine) ValidateCreate() error {
50+
func (r *AWSMachine) ValidateCreate() (admission.Warnings, error) {
5051
var allErrs field.ErrorList
5152

5253
allErrs = append(allErrs, r.validateCloudInitSecret()...)
@@ -57,20 +58,20 @@ func (r *AWSMachine) ValidateCreate() error {
5758
allErrs = append(allErrs, r.validateAdditionalSecurityGroups()...)
5859
allErrs = append(allErrs, r.Spec.AdditionalTags.Validate()...)
5960

60-
return aggregateObjErrors(r.GroupVersionKind().GroupKind(), r.Name, allErrs)
61+
return nil, aggregateObjErrors(r.GroupVersionKind().GroupKind(), r.Name, allErrs)
6162
}
6263

6364
// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type.
64-
func (r *AWSMachine) ValidateUpdate(old runtime.Object) error {
65+
func (r *AWSMachine) ValidateUpdate(old runtime.Object) (admission.Warnings, error) {
6566
newAWSMachine, err := runtime.DefaultUnstructuredConverter.ToUnstructured(r)
6667
if err != nil {
67-
return apierrors.NewInvalid(GroupVersion.WithKind("AWSMachine").GroupKind(), r.Name, field.ErrorList{
68+
return nil, apierrors.NewInvalid(GroupVersion.WithKind("AWSMachine").GroupKind(), r.Name, field.ErrorList{
6869
field.InternalError(nil, errors.Wrap(err, "failed to convert new AWSMachine to unstructured object")),
6970
})
7071
}
7172
oldAWSMachine, err := runtime.DefaultUnstructuredConverter.ToUnstructured(old)
7273
if err != nil {
73-
return apierrors.NewInvalid(GroupVersion.WithKind("AWSMachine").GroupKind(), r.Name, field.ErrorList{
74+
return nil, apierrors.NewInvalid(GroupVersion.WithKind("AWSMachine").GroupKind(), r.Name, field.ErrorList{
7475
field.InternalError(nil, errors.Wrap(err, "failed to convert old AWSMachine to unstructured object")),
7576
})
7677
}
@@ -117,7 +118,7 @@ func (r *AWSMachine) ValidateUpdate(old runtime.Object) error {
117118
allErrs = append(allErrs, field.Forbidden(field.NewPath("spec"), "cannot be modified"))
118119
}
119120

120-
return aggregateObjErrors(r.GroupVersionKind().GroupKind(), r.Name, allErrs)
121+
return nil, aggregateObjErrors(r.GroupVersionKind().GroupKind(), r.Name, allErrs)
121122
}
122123

123124
func (r *AWSMachine) validateCloudInitSecret() field.ErrorList {
@@ -226,8 +227,8 @@ func (r *AWSMachine) validateNonRootVolumes() field.ErrorList {
226227
}
227228

228229
// ValidateDelete implements webhook.Validator so a webhook will be registered for the type.
229-
func (r *AWSMachine) ValidateDelete() error {
230-
return nil
230+
func (r *AWSMachine) ValidateDelete() (admission.Warnings, error) {
231+
return nil, nil
231232
}
232233

233234
// Default implements webhook.Defaulter such that an empty CloudInit will be defined with a default

0 commit comments

Comments
 (0)