kubectl: fix wait --for=create to work correctly with label selectors (#128662)

* kubectl: fix wait --for=create to work correctly with label selectors

Signed-off-by: Omer Aplatony <omerap12@gmail.com>

* Add unit test

Signed-off-by: Omer Aplatony <omerap12@gmail.com>

* add integration test

Signed-off-by: Omer Aplatony <omerap12@gmail.com>

* Increase wait time to 40 seconds

Signed-off-by: Omer Aplatony <omerap12@gmail.com>

---------

Signed-off-by: Omer Aplatony <omerap12@gmail.com>

Kubernetes-commit: 0cc926220067cd814cecd8f3d0c3b9235e6a68db
This commit is contained in:
Omer Aplatony 2024-12-12 04:57:28 +02:00 committed by Kubernetes Publisher
parent 92bb3cdeda
commit 56c9d286fe
3 changed files with 6 additions and 4 deletions

2
go.mod
View File

@ -32,7 +32,7 @@ require (
golang.org/x/sys v0.26.0
gopkg.in/evanphx/json-patch.v4 v4.12.0
k8s.io/api v0.0.0-20241206182100-8b216f34d7ed
k8s.io/apimachinery v0.0.0-20241206181643-8c60292e48e4
k8s.io/apimachinery v0.0.0-20241212054420-6e120e1a46e1
k8s.io/cli-runtime v0.0.0-20241206192854-f6c5161ff902
k8s.io/client-go v0.0.0-20241206182637-8e21410d16a5
k8s.io/component-base v0.0.0-20241206184758-96018783480f

4
go.sum
View File

@ -204,8 +204,8 @@ gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
k8s.io/api v0.0.0-20241206182100-8b216f34d7ed h1:I/5qfHM86vTbxgBF5ndeCJyTDVoJy/rZL6bSse/9DFU=
k8s.io/api v0.0.0-20241206182100-8b216f34d7ed/go.mod h1:lUM9fsfbAc6N6JbIwnis087wfRQs4x/1VDpNyw4Un6c=
k8s.io/apimachinery v0.0.0-20241206181643-8c60292e48e4 h1:c4XtWsfwbNtBf5CEhvo2EX7nqVrObhWkSyGrpvrNw3o=
k8s.io/apimachinery v0.0.0-20241206181643-8c60292e48e4/go.mod h1:GpHVgxoKlTxClKcteaeuF1Ul/lDVb74KpZcxcmLDElE=
k8s.io/apimachinery v0.0.0-20241212054420-6e120e1a46e1 h1:80IlEOFbCKCnZZRkwjGP5TPx7Nvx5UyhR7ihknEcJhU=
k8s.io/apimachinery v0.0.0-20241212054420-6e120e1a46e1/go.mod h1:GpHVgxoKlTxClKcteaeuF1Ul/lDVb74KpZcxcmLDElE=
k8s.io/cli-runtime v0.0.0-20241206192854-f6c5161ff902 h1:LlS8236wfzD58/D2/kDKmJ0qs8s2IzTwRaCO0h0wFhM=
k8s.io/cli-runtime v0.0.0-20241206192854-f6c5161ff902/go.mod h1:/eNxaLgPb/QGUSS0N9OBoOwU6OOlvN/tg1j82fiwc0o=
k8s.io/client-go v0.0.0-20241206182637-8e21410d16a5 h1:jFY2Dq4WCHUiLhVH1tUVGSnasQfC1GKLb0XS82M8SuA=

View File

@ -329,7 +329,9 @@ func (o *WaitOptions) RunWait() error {
// or functions from ResourceBuilder for parsing those. Lastly, this poll
// should be replaced with a ListWatch cache.
if err := wait.PollUntilContextTimeout(ctx, 500*time.Millisecond, o.Timeout, true, func(context.Context) (done bool, err error) {
foundResource := false
visitErr := o.ResourceFinder.Do().Visit(func(info *resource.Info, err error) error {
foundResource = true
return nil
})
if apierrors.IsNotFound(visitErr) {
@ -338,7 +340,7 @@ func (o *WaitOptions) RunWait() error {
if visitErr != nil {
return false, visitErr
}
return true, nil
return foundResource, nil
}); err != nil {
if errors.Is(err, context.DeadlineExceeded) {
return fmt.Errorf("%s", wait.ErrWaitTimeout.Error()) // nolint:staticcheck // SA1019