From 5c3de9f1de913d1251ce2183991a845edc01d123 Mon Sep 17 00:00:00 2001 From: atiratree Date: Thu, 5 Aug 2021 18:39:43 +0200 Subject: [PATCH 1/2] revert "fix wrong output when using jsonpath" This partially reverts commit 39cfe232325d66bcdbc935af7aaf7022562e7010and PR #98057 the original problem was caused by not using {end} at the end of the range --- staging/src/k8s.io/client-go/util/jsonpath/jsonpath.go | 3 --- staging/src/k8s.io/client-go/util/jsonpath/jsonpath_test.go | 4 ++-- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/staging/src/k8s.io/client-go/util/jsonpath/jsonpath.go b/staging/src/k8s.io/client-go/util/jsonpath/jsonpath.go index 0b1dc338bd0..49ecd1465ae 100644 --- a/staging/src/k8s.io/client-go/util/jsonpath/jsonpath.go +++ b/staging/src/k8s.io/client-go/util/jsonpath/jsonpath.go @@ -132,9 +132,6 @@ func (j *JSONPath) FindResults(data interface{}) ([][]reflect.Value, error) { } continue } - if len(results) == 0 { - break - } fullResult = append(fullResult, results) } return fullResult, nil diff --git a/staging/src/k8s.io/client-go/util/jsonpath/jsonpath_test.go b/staging/src/k8s.io/client-go/util/jsonpath/jsonpath_test.go index 58ad938456e..c7714ee8346 100644 --- a/staging/src/k8s.io/client-go/util/jsonpath/jsonpath_test.go +++ b/staging/src/k8s.io/client-go/util/jsonpath/jsonpath_test.go @@ -806,8 +806,8 @@ func TestRunningPodsJSONPathOutput(t *testing.T) { testJSONPath( []jsonpathTest{ { - "when range is used in a certain way in script, additional line is printed", - `{range .items[?(.status.phase=="Running")]}{.metadata.name}{" is Running\n"}`, + "range over pods without selecting the last one", + `{range .items[?(.status.phase=="Running")]}{.metadata.name}{" is Running\n"}{end}`, data, "pod1 is Running\npod2 is Running\npod3 is Running\n", false, // expect no error From b79859cb12b19222fffc17481e1fe006819de63c Mon Sep 17 00:00:00 2001 From: atiratree Date: Thu, 26 Aug 2021 14:49:58 +0200 Subject: [PATCH 2/2] add a test for jsonpath template parsing to prevent regressions This behaviour was broken by commit 39cfe232325d66bcdbc935af7aaf7022562e7010 and PR kubernetes#98057 --- staging/src/k8s.io/client-go/util/jsonpath/jsonpath_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/staging/src/k8s.io/client-go/util/jsonpath/jsonpath_test.go b/staging/src/k8s.io/client-go/util/jsonpath/jsonpath_test.go index c7714ee8346..197e73e84dd 100644 --- a/staging/src/k8s.io/client-go/util/jsonpath/jsonpath_test.go +++ b/staging/src/k8s.io/client-go/util/jsonpath/jsonpath_test.go @@ -280,6 +280,7 @@ func TestStructInput(t *testing.T) { missingKeyTests := []jsonpathTest{ {"nonexistent field", "{.hello}", storeData, "", false}, + {"nonexistent field 2", "before-{.hello}after", storeData, "before-after", false}, } testJSONPath(missingKeyTests, true, t)