Skip to content

Commit 98058a1

Browse files
committed
Fix the flaky kubectl tests at scale
1 parent 3e2ae63 commit 98058a1

File tree

4 files changed

+3
-51
lines changed

4 files changed

+3
-51
lines changed

staging/src/k8s.io/kubectl/pkg/cmd/debug/debug.go

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -355,21 +355,6 @@ func waitForEphemeralContainer(ctx context.Context, podClient corev1client.PodsG
355355
ctx, cancel := watchtools.ContextWithOptionalTimeout(ctx, 0*time.Second)
356356
defer cancel()
357357

358-
preconditionFunc := func(store cache.Store) (bool, error) {
359-
_, exists, err := store.Get(&metav1.ObjectMeta{Namespace: ns, Name: podName})
360-
if err != nil {
361-
return true, err
362-
}
363-
if !exists {
364-
// We need to make sure we see the object in the cache before we start waiting for events
365-
// or we would be waiting for the timeout if such object didn't exist.
366-
// (e.g. it was deleted before we started informers so they wouldn't even see the delete event)
367-
return true, errors.NewNotFound(corev1.Resource("pods"), podName)
368-
}
369-
370-
return false, nil
371-
}
372-
373358
fieldSelector := fields.OneTermEqualSelector("metadata.name", podName).String()
374359
lw := &cache.ListWatch{
375360
ListFunc: func(options metav1.ListOptions) (runtime.Object, error) {
@@ -385,7 +370,7 @@ func waitForEphemeralContainer(ctx context.Context, podClient corev1client.PodsG
385370
intr := interrupt.New(nil, cancel)
386371
var result *corev1.Pod
387372
err := intr.Run(func() error {
388-
ev, err := watchtools.UntilWithSync(ctx, lw, &corev1.Pod{}, preconditionFunc, func(ev watch.Event) (bool, error) {
373+
ev, err := watchtools.UntilWithSync(ctx, lw, &corev1.Pod{}, nil, func(ev watch.Event) (bool, error) {
389374
switch ev.Type {
390375
case watch.Deleted:
391376
return false, errors.NewNotFound(schema.GroupResource{Resource: "pods"}, "")

staging/src/k8s.io/kubectl/pkg/cmd/rollout/BUILD

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ go_library(
2121
"//build/visible_to:pkg_kubectl_cmd_rollout_CONSUMERS",
2222
],
2323
deps = [
24-
"//staging/src/k8s.io/apimachinery/pkg/api/errors:go_default_library",
2524
"//staging/src/k8s.io/apimachinery/pkg/api/meta:go_default_library",
2625
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
2726
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1/unstructured:go_default_library",

staging/src/k8s.io/kubectl/pkg/cmd/rollout/rollout_status.go

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import (
2323

2424
"github.com/spf13/cobra"
2525

26-
apierrors "k8s.io/apimachinery/pkg/api/errors"
2726
"k8s.io/apimachinery/pkg/api/meta"
2827
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2928
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
@@ -200,25 +199,11 @@ func (o *RolloutStatusOptions) Run() error {
200199
},
201200
}
202201

203-
preconditionFunc := func(store cache.Store) (bool, error) {
204-
_, exists, err := store.Get(&metav1.ObjectMeta{Namespace: info.Namespace, Name: info.Name})
205-
if err != nil {
206-
return true, err
207-
}
208-
if !exists {
209-
// We need to make sure we see the object in the cache before we start waiting for events
210-
// or we would be waiting for the timeout if such object didn't exist.
211-
return true, apierrors.NewNotFound(mapping.Resource.GroupResource(), info.Name)
212-
}
213-
214-
return false, nil
215-
}
216-
217202
// if the rollout isn't done yet, keep watching deployment status
218203
ctx, cancel := watchtools.ContextWithOptionalTimeout(context.Background(), o.Timeout)
219204
intr := interrupt.New(nil, cancel)
220205
return intr.Run(func() error {
221-
_, err = watchtools.UntilWithSync(ctx, lw, &unstructured.Unstructured{}, preconditionFunc, func(e watch.Event) (bool, error) {
206+
_, err = watchtools.UntilWithSync(ctx, lw, &unstructured.Unstructured{}, nil, func(e watch.Event) (bool, error) {
222207
switch t := e.Type; t {
223208
case watch.Added, watch.Modified:
224209
status, done, err := statusViewer.Status(e.Object.(runtime.Unstructured), o.Revision)

staging/src/k8s.io/kubectl/pkg/cmd/run/run.go

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -457,21 +457,6 @@ func waitForPod(podClient corev1client.PodsGetter, ns, name string, timeout time
457457
ctx, cancel := watchtools.ContextWithOptionalTimeout(context.Background(), timeout)
458458
defer cancel()
459459

460-
preconditionFunc := func(store cache.Store) (bool, error) {
461-
_, exists, err := store.Get(&metav1.ObjectMeta{Namespace: ns, Name: name})
462-
if err != nil {
463-
return true, err
464-
}
465-
if !exists {
466-
// We need to make sure we see the object in the cache before we start waiting for events
467-
// or we would be waiting for the timeout if such object didn't exist.
468-
// (e.g. it was deleted before we started informers so they wouldn't even see the delete event)
469-
return true, errors.NewNotFound(corev1.Resource("pods"), name)
470-
}
471-
472-
return false, nil
473-
}
474-
475460
fieldSelector := fields.OneTermEqualSelector("metadata.name", name).String()
476461
lw := &cache.ListWatch{
477462
ListFunc: func(options metav1.ListOptions) (runtime.Object, error) {
@@ -487,9 +472,7 @@ func waitForPod(podClient corev1client.PodsGetter, ns, name string, timeout time
487472
intr := interrupt.New(nil, cancel)
488473
var result *corev1.Pod
489474
err := intr.Run(func() error {
490-
ev, err := watchtools.UntilWithSync(ctx, lw, &corev1.Pod{}, preconditionFunc, func(ev watch.Event) (bool, error) {
491-
return exitCondition(ev)
492-
})
475+
ev, err := watchtools.UntilWithSync(ctx, lw, &corev1.Pod{}, nil, exitCondition)
493476
if ev != nil {
494477
result = ev.Object.(*corev1.Pod)
495478
}

0 commit comments

Comments
 (0)