Skip to content

Commit 135a3ff

Browse files
authored
Merge pull request #4510 from Ankitasw/bump-capi-v1.5
Bump CAPI to v1.5.0
2 parents d04e95c + 43b06c8 commit 135a3ff

File tree

85 files changed

+633
-508
lines changed

Some content is hidden

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

85 files changed

+633
-508
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

.golangci.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,6 @@ linters-settings:
8787
alias: apiextensionsv1
8888
- pkg: k8s.io/apimachinery/pkg/apis/meta/v1
8989
alias: metav1
90-
- pkg: k8s.io/apimachinery/pkg/api/errors
91-
alias: apierrors
9290
- pkg: k8s.io/apimachinery/pkg/util/errors
9391
alias: kerrors
9492
- pkg: sigs.k8s.io/controller-runtime/pkg/conversion
@@ -165,6 +163,12 @@ linters-settings:
165163
go: "1.20"
166164
stylecheck:
167165
go: "1.20"
166+
depguard:
167+
rules:
168+
main:
169+
deny:
170+
- pkg: "io/ioutil"
171+
desc: "ioutil is deprecated starting with Go 1.16"
168172
issues:
169173
max-same-issues: 0
170174
max-issues-per-linter: 0

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/awscluster_webhook_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ func TestAWSClusterValidateCreate(t *testing.T) {
476476
g.Eventually(func() bool {
477477
err := testEnv.Get(ctx, key, c)
478478
return err == nil
479-
}, 10*time.Second).Should(Equal(true))
479+
}, 10*time.Second).Should(BeTrue())
480480

481481
if tt.expect != nil {
482482
tt.expect(g, c.Spec.ControlPlaneLoadBalancer)

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
}

0 commit comments

Comments
 (0)