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
Conversation
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. |
There was a problem hiding this 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!
if strings.Contains(err.Error(), "is not found") { // TODO(jonyhy96) change this to error assertion when client-go support. | ||
return false, nil | ||
} |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
/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) |
There was a problem hiding this comment.
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
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great point!
/retest |
There was a problem hiding this 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)
Since you reviewed the original PR. /cc seans3 dims |
/cc @mpuckett159 @soltysh |
@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:
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' |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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,'
There was a problem hiding this comment.
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
/assign @eddiezane |
/assign |
Yea, good call. For people who use workaround like 'until kubectl wait' would definitely see unexpected changes - longer wait time.
I have informed Eddie so he can voice his opinions on this. Thanks!
…On Jun 28, 2022, 23:38 -0400, Marcus Puckett ***@***.***>, wrote:
@mpuckett159 commented on this pull request.
In staging/src/k8s.io/kubectl/pkg/cmd/wait/wait_test.go:
> @@ -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",
Sorry by middle ground I just meant keep the default for the command the way it is so it doesn't potentially break anything for downstream users, and add a flag that users can use to ignore missing keys, so that we basically enable both options. It would serve to both ensure no unexpected changes for downstream users and act as a kind of guard against users potentially adding a path to a key that doesn't exist unless they specifically are ok with it being missing.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you were assigned.Message ID: ***@***.***>
|
Signed-off-by: jonyhy96 <hy352144278@gmail.com>
/assign @eddiezane @soltysh |
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! |
i hope so @neoaggelos :) |
please let me known if any updates i should made to push this forward! /cc @ardaguclu @lauchokyip @pierDipi |
@jonyhy96 I think we would have to wait for more reviewers/approvers to get this things going |
There was a problem hiding this 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", |
There was a problem hiding this comment.
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.
[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 |
Fixes kubernetes/kubectl#1204 |
/triage accepted |
/remove-label kind/api-change |
@soltysh: The label(s) In response to this:
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. |
/retest |
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?