Skip to content

Commit 973f4e0

Browse files
committed
fix Failing test in 1.35
Signed-off-by: Kay Yan <kay.yan@daocloud.io>
1 parent b32125d commit 973f4e0

9 files changed

Lines changed: 52 additions & 40 deletions

File tree

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
GO_VERSION := $(shell awk '/^go /{print $$2}' go.mod|head -n1)
33

44
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
5-
ENVTEST_K8S_VERSION = 1.35.0
5+
ENVTEST_K8S_VERSION = 1.34.0
66

77
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
88
ifeq (,$(shell go env GOBIN))
@@ -69,7 +69,7 @@ ARTIFACTS ?= $(PROJECT_DIR)/bin
6969

7070
INTEGRATION_TARGET ?= ./test/integration/...
7171

72-
E2E_KIND_VERSION ?= kindest/node:v1.35.0
72+
E2E_KIND_VERSION ?= kindest/node:v1.34.0
7373
CERT_MANAGER_VERSION ?= v1.17.0
7474
USE_EXISTING_CLUSTER ?= false
7575

cmd/main.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -192,11 +192,10 @@ func setupControllers(mgr ctrl.Manager, certsReady chan struct{}, cfg configapi.
192192
<-certsReady
193193
setupLog.Info("certs ready")
194194

195-
// TODO: Deprecated: this uses the old events API and will be removed in a future release. Please use GetEventRecorder instead.
196195
if err := controllers.NewLeaderWorkerSetReconciler(
197196
mgr.GetClient(),
198197
mgr.GetScheme(),
199-
mgr.GetEventRecorderFor("leaderworkerset"), //nolint
198+
mgr.GetEventRecorderFor("leaderworkerset"),
200199
).SetupWithManager(mgr); err != nil {
201200
setupLog.Error(err, "unable to create controller", "controller", "LeaderWorkerSet")
202201
os.Exit(1)
@@ -213,8 +212,7 @@ func setupControllers(mgr ctrl.Manager, certsReady chan struct{}, cfg configapi.
213212
setupLog.Info("Gang scheduling enabled", "provider", *cfg.GangSchedulingManagement.SchedulerProvider)
214213
}
215214
// Set up pod reconciler.
216-
// TODO: Deprecated: this uses the old events API and will be removed in a future release. Please use GetEventRecorder instead.
217-
podController := controllers.NewPodReconciler(mgr.GetClient(), mgr.GetScheme(), mgr.GetEventRecorderFor("leaderworkerset"), sp) //nolint
215+
podController := controllers.NewPodReconciler(mgr.GetClient(), mgr.GetScheme(), mgr.GetEventRecorderFor("leaderworkerset"), sp)
218216
if err := podController.SetupWithManager(mgr); err != nil {
219217
setupLog.Error(err, "unable to create controller", "controller", "Pod")
220218
os.Exit(1)

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ require (
1919
k8s.io/component-helpers v0.35.0
2020
k8s.io/klog/v2 v2.130.1
2121
k8s.io/utils v0.0.0-20251002143259-bc988d571ff4
22-
sigs.k8s.io/controller-runtime v0.23.0
23-
sigs.k8s.io/structured-merge-diff/v6 v6.3.1
22+
sigs.k8s.io/controller-runtime v0.22.4
23+
sigs.k8s.io/structured-merge-diff/v6 v6.3.2-0.20260122202528-d9cc6641c482
2424
volcano.sh/apis v1.12.1
2525
)
2626

go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -259,14 +259,14 @@ k8s.io/utils v0.0.0-20251002143259-bc988d571ff4 h1:SjGebBtkBqHFOli+05xYbK8YF1Dzk
259259
k8s.io/utils v0.0.0-20251002143259-bc988d571ff4/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0=
260260
sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.31.2 h1:jpcvIRr3GLoUoEKRkHKSmGjxb6lWwrBlJsXc+eUYQHM=
261261
sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.31.2/go.mod h1:Ve9uj1L+deCXFrPOk1LpFXqTg7LCFzFso6PA48q/XZw=
262-
sigs.k8s.io/controller-runtime v0.23.0 h1:Ubi7klJWiwEWqDY+odSVZiFA0aDSevOCXpa38yCSYu8=
263-
sigs.k8s.io/controller-runtime v0.23.0/go.mod h1:DBOIr9NsprUqCZ1ZhsuJ0wAnQSIxY/C6VjZbmLgw0j0=
262+
sigs.k8s.io/controller-runtime v0.22.4 h1:GEjV7KV3TY8e+tJ2LCTxUTanW4z/FmNB7l327UfMq9A=
263+
sigs.k8s.io/controller-runtime v0.22.4/go.mod h1:+QX1XUpTXN4mLoblf4tqr5CQcyHPAki2HLXqQMY6vh8=
264264
sigs.k8s.io/json v0.0.0-20250730193827-2d320260d730 h1:IpInykpT6ceI+QxKBbEflcR5EXP7sU1kvOlxwZh5txg=
265265
sigs.k8s.io/json v0.0.0-20250730193827-2d320260d730/go.mod h1:mdzfpAEoE6DHQEN0uh9ZbOCuHbLK5wOm7dK4ctXE9Tg=
266266
sigs.k8s.io/randfill v1.0.0 h1:JfjMILfT8A6RbawdsK2JXGBR5AQVfd+9TbzrlneTyrU=
267267
sigs.k8s.io/randfill v1.0.0/go.mod h1:XeLlZ/jmk4i1HRopwe7/aU3H5n1zNUcX6TM94b3QxOY=
268-
sigs.k8s.io/structured-merge-diff/v6 v6.3.1 h1:JrhdFMqOd/+3ByqlP2I45kTOZmTRLBUm5pvRjeheg7E=
269-
sigs.k8s.io/structured-merge-diff/v6 v6.3.1/go.mod h1:M3W8sfWvn2HhQDIbGWj3S099YozAsymCo/wrT5ohRUE=
268+
sigs.k8s.io/structured-merge-diff/v6 v6.3.2-0.20260122202528-d9cc6641c482 h1:2WOzJpHUBVrrkDjU4KBT8n5LDcj824eX0I5UKcgeRUs=
269+
sigs.k8s.io/structured-merge-diff/v6 v6.3.2-0.20260122202528-d9cc6641c482/go.mod h1:M3W8sfWvn2HhQDIbGWj3S099YozAsymCo/wrT5ohRUE=
270270
sigs.k8s.io/yaml v1.6.0 h1:G8fkbMSAFqgEFgh4b1wmtzDnioxFCUgTZhlbj5P9QYs=
271271
sigs.k8s.io/yaml v1.6.0/go.mod h1:796bPqUfzR/0jLAl6XjHl3Ck7MiyVv8dbTdyT3/pMf4=
272272
volcano.sh/apis v1.12.1 h1:yq5dVj/g21vnWObCIKsJKPhMoThpzDrHDD/GMouYVxk=

pkg/controllers/leaderworkerset_controller.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -368,8 +368,7 @@ func (r *LeaderWorkerSetReconciler) SSAWithStatefulset(ctx context.Context, lws
368368
// If there are conflicts in the fields owned by the lws controller, lws will obtain the ownership and force override
369369
// these fields to the ones desired by the lws controller
370370
// TODO b/316776287 add E2E test for SSA
371-
// TODO: Deprecated: Use client.Client.Apply() and client.Client.SubResource("subrsource").Apply() instead.
372-
err = r.Patch(ctx, patch, client.Apply, &client.PatchOptions{ //nolint
371+
err = r.Patch(ctx, patch, client.Apply, &client.PatchOptions{
373372
FieldManager: fieldManager,
374373
Force: ptr.To[bool](true),
375374
})

pkg/webhooks/leaderworkerset_webhook.go

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,12 @@ import (
2525
apivalidation "k8s.io/apimachinery/pkg/api/validation"
2626
utilvalidation "k8s.io/apimachinery/pkg/util/validation"
2727

28+
"k8s.io/apimachinery/pkg/runtime"
2829
"k8s.io/apimachinery/pkg/util/intstr"
2930
"k8s.io/apimachinery/pkg/util/validation/field"
3031
"k8s.io/utils/ptr"
3132
ctrl "sigs.k8s.io/controller-runtime"
33+
"sigs.k8s.io/controller-runtime/pkg/webhook"
3234
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
3335

3436
v1 "sigs.k8s.io/lws/api/leaderworkerset/v1"
@@ -38,18 +40,20 @@ type LeaderWorkerSetWebhook struct{}
3840

3941
// SetupLeaderWorkerSetWebhook will setup the manager to manage the webhooks
4042
func SetupLeaderWorkerSetWebhook(mgr ctrl.Manager) error {
41-
return ctrl.NewWebhookManagedBy(mgr, &v1.LeaderWorkerSet{}).
43+
return ctrl.NewWebhookManagedBy(mgr).
44+
For(&v1.LeaderWorkerSet{}).
4245
WithDefaulter(&LeaderWorkerSetWebhook{}).
4346
WithValidator(&LeaderWorkerSetWebhook{}).
4447
Complete()
4548
}
4649

4750
//+kubebuilder:webhook:path=/mutate-leaderworkerset-x-k8s-io-v1-leaderworkerset,mutating=true,failurePolicy=fail,sideEffects=None,groups=leaderworkerset.x-k8s.io,resources=leaderworkersets,verbs=create;update,versions=v1,name=mleaderworkerset.kb.io,admissionReviewVersions=v1
4851

49-
var _ admission.Defaulter[*v1.LeaderWorkerSet] = &LeaderWorkerSetWebhook{}
52+
var _ webhook.CustomDefaulter = &LeaderWorkerSetWebhook{}
5053

51-
// Default implements admission.Defaulter[*v1.LeaderWorkerSet] so a webhook will be registered for the type
52-
func (r *LeaderWorkerSetWebhook) Default(ctx context.Context, lws *v1.LeaderWorkerSet) error {
54+
// Default implements webhook.Defaulter so a webhook will be registered for the type
55+
func (r *LeaderWorkerSetWebhook) Default(ctx context.Context, obj runtime.Object) error {
56+
lws := obj.(*v1.LeaderWorkerSet)
5357
if lws.Spec.LeaderWorkerTemplate.RestartPolicy == "" {
5458
lws.Spec.LeaderWorkerTemplate.RestartPolicy = v1.RecreateGroupOnPodRestart
5559
}
@@ -86,19 +90,21 @@ func (r *LeaderWorkerSetWebhook) Default(ctx context.Context, lws *v1.LeaderWork
8690

8791
//+kubebuilder:webhook:path=/validate-leaderworkerset-x-k8s-io-v1-leaderworkerset,mutating=false,failurePolicy=fail,sideEffects=None,groups=leaderworkerset.x-k8s.io,resources=leaderworkersets,verbs=create;update,versions=v1,name=vleaderworkerset.kb.io,admissionReviewVersions=v1
8892

89-
var _ admission.Validator[*v1.LeaderWorkerSet] = &LeaderWorkerSetWebhook{}
93+
var _ webhook.CustomValidator = &LeaderWorkerSetWebhook{}
9094

91-
// ValidateCreate implements admission.Validator[*v1.LeaderWorkerSet] so a webhook will be registered for the type
92-
func (r *LeaderWorkerSetWebhook) ValidateCreate(ctx context.Context, lws *v1.LeaderWorkerSet) (admission.Warnings, error) {
93-
allErrs := r.generalValidate(lws)
95+
// ValidateCreate implements webhook.Validator so a webhook will be registered for the type
96+
func (r *LeaderWorkerSetWebhook) ValidateCreate(ctx context.Context, obj runtime.Object) (admission.Warnings, error) {
97+
allErrs := r.generalValidate(obj)
9498
return nil, allErrs.ToAggregate()
9599
}
96100

97-
// ValidateUpdate implements admission.Validator[*v1.LeaderWorkerSet] so a webhook will be registered for the type
98-
func (r *LeaderWorkerSetWebhook) ValidateUpdate(ctx context.Context, oldLws, newLws *v1.LeaderWorkerSet) (admission.Warnings, error) {
99-
allErrs := r.generalValidate(newLws)
101+
// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type
102+
func (r *LeaderWorkerSetWebhook) ValidateUpdate(ctx context.Context, oldObj, newObj runtime.Object) (admission.Warnings, error) {
103+
allErrs := r.generalValidate(newObj)
100104
specPath := field.NewPath("spec")
101105

106+
oldLws := oldObj.(*v1.LeaderWorkerSet)
107+
newLws := newObj.(*v1.LeaderWorkerSet)
102108
if newLws.Spec.LeaderWorkerTemplate.SubGroupPolicy != nil && oldLws.Spec.LeaderWorkerTemplate.SubGroupPolicy != nil {
103109
allErrs = append(allErrs, apivalidation.ValidateImmutableField(*newLws.Spec.LeaderWorkerTemplate.SubGroupPolicy.SubGroupSize, *oldLws.Spec.LeaderWorkerTemplate.SubGroupPolicy.SubGroupSize, field.NewPath("spec", "leaderWorkerTemplate", "SubGroupPolicy", "subGroupSize"))...)
104110
}
@@ -115,12 +121,13 @@ func (r *LeaderWorkerSetWebhook) ValidateUpdate(ctx context.Context, oldLws, new
115121
return nil, allErrs.ToAggregate()
116122
}
117123

118-
// ValidateDelete implements admission.Validator[*v1.LeaderWorkerSet] so a webhook will be registered for the type
119-
func (r *LeaderWorkerSetWebhook) ValidateDelete(ctx context.Context, lws *v1.LeaderWorkerSet) (admission.Warnings, error) {
124+
// ValidateDelete implements webhook.Validator so a webhook will be registered for the type
125+
func (r *LeaderWorkerSetWebhook) ValidateDelete(ctx context.Context, obj runtime.Object) (admission.Warnings, error) {
120126
return nil, nil
121127
}
122128

123-
func (r *LeaderWorkerSetWebhook) generalValidate(lws *v1.LeaderWorkerSet) field.ErrorList {
129+
func (r *LeaderWorkerSetWebhook) generalValidate(obj runtime.Object) field.ErrorList {
130+
lws := obj.(*v1.LeaderWorkerSet)
124131
specPath := field.NewPath("spec")
125132
metadataPath := field.NewPath("metadata")
126133

pkg/webhooks/pod_webhook.go

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222

2323
corev1 "k8s.io/api/core/v1"
2424
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
25+
"k8s.io/apimachinery/pkg/runtime"
2526
ctrl "sigs.k8s.io/controller-runtime"
2627
logf "sigs.k8s.io/controller-runtime/pkg/log"
2728
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
@@ -43,7 +44,8 @@ func NewPodWebhook(sp schedulerprovider.SchedulerProvider) *PodWebhook {
4344
}
4445

4546
func (p *PodWebhook) Setup(mgr ctrl.Manager) error {
46-
return ctrl.NewWebhookManagedBy(mgr, &corev1.Pod{}).
47+
return ctrl.NewWebhookManagedBy(mgr).
48+
For(&corev1.Pod{}).
4749
WithDefaulter(p).
4850
WithValidator(p).
4951
Complete()
@@ -52,8 +54,12 @@ func (p *PodWebhook) Setup(mgr ctrl.Manager) error {
5254
//+kubebuilder:webhook:path=/validate--v1-pod,mutating=false,failurePolicy=fail,sideEffects=None,groups="",resources=pods,verbs=create;update,versions=v1,name=vpod.kb.io,sideEffects=None,admissionReviewVersions=v1
5355

5456
// validate admits a pod if a specific annotation exists.
55-
func (p *PodWebhook) validate(ctx context.Context, pod *corev1.Pod) (admission.Warnings, error) {
57+
func (p *PodWebhook) validate(ctx context.Context, obj runtime.Object) (admission.Warnings, error) {
5658
log := logf.FromContext(ctx)
59+
pod, ok := obj.(*corev1.Pod)
60+
if !ok {
61+
return nil, fmt.Errorf("expected a Pod but got a %T", obj)
62+
}
5763

5864
log.V(2).Info("Validating Pod")
5965

@@ -66,22 +72,26 @@ func (p *PodWebhook) validate(ctx context.Context, pod *corev1.Pod) (admission.W
6672
return nil, nil
6773
}
6874

69-
func (p *PodWebhook) ValidateCreate(ctx context.Context, pod *corev1.Pod) (admission.Warnings, error) {
70-
return p.validate(ctx, pod)
75+
func (p *PodWebhook) ValidateCreate(ctx context.Context, obj runtime.Object) (admission.Warnings, error) {
76+
return p.validate(ctx, obj)
7177
}
7278

73-
func (p *PodWebhook) ValidateUpdate(ctx context.Context, oldObj, newObj *corev1.Pod) (admission.Warnings, error) {
79+
func (p *PodWebhook) ValidateUpdate(ctx context.Context, oldObj, newObj runtime.Object) (admission.Warnings, error) {
7480
return nil, nil
7581
}
7682

77-
func (p *PodWebhook) ValidateDelete(ctx context.Context, pod *corev1.Pod) (admission.Warnings, error) {
83+
func (p *PodWebhook) ValidateDelete(ctx context.Context, obj runtime.Object) (admission.Warnings, error) {
7884
return nil, nil
7985
}
8086

8187
//+kubebuilder:webhook:path=/mutate--v1-pod,mutating=true,failurePolicy=fail,groups="",resources=pods,verbs=create,versions=v1,name=mpod.kb.io,sideEffects=None,admissionReviewVersions=v1
8288

83-
func (p *PodWebhook) Default(ctx context.Context, pod *corev1.Pod) error {
89+
func (p *PodWebhook) Default(ctx context.Context, obj runtime.Object) error {
8490
log := logf.FromContext(ctx)
91+
pod, ok := obj.(*corev1.Pod)
92+
if !ok {
93+
return fmt.Errorf("expected a Pod but got a %T", obj)
94+
}
8595

8696
log.V(2).Info("Defaulting Pod")
8797
// if pod is not part of leaderworkerset, skip

test/e2e/e2e_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ var _ = ginkgo.Describe("leaderWorkerSet e2e tests", func() {
166166

167167
ginkgo.It("Can perform a rolling update even if old lws not ready", func() {
168168
// Create lws with not exist image.
169-
lws := wrappers.BuildLeaderWorkerSet(ns.Name).LeaderTemplate(nil).Size(1).Replica(2).MaxSurge(1).MaxUnavailable(0).Obj()
169+
lws := wrappers.BuildLeaderWorkerSet(ns.Name).LeaderTemplate(nil).Size(1).Replica(2).MaxSurge(1).MaxUnavailable(1).Obj()
170170
lws.Spec.LeaderWorkerTemplate.WorkerTemplate.Spec.Containers[0].Image = "not-exist-image:v1"
171171
testing.MustCreateLws(ctx, k8sClient, lws)
172172

test/integration/controllers/suite_test.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,16 +104,14 @@ var _ = BeforeSuite(func() {
104104
})
105105
Expect(err).ToNot(HaveOccurred())
106106

107-
// TODO: Deprecated: this uses the old events API and will be removed in a future release. Please use GetEventRecorder instead.
108-
lwsController := controllers.NewLeaderWorkerSetReconciler(k8sManager.GetClient(), k8sManager.GetScheme(), k8sManager.GetEventRecorderFor("leaderworkerset")) // nolint
107+
lwsController := controllers.NewLeaderWorkerSetReconciler(k8sManager.GetClient(), k8sManager.GetScheme(), k8sManager.GetEventRecorderFor("leaderworkerset"))
109108

110109
err = controllers.SetupIndexes(k8sManager.GetFieldIndexer())
111110
Expect(err).ToNot(HaveOccurred())
112111
err = lwsController.SetupWithManager(k8sManager)
113112
Expect(err).ToNot(HaveOccurred())
114113

115-
// TODO: Deprecated: this uses the old events API and will be removed in a future release. Please use GetEventRecorder instead.
116-
podController = controllers.NewPodReconciler(k8sManager.GetClient(), k8sManager.GetScheme(), k8sManager.GetEventRecorderFor("pod"), nil) // nolint
114+
podController = controllers.NewPodReconciler(k8sManager.GetClient(), k8sManager.GetScheme(), k8sManager.GetEventRecorderFor("pod"), nil)
117115
err = podController.SetupWithManager(k8sManager)
118116
Expect(err).ToNot(HaveOccurred())
119117

0 commit comments

Comments
 (0)