Skip to content

Commit

Permalink
Add a example for union operator in the shell env
Browse files Browse the repository at this point in the history
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']}"`
  • Loading branch information
hardy4yooz authored Sep 10, 2019
1 parent b766893 commit df3ab67
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion content/en/docs/reference/kubectl/jsonpath.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]]`
Expand All @@ -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}'
```

Expand Down

0 comments on commit df3ab67

Please sign in to comment.