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

feat: make jsonpath wait logics consistent with condition #109525

Merged
merged 1 commit into from Oct 30, 2022

Conversation

jonyhy96
Copy link
Contributor

@jonyhy96 jonyhy96 commented Apr 18, 2022

What type of PR is this?

/kind feature

What this PR does / why we need it:

Keep the behavior of jsonpath and condition consistent.

Which issue(s) this PR fixes:

Fixes kubernetes/kubectl#1236

Special notes for your reviewer:

Does this PR introduce a user-facing change?

kubectl wait command with jsonpath flag will wait for target path appear until timeout.

@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. kind/feature Categorizes issue or PR as related to a new feature. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. labels Apr 18, 2022
@k8s-ci-robot k8s-ci-robot added area/kubectl sig/cli Categorizes an issue or PR as relevant to SIG CLI. and removed do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Apr 18, 2022
@k8s-triage-robot
Copy link

This PR may require API review.

If so, when the changes are ready, complete the pre-review checklist and request an API review.

Status of requested reviews is tracked in the API Review project.

Copy link

@pierDipi pierDipi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the patch!

Comment on lines 590 to 592
if strings.Contains(err.Error(), "is not found") { // TODO(jonyhy96) change this to error assertion when client-go support.
return false, nil
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than parsing the error string, did you consider using AllowMissingKeys and then when len(parseResults) == 0 we can return false, nil instead of an error?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! Thanks for advice, then we can remove that todo.

@jonyhy96
Copy link
Contributor Author

/retest

@@ -585,10 +585,14 @@ func (j JSONPathWait) isJSONPathConditionMet(event watch.Event) (bool, error) {
// and check if it matches the desired condition
func (j JSONPathWait) checkCondition(obj *unstructured.Unstructured) (bool, error) {
queryObj := obj.UnstructuredContent()
j.jsonPathParser.AllowMissingKeys(true)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would call AllowMissingKeys(true) when we create the parser [1] [2] since it changes the internal state of the parser and might produce unexpected side effects.

I wouldn't expect that x and y might be different in this case:

x, _ := j.jsonPathParser.FindResults(obj.UnstructuredContent())
j.checkCondition(obj)
y, _ := j.jsonPathParser.FindResults(obj.UnstructuredContent())

[1]

func newJSONPathParser(jsonPathExpression string) (*jsonpath.JSONPath, error) {
	j := jsonpath.New("wait").AllowMissingKeys(true)
	if jsonPathExpression == "" {
		return nil, errors.New("jsonpath expression cannot be empty")
	}
	if err := j.Parse(jsonPathExpression); err != nil {
		return nil, err
	}
	return j, nil
}

[2] https://github.com/kubernetes/kubernetes/blob/9c0eaddf121d91863b70b03cb408a7249b882e5e/staging/src/k8s.io/kubectl/pkg/cmd/wait/wait.go#L229-L238

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great point!

@k8s-ci-robot k8s-ci-robot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Apr 19, 2022
@jonyhy96
Copy link
Contributor Author

/retest

Copy link

@pierDipi pierDipi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the patch, LGTM.

(note: I'm not a reviewer or approver, so we need someone from the SIG for a review)

@pierDipi
Copy link

Since you reviewed the original PR.

/cc seans3 dims

@jonyhy96
Copy link
Contributor Author

PTAL @seans3 @dims

@pierDipi
Copy link

/cc @mpuckett159 @soltysh

@k8s-ci-robot
Copy link
Contributor

@pierDipi: GitHub didn't allow me to request PR reviews from the following users: mpuckett159.

Note that only kubernetes members and repo collaborators can review this PR, and authors cannot review their own PRs.

In response to this:

/cc @mpuckett159 @soltysh

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.

output_message=$(kubectl wait --for=jsonpath=.status.readyReplicas=1 deploy/test-1)

# Post-Condition: Wait failed
kube::test::if_has_string "${output_message}" 'timed out'
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't we expect condition met?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Busybox deploy will never be ready.
Change image to nginx will reach condition met, already test locally but not work as expect when running on k8s ci.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm what if the test above failed?

kube::test::get_object_assert "deployments" "{{range .items}}{{.metadata.name}},{{end}}" 'test-1,test-2,'

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm what if the test above failed?

kube::test::get_object_assert "deployments" "{{range .items}}{{.metadata.name}},{{end}}" 'test-1,test-2,'

updated

@dims
Copy link
Member

dims commented Jun 1, 2022

/assign @eddiezane

@lauchokyip
Copy link
Member

/assign

@lauchokyip
Copy link
Member

lauchokyip commented Jun 29, 2022 via email

Signed-off-by: jonyhy96 <hy352144278@gmail.com>
@dims
Copy link
Member

dims commented Aug 23, 2022

/assign @eddiezane @soltysh
/milestone v1.26

@k8s-ci-robot k8s-ci-robot added this to the v1.26 milestone Aug 23, 2022
@neoaggelos
Copy link

Hi @dims, 1.26 bug triage team here, just wanted to check whether this Is this still on track for the 1.26 milestone.

Thank you!

@dims
Copy link
Member

dims commented Oct 5, 2022

i hope so @neoaggelos :)

@jonyhy96
Copy link
Contributor Author

jonyhy96 commented Oct 8, 2022

please let me known if any updates i should made to push this forward! /cc @ardaguclu @lauchokyip @pierDipi

@lauchokyip
Copy link
Member

@jonyhy96 I think we would have to wait for more reviewers/approvers to get this things going

Copy link
Contributor

@soltysh soltysh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm
/approve

@@ -1173,7 +1173,7 @@ func TestWaitForDifferentJSONPathExpression(t *testing.T) {
jsonPathExp: "{.foo.bar}",
jsonPathCond: "baz",

expectedErr: "foo is not found",
expectedErr: "timed out waiting for the condition on theresource/foo-b6699dcfb-rnv7t",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The middle ground would only apply to jsonpath, b/c as mentioned in the original issue that is possible when waiting for conditions already, so I'm considering this more like a bug, and aligning the functionality at this time.

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Oct 30, 2022
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: jonyhy96, pierDipi, soltysh

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Oct 30, 2022
@soltysh
Copy link
Contributor

soltysh commented Oct 30, 2022

Fixes kubernetes/kubectl#1204

@soltysh
Copy link
Contributor

soltysh commented Oct 30, 2022

/triage accepted
/priority important-longterm

@k8s-ci-robot k8s-ci-robot added triage/accepted Indicates an issue or PR is ready to be actively worked on. priority/important-longterm Important over the long term, but may not be staffed and/or may need multiple releases to complete. and removed needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. labels Oct 30, 2022
@soltysh
Copy link
Contributor

soltysh commented Oct 30, 2022

/remove-label kind/api-change

@k8s-ci-robot
Copy link
Contributor

@soltysh: The label(s) /remove-label kind/api-change cannot be applied. These labels are supported: api-review, tide/merge-method-merge, tide/merge-method-rebase, tide/merge-method-squash, team/katacoda, refactor, official-cve-feed. Is this label configured under labels -> additional_labels or labels -> restricted_labels in plugin.yaml?

In response to this:

/remove-label kind/api-change

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.

@pacoxu
Copy link
Member

pacoxu commented Oct 30, 2022

/retest

@k8s-ci-robot k8s-ci-robot merged commit 526650f into kubernetes:master Oct 30, 2022
@jonyhy96 jonyhy96 deleted the feat-wait branch November 1, 2022 05:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. area/kubectl area/test cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API kind/feature Categorizes issue or PR as related to a new feature. lgtm "Looks good to me", indicates that a PR is ready to be merged. priority/important-longterm Important over the long term, but may not be staffed and/or may need multiple releases to complete. release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/cli Categorizes an issue or PR as relevant to SIG CLI. sig/testing Categorizes an issue or PR as relevant to SIG Testing. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. triage/accepted Indicates an issue or PR is ready to be actively worked on.
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

kubectl wait with jsonpath fails when field is not found