From df3ab67a699d2bc4e46a8c2aea4fd95b9df66172 Mon Sep 17 00:00:00 2001 From: Hardy Date: Tue, 10 Sep 2019 17:57:31 +0800 Subject: [PATCH] Add a example for union operator in the shell env MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In the current example, single quotes are used, but the union operator can be confusing. Incorrect: `kubectl get pod -o=jsonpath='{.items[*]['metadata.name','spec.nodeName']}'` Correct: `kubectl get pods -o=jsonpath="{.items[*]['metadata.name', 'status.capacity']}"` --- content/en/docs/reference/kubectl/jsonpath.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/content/en/docs/reference/kubectl/jsonpath.md b/content/en/docs/reference/kubectl/jsonpath.md index 457129e315657..f684a34dffdec 100644 --- a/content/en/docs/reference/kubectl/jsonpath.md +++ b/content/en/docs/reference/kubectl/jsonpath.md @@ -72,7 +72,7 @@ Function | Description | Example `.` or `[]` | child operator | `{.kind}` or `{['kind']}` | `List` `..` | recursive descent | `{..name}` | `127.0.0.1 127.0.0.2 myself e2e` `*` | wildcard. Get all objects | `{.items[*].metadata.name}` | `[127.0.0.1 127.0.0.2]` -`[start:end :step]` | subscript operator | `{.users[0].name}` | `myself` +`[start:end:step]` | subscript operator | `{.users[0].name}` | `myself` `[,]` | union operator | `{.items[*]['metadata.name', 'status.capacity']}` | `127.0.0.1 127.0.0.2 map[cpu:4] map[cpu:8]` `?()` | filter | `{.users[?(@.name=="e2e")].user.password}` | `secret` `range`, `end` | iterate list | `{range .items[*]}[{.metadata.name}, {.status.capacity}] {end}` | `[127.0.0.1, map[cpu:4]] [127.0.0.2, map[cpu:8]]` @@ -85,6 +85,7 @@ kubectl get pods -o json kubectl get pods -o=jsonpath='{@}' kubectl get pods -o=jsonpath='{.items[0]}' kubectl get pods -o=jsonpath='{.items[0].metadata.name}' +kubectl get pods -o=jsonpath="{.items[*]['metadata.name', 'status.capacity']}" kubectl get pods -o=jsonpath='{range .items[*]}{.metadata.name}{"\t"}{.status.startTime}{"\n"}{end}' ```