Skip to content

Commit df3ab67

Browse files
authored
Add a example for union operator in the shell env
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']}"`
1 parent b766893 commit df3ab67

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

content/en/docs/reference/kubectl/jsonpath.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ Function | Description | Example
7272
`.` or `[]` | child operator | `{.kind}` or `{['kind']}` | `List`
7373
`..` | recursive descent | `{..name}` | `127.0.0.1 127.0.0.2 myself e2e`
7474
`*` | wildcard. Get all objects | `{.items[*].metadata.name}` | `[127.0.0.1 127.0.0.2]`
75-
`[start:end :step]` | subscript operator | `{.users[0].name}` | `myself`
75+
`[start:end:step]` | subscript operator | `{.users[0].name}` | `myself`
7676
`[,]` | union operator | `{.items[*]['metadata.name', 'status.capacity']}` | `127.0.0.1 127.0.0.2 map[cpu:4] map[cpu:8]`
7777
`?()` | filter | `{.users[?(@.name=="e2e")].user.password}` | `secret`
7878
`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
8585
kubectl get pods -o=jsonpath='{@}'
8686
kubectl get pods -o=jsonpath='{.items[0]}'
8787
kubectl get pods -o=jsonpath='{.items[0].metadata.name}'
88+
kubectl get pods -o=jsonpath="{.items[*]['metadata.name', 'status.capacity']}"
8889
kubectl get pods -o=jsonpath='{range .items[*]}{.metadata.name}{"\t"}{.status.startTime}{"\n"}{end}'
8990
```
9091

0 commit comments

Comments
 (0)