mirror of
https://github.com/kubernetes/kubectl.git
synced 2026-06-08 16:23:21 -04:00
feat: make jsonpath wait logics consistent with condition
Signed-off-by: jonyhy96 <hy352144278@gmail.com> Kubernetes-commit: 7a1493be5679ed3ec85b7fdef685c7e6b580e8e4
This commit is contained in:
parent
8e2918ab8b
commit
1906bda541
2 changed files with 5 additions and 5 deletions
|
|
@ -229,7 +229,7 @@ func conditionFuncFor(condition string, errOut io.Writer) (ConditionFunc, error)
|
|||
|
||||
// newJSONPathParser will create a new JSONPath parser based on the jsonPathExpression
|
||||
func newJSONPathParser(jsonPathExpression string) (*jsonpath.JSONPath, error) {
|
||||
j := jsonpath.New("wait")
|
||||
j := jsonpath.New("wait").AllowMissingKeys(true)
|
||||
if jsonPathExpression == "" {
|
||||
return nil, errors.New("jsonpath expression cannot be empty")
|
||||
}
|
||||
|
|
@ -624,6 +624,9 @@ func (j JSONPathWait) checkCondition(obj *unstructured.Unstructured) (bool, erro
|
|||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
if len(parseResults) == 0 || len(parseResults[0]) == 0 {
|
||||
return false, nil
|
||||
}
|
||||
if err := verifyParsedJSONPath(parseResults); err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
|
@ -637,9 +640,6 @@ func (j JSONPathWait) checkCondition(obj *unstructured.Unstructured) (bool, erro
|
|||
// verifyParsedJSONPath verifies the JSON received from the API server is valid.
|
||||
// It will only accept a single JSON
|
||||
func verifyParsedJSONPath(results [][]reflect.Value) error {
|
||||
if len(results) == 0 {
|
||||
return errors.New("given jsonpath expression does not match any value")
|
||||
}
|
||||
if len(results) > 1 {
|
||||
return errors.New("given jsonpath expression matches more than one list")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1043,7 +1043,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",
|
||||
},
|
||||
{
|
||||
name: "compare boolean JSONPath entry",
|
||||
|
|
|
|||
Loading…
Reference in a new issue