Skip to content

Commit ea2ce3d

Browse files
terassyihanapedia
andauthored
Support k8s 1.32 (#332)
* Support k8s 1.32 Signed-off-by: terashima <tomoya-terashima@cybozu.co.jp> * fix webhook setup Signed-off-by: Hiroki Hanada <hiroki-hanada@cybozu.co.jp> * wait for manager setup to complete before each test Signed-off-by: Hiroki Hanada <hiroki-hanada@cybozu.co.jp> * run make generate Signed-off-by: Hiroki Hanada <hiroki-hanada@cybozu.co.jp> * rewrite error handling in a more idiomatic manner Signed-off-by: Hiroki Hanada <hiroki-hanada@cybozu.co.jp> * add a comment for a sleep in pod_watcher_test Signed-off-by: Hiroki Hanada <hiroki-hanada@cybozu.co.jp> --------- Signed-off-by: terashima <tomoya-terashima@cybozu.co.jp> Signed-off-by: Hiroki Hanada <hiroki-hanada@cybozu.co.jp> Co-authored-by: Hiroki Hanada <hiroki-hanada@cybozu.co.jp>
1 parent 7d0307a commit ea2ce3d

File tree

12 files changed

+191
-87
lines changed

12 files changed

+191
-87
lines changed

.github/workflows/ci.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,14 @@ jobs:
4343
name: End-to-end Test
4444
strategy:
4545
matrix:
46-
kindest-node: ["1.29.12", "1.30.8", "1.31.4"]
46+
kindest-node: ["1.30.13", "1.31.9", "1.32.5"]
4747
with-ipam: ["false", "true"]
4848
ipv4: ["false", "true"]
4949
ipv6: ["false", "true"]
5050
ipv6-primary: ["false", "true"]
5151
exclude:
5252
- ipv4: "false"
53-
ipv6: "false"
53+
ipv6: "false"
5454
- ipv4: "false"
5555
ipv6: "true"
5656
ipv6-primary: "true"
@@ -107,7 +107,7 @@ jobs:
107107
name: Cert generation test
108108
strategy:
109109
matrix:
110-
kindest-node: ["1.29.12", "1.30.8", "1.31.4"]
110+
kindest-node: ["1.30.13", "1.31.9", "1.32.5"]
111111
runs-on: ubuntu-24.04
112112
steps:
113113
- uses: actions/checkout@v4

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Version 2 is generally available (GA). It conforms to [CNI spec 1.1.0](https://
2323

2424
## Dependencies
2525

26-
- Kubernetes Version: 1.29, 1.30, 1.31
26+
- Kubernetes Version: 1.30, 1.31, 1.32
2727
- Other versions are likely to work, but not tested.
2828

2929
- (Optional) Routing software

v2/Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
IMAGE_TAG := latest
44
CONTROLLER_RUNTIME_VERSION := $(shell awk '/sigs\.k8s\.io\/controller-runtime/ {print substr($$2, 2)}' go.mod)
5-
CONTROLLER_TOOLS_VERSION=0.16.5
6-
PROTOC_VERSION=30.2
5+
CONTROLLER_TOOLS_VERSION=0.17.3
6+
PROTOC_VERSION=31.1
77
PROTOC_GEN_GO_VERSION := $(shell awk '/google.golang.org\/protobuf/ {print substr($$2, 2)}' go.mod)
88
PROTOC_GEN_GO_GRPC_VERSON=1.5.1
99
PROTOC_GEN_DOC_VERSION=1.5.1
10-
YQ_VERSION=4.45.1
10+
YQ_VERSION=4.45.4
1111

1212
## DON'T EDIT BELOW THIS LINE
1313
SUDO=sudo

v2/api/v2/addresspool_webhook.go

Lines changed: 40 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package v2
22

33
import (
4+
"context"
5+
"fmt"
6+
47
"github.com/cybozu-go/coil/v2/pkg/constants"
58
apierrors "k8s.io/apimachinery/pkg/api/errors"
69
"k8s.io/apimachinery/pkg/runtime"
@@ -15,45 +18,67 @@ import (
1518
func (r *AddressPool) SetupWebhookWithManager(mgr ctrl.Manager) error {
1619
return ctrl.NewWebhookManagedBy(mgr).
1720
For(r).
21+
WithDefaulter(&AddressPoolCustomDefaulter{}).
22+
WithValidator(&AddressPoolCustomValidator{}).
1823
Complete()
1924
}
2025

26+
// AddressPoolCustomDefaulter is an empty struct that implements webhook.CustomDefaulter
27+
type AddressPoolCustomDefaulter struct{}
28+
2129
// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
2230

2331
//+kubebuilder:webhook:path=/mutate-coil-cybozu-com-v2-addresspool,mutating=true,failurePolicy=fail,sideEffects=None,groups=coil.cybozu.com,resources=addresspools,verbs=create,versions=v2,name=maddresspool.kb.io,admissionReviewVersions={v1,v1beta1}
2432

25-
var _ webhook.Defaulter = &AddressPool{}
33+
var _ webhook.CustomDefaulter = &AddressPoolCustomDefaulter{}
2634

2735
// Default implements webhook.Defaulter so a webhook will be registered for the type
28-
func (r *AddressPool) Default() {
29-
controllerutil.AddFinalizer(r, constants.FinCoil)
36+
func (r *AddressPoolCustomDefaulter) Default(ctx context.Context, obj runtime.Object) error {
37+
addressPool, ok := obj.(*AddressPool)
38+
if !ok {
39+
return fmt.Errorf("expected an AddressPool object but got a %T", obj)
40+
}
41+
42+
controllerutil.AddFinalizer(addressPool, constants.FinCoil)
43+
return nil
3044
}
3145

46+
// AddressPoolCustomValidator is an empty struct that implements webhook.CustomValidator
47+
type AddressPoolCustomValidator struct{}
48+
3249
// +kubebuilder:webhook:path=/validate-coil-cybozu-com-v2-addresspool,mutating=false,failurePolicy=fail,sideEffects=None,groups=coil.cybozu.com,resources=addresspools,verbs=create;update,versions=v2,name=vaddresspool.kb.io,admissionReviewVersions={v1,v1beta1}
3350

34-
var _ webhook.Validator = &AddressPool{}
51+
var _ webhook.CustomValidator = &AddressPoolCustomValidator{}
3552

3653
// ValidateCreate implements webhook.Validator so a webhook will be registered for the type
37-
func (r *AddressPool) ValidateCreate() (warnings admission.Warnings, err error) {
38-
errs := r.Spec.validate()
39-
if len(errs) == 0 {
40-
return nil, nil
54+
func (r *AddressPoolCustomValidator) ValidateCreate(ctx context.Context, obj runtime.Object) (warnings admission.Warnings, err error) {
55+
addressPool, ok := obj.(*AddressPool)
56+
if !ok {
57+
return nil, fmt.Errorf("expected an AddressPool object but got a %T", obj)
4158
}
4259

43-
return nil, apierrors.NewInvalid(schema.GroupKind{Group: GroupVersion.Group, Kind: "AddressPool"}, r.Name, errs)
60+
if errs := addressPool.Spec.validate(); len(errs) != 0 {
61+
return nil, apierrors.NewInvalid(schema.GroupKind{Group: GroupVersion.Group, Kind: "AddressPool"}, addressPool.Name, errs)
62+
}
63+
64+
return nil, nil
4465
}
4566

4667
// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type
47-
func (r *AddressPool) ValidateUpdate(old runtime.Object) (warnings admission.Warnings, err error) {
48-
errs := r.Spec.validateUpdate(old.(*AddressPool).Spec)
49-
if len(errs) == 0 {
50-
return nil, nil
68+
func (r *AddressPoolCustomValidator) ValidateUpdate(ctx context.Context, oldObj, newObj runtime.Object) (warnings admission.Warnings, err error) {
69+
addressPool, ok := newObj.(*AddressPool)
70+
if !ok {
71+
return nil, fmt.Errorf("expected an AddressPool object but got a %T", newObj)
5172
}
5273

53-
return nil, apierrors.NewInvalid(schema.GroupKind{Group: GroupVersion.Group, Kind: "AddressPool"}, r.Name, errs)
74+
if errs := addressPool.Spec.validateUpdate(oldObj.(*AddressPool).Spec); len(errs) != 0 {
75+
return nil, apierrors.NewInvalid(schema.GroupKind{Group: GroupVersion.Group, Kind: "AddressPool"}, addressPool.Name, errs)
76+
}
77+
78+
return nil, nil
5479
}
5580

5681
// ValidateDelete implements webhook.Validator so a webhook will be registered for the type
57-
func (r *AddressPool) ValidateDelete() (warnings admission.Warnings, err error) {
82+
func (r *AddressPoolCustomValidator) ValidateDelete(ctx context.Context, obj runtime.Object) (warnings admission.Warnings, err error) {
5883
return nil, nil
5984
}

v2/api/v2/egress_webhook.go

Lines changed: 41 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package v2
22

33
import (
4+
"context"
5+
"fmt"
6+
47
corev1 "k8s.io/api/core/v1"
58
apierrors "k8s.io/apimachinery/pkg/api/errors"
69
"k8s.io/apimachinery/pkg/runtime"
@@ -14,20 +17,30 @@ import (
1417
func (r *Egress) SetupWebhookWithManager(mgr ctrl.Manager) error {
1518
return ctrl.NewWebhookManagedBy(mgr).
1619
For(r).
20+
WithDefaulter(&EgressCustomDefaulter{}).
21+
WithValidator(&EgressCustomValidator{}).
1722
Complete()
1823
}
1924

25+
// EgressCustomDefaulter is an empty struct that implements webhook.CustomDefaulter
26+
type EgressCustomDefaulter struct{}
27+
2028
// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
2129

2230
// +kubebuilder:webhook:path=/mutate-coil-cybozu-com-v2-egress,mutating=true,failurePolicy=fail,sideEffects=None,groups=coil.cybozu.com,resources=egresses,verbs=create,versions=v2,name=megress.kb.io,admissionReviewVersions={v1,v1beta1}
2331

24-
var _ webhook.Defaulter = &Egress{}
32+
var _ webhook.CustomDefaulter = &EgressCustomDefaulter{}
2533

2634
// Default implements webhook.Defaulter so a webhook will be registered for the type
27-
func (r *Egress) Default() {
28-
tmpl := r.Spec.Template
35+
func (r *EgressCustomDefaulter) Default(ctx context.Context, obj runtime.Object) error {
36+
egress, ok := obj.(*Egress)
37+
if !ok {
38+
return fmt.Errorf("expected an Egress object but got a %T", obj)
39+
}
40+
41+
tmpl := egress.Spec.Template
2942
if tmpl == nil {
30-
return
43+
return nil
3144
}
3245

3346
if len(tmpl.Spec.Containers) == 0 {
@@ -37,33 +50,45 @@ func (r *Egress) Default() {
3750
},
3851
}
3952
}
53+
return nil
4054
}
4155

56+
// EgressCustomValidator is an empty struct that implements webhook.CustomValidator
57+
type EgressCustomValidator struct{}
58+
4259
// +kubebuilder:webhook:path=/validate-coil-cybozu-com-v2-egress,mutating=false,failurePolicy=fail,sideEffects=None,groups=coil.cybozu.com,resources=egresses,verbs=create;update,versions=v2,name=vegress.kb.io,admissionReviewVersions={v1,v1beta1}
4360

44-
var _ webhook.Validator = &Egress{}
61+
var _ webhook.CustomValidator = &EgressCustomValidator{}
4562

4663
// ValidateCreate implements webhook.Validator so a webhook will be registered for the type
47-
func (r *Egress) ValidateCreate() (warnings admission.Warnings, err error) {
48-
errs := r.Spec.validate()
49-
if len(errs) == 0 {
50-
return nil, nil
64+
func (r *EgressCustomValidator) ValidateCreate(ctx context.Context, obj runtime.Object) (warnings admission.Warnings, err error) {
65+
egress, ok := obj.(*Egress)
66+
if !ok {
67+
return nil, fmt.Errorf("expected an Egress object but got a %T", obj)
5168
}
5269

53-
return nil, apierrors.NewInvalid(schema.GroupKind{Group: GroupVersion.Group, Kind: "Egress"}, r.Name, errs)
70+
if errs := egress.Spec.validate(); len(errs) != 0 {
71+
return nil, apierrors.NewInvalid(schema.GroupKind{Group: GroupVersion.Group, Kind: "Egress"}, egress.Name, errs)
72+
}
73+
74+
return nil, nil
5475
}
5576

5677
// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type
57-
func (r *Egress) ValidateUpdate(old runtime.Object) (warnings admission.Warnings, err error) {
58-
errs := r.Spec.validateUpdate()
59-
if len(errs) == 0 {
60-
return nil, nil
78+
func (r *EgressCustomValidator) ValidateUpdate(ctx context.Context, oldObj, newObj runtime.Object) (warnings admission.Warnings, err error) {
79+
egress, ok := newObj.(*Egress)
80+
if !ok {
81+
return nil, fmt.Errorf("expected an Egress object but got a %T", newObj)
6182
}
6283

63-
return nil, apierrors.NewInvalid(schema.GroupKind{Group: GroupVersion.Group, Kind: "Egress"}, r.Name, errs)
84+
if errs := egress.Spec.validateUpdate(); len(errs) != 0 {
85+
return nil, apierrors.NewInvalid(schema.GroupKind{Group: GroupVersion.Group, Kind: "Egress"}, egress.Name, errs)
86+
}
87+
88+
return nil, nil
6489
}
6590

6691
// ValidateDelete implements webhook.Validator so a webhook will be registered for the type
67-
func (r *Egress) ValidateDelete() (warnings admission.Warnings, err error) {
92+
func (r *EgressCustomValidator) ValidateDelete(ctx context.Context, old runtime.Object) (warnings admission.Warnings, err error) {
6893
return nil, nil
6994
}

v2/api/v2/zz_generated.deepcopy.go

Lines changed: 60 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

v2/controllers/pod_watcher_test.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,11 @@ var _ = Describe("Pod watcher", Ordered, func() {
122122
panic(err)
123123
}
124124
}()
125-
time.Sleep(100 * time.Millisecond)
125+
126+
// Must sleep so that tests do not run before the controller manager is ready.
127+
// Although, a shorter duration was previously set (100ms),
128+
// the duration was increased because the tests that perform write operation early became flaky (e.g. `should check Pod deletion`).
129+
time.Sleep(1000 * time.Millisecond)
126130
})
127131

128132
AfterEach(func() {

v2/e2e/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
KIND_VERSION=0.27.0
2-
KUBERNETES_VERSION=1.31.6
1+
KIND_VERSION=0.29.0
2+
KUBERNETES_VERSION=1.32.5
33
KUSTOMIZE_VERSION = 5.6.0
44
BINDIR := $(abspath $(PWD)/../bin)
55

0 commit comments

Comments
 (0)