Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kubectl wait with jsonpath fails when field is not found #1236

Closed
pierDipi opened this issue Apr 14, 2022 · 10 comments · Fixed by kubernetes/kubernetes#109525
Closed

kubectl wait with jsonpath fails when field is not found #1236

pierDipi opened this issue Apr 14, 2022 · 10 comments · Fixed by kubernetes/kubernetes#109525
Assignees
Labels
kind/bug Categorizes issue or PR as related to a bug. sig/cli Categorizes an issue or PR as relevant to SIG CLI. triage/accepted Indicates an issue or PR is ready to be actively worked on.

Comments

@pierDipi
Copy link

pierDipi commented Apr 14, 2022

What happened?

Waiting for a field to be set on a resource using --for=jsonpath= fails when the field is not found.

kubectl wait brokers -n knative-eventing  --timeout 300s --for=jsonpath='{.status.state}'=https://example.com
error: state is not found

What did you expect to happen?

The jsonpath syntax behaves differently when compared to --for=condition= since this:

kubectl wait deployment <deployment_name> --timeout 300s --for=condition=Nope=True

waits even when there is no condition called Nope.

In addition, waiting on status fields that are set asynchronously is really useful, so the usual flow of creating and waiting for a resource to have a specific field isn't reliably solvable with this error thrown.

How can we reproduce it (as minimally and precisely as possible)?

Run:

$ kubectl create deployment nginx --image=nginx; kubectl wait --for=jsonpath='{.status.readyReplicas}'=1 deploy/nginx
deployment.apps/nginx created
error: readyReplicas is not found

Anything else we need to know?

I see a test with this behavior [1], however, I think it's not consistent with the existing wait behavior.

[1] https://github.com/kubernetes/kubernetes/blob/10dcc6c5f44a0607881cd2f3bd5c4d80f61ad120/staging/src/k8s.io/kubectl/pkg/cmd/wait/wait_test.go#L1167-L1176

Kubernetes version

$ kubectl version
Client Version: version.Info{Major:"1", Minor:"23", GitVersion:"v1.23.5", GitCommit:"c285e781331a3785a7f436042c65c5641ce8a9e9", GitTreeState:"clean", BuildDate:"2022-03-16T15:58:47Z", GoVersion:"go1.17.8", Compiler:"gc", Platform:"linux/amd64"}

Server Version: version.Info{Major:"1", Minor:"23", GitVersion:"v1.23.3", GitCommit:"816c97ab8cff8a1c72eccca1026f7820e93e0d25", GitTreeState:"clean", BuildDate:"2022-01-26T08:02:07Z", GoVersion:"go1.17.6", Compiler:"gc", Platform:"linux/amd64"}

Cloud provider

N/A

OS version

NAME="Fedora Linux"
VERSION="35 (Workstation Edition)"
ID=fedora
VERSION_ID=35
VERSION_CODENAME=""
PLATFORM_ID="platform:f35"
PRETTY_NAME="Fedora Linux 35 (Workstation Edition)"
ANSI_COLOR="0;38;2;60;110;180"
LOGO=fedora-logo-icon
CPE_NAME="cpe:/o:fedoraproject:fedora:35"
HOME_URL="https://fedoraproject.org/"
DOCUMENTATION_URL="https://docs.fedoraproject.org/en-US/fedora/f35/system-administrators-guide/"
SUPPORT_URL="https://ask.fedoraproject.org/"
BUG_REPORT_URL="https://bugzilla.redhat.com/"
REDHAT_BUGZILLA_PRODUCT="Fedora"
REDHAT_BUGZILLA_PRODUCT_VERSION=35
REDHAT_SUPPORT_PRODUCT="Fedora"
REDHAT_SUPPORT_PRODUCT_VERSION=35
PRIVACY_POLICY_URL="https://fedoraproject.org/wiki/Legal:PrivacyPolicy"
VARIANT="Workstation Edition"
VARIANT_ID=workstation

Install tools

N/A

Container runtime (CRI) and version (if applicable)

N/A

Related plugins (CNI, CSI, ...) and versions (if applicable)

N/A
@pierDipi pierDipi added the kind/bug Categorizes issue or PR as related to a bug. label Apr 14, 2022
@k8s-ci-robot k8s-ci-robot added the needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. label Apr 14, 2022
@k8s-ci-robot
Copy link
Contributor

@pierDipi: This issue is currently awaiting triage.

If a SIG or subproject determines this is a relevant issue, they will accept it by applying the triage/accepted label and provide further guidance.

The triage/accepted label can be added by org members by writing /triage accepted in a comment.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@k8s-ci-robot k8s-ci-robot added the needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. label Apr 14, 2022
@pierDipi
Copy link
Author

/sig cli

@k8s-ci-robot k8s-ci-robot added sig/cli Categorizes an issue or PR as relevant to SIG CLI. and removed needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Apr 14, 2022
@jonyhy96
Copy link
Contributor

I think it's not consistent with the existing wait behavior.

Could u please explain this more? IMO, If the field is not exist, wait will return field is not found just like the test.

@pierDipi
Copy link
Author

pierDipi commented Apr 15, 2022

Currently, waiting on a condition with

kubectl wait deployment <deployment_name> --timeout 300s --for=condition=Nope=True

waits even when the condition Nope doesn't exist, while waiting on a custom field with jsonpath like:

kubectl wait <my_crd> <name> --timeout 300s --for=jsonpath='{.status.state}'=https://example.com

fails immediately when .status.state doesn't exist which defeats the purpose of waiting for a specific value that is set asynchronously.

@pierDipi
Copy link
Author

Example use case where the wait with jsonpath fails immediately:

$ kubectl create deployment nginx --image=nginx; kubectl wait --for=jsonpath='{.status.readyReplicas}'=1 deploy/nginx
deployment.apps/nginx created
error: readyReplicas is not found

instead with condition it waits even when the condition doesn't exist:

kubectl create deployment nginx --image=nginx; kubectl wait --for=condition=Available=True deploy/nginx
deployment.apps/nginx created
deployment.apps/nginx condition met

@jonyhy96
Copy link
Contributor

I think this is more like a feature which keep the behavior of both logics consistent.
I'm interest in implementing this.
/assign

@jonyhy96
Copy link
Contributor

Already implement this and test locally.

kubectl create deployment nginx --image=nginx; kubectl wait --for=jsonpath=.status.readyReplicas=1 deploy/nginx
deployment.apps/nginx created
deployment.apps/nginx condition met

For fileds that not exist, will return timeout.

pierDipi referenced this issue in pierDipi/eventing-hyperfoil-benchmark May 31, 2022
Signed-off-by: Pierangelo Di Pilato <pierdipi@redhat.com>
pierDipi referenced this issue in pierDipi/eventing-hyperfoil-benchmark Jun 6, 2022
Signed-off-by: Pierangelo Di Pilato <pierdipi@redhat.com>
pierDipi referenced this issue in pierDipi/eventing-hyperfoil-benchmark Jun 6, 2022
Signed-off-by: Pierangelo Di Pilato <pierdipi@redhat.com>
pierDipi referenced this issue in pierDipi/eventing-hyperfoil-benchmark Jun 6, 2022
Signed-off-by: Pierangelo Di Pilato <pierdipi@redhat.com>
openshift-merge-robot referenced this issue in openshift-knative/eventing-hyperfoil-benchmark Jun 7, 2022
* Add Kafka Broker generator

Signed-off-by: Pierangelo Di Pilato <pierdipi@redhat.com>

* Generate some tests

Signed-off-by: Pierangelo Di Pilato <pierdipi@redhat.com>

* Scale machinesets

Signed-off-by: Pierangelo Di Pilato <pierdipi@redhat.com>

* Introduce a Kafka Broker/Trigger generator

Signed-off-by: Pierangelo Di Pilato <pierdipi@redhat.com>

* Update nightlies - ./bin/update-nightlies.sh

Signed-off-by: Pierangelo Di Pilato <pierdipi@redhat.com>

* Adjust resource requests and limits

Signed-off-by: Pierangelo Di Pilato <pierdipi@redhat.com>

* Use hyperfoil snapshot version

Signed-off-by: Pierangelo Di Pilato <pierdipi@redhat.com>

* Add workaround for kubernetes/kubernetes#109489

Signed-off-by: Pierangelo Di Pilato <pierdipi@redhat.com>

* Test hyperfoil route connection

Signed-off-by: Pierangelo Di Pilato <pierdipi@redhat.com>

* Use Dict instead of dict

Signed-off-by: Pierangelo Di Pilato <pierdipi@redhat.com>

* Avoid using python 3.9 APIs

Signed-off-by: Pierangelo Di Pilato <pierdipi@redhat.com>

* Scale Kafka broker deployments

Signed-off-by: Pierangelo Di Pilato <pierdipi@redhat.com>

* Remove duplicate scale machineset

Signed-off-by: Pierangelo Di Pilato <pierdipi@redhat.com>

* Fix scale deployment

Signed-off-by: Pierangelo Di Pilato <pierdipi@redhat.com>
@lauchokyip
Copy link
Member

/transfer kubectl

@k8s-ci-robot k8s-ci-robot transferred this issue from kubernetes/kubernetes Jun 28, 2022
@lauchokyip
Copy link
Member

/triage accepted

@k8s-ci-robot k8s-ci-robot added triage/accepted Indicates an issue or PR is ready to be actively worked on. and removed needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Jun 28, 2022
@zevisert
Copy link

zevisert commented Sep 2, 2022

This might be a duplicate of #1204

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Categorizes issue or PR as related to a bug. sig/cli Categorizes an issue or PR as relevant to SIG CLI. triage/accepted Indicates an issue or PR is ready to be actively worked on.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants