From 86984f220ec59ebcc1e06eaa1dda7efaf64457db Mon Sep 17 00:00:00 2001 From: GoodGameZoo Date: Mon, 28 Jun 2021 00:08:05 -0700 Subject: [PATCH] Update Chinese page jsonpath --- content/zh/docs/reference/kubectl/jsonpath.md | 33 +++++++++---------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/content/zh/docs/reference/kubectl/jsonpath.md b/content/zh/docs/reference/kubectl/jsonpath.md index c1302ec3d6..9d9c82b974 100644 --- a/content/zh/docs/reference/kubectl/jsonpath.md +++ b/content/zh/docs/reference/kubectl/jsonpath.md @@ -3,7 +3,7 @@ title: JSONPath 支持 content_type: concept weight: 25 --- - Kubectl 支持 JSONPath 模板。 - JSONPath 模板由 {} 包起来的 JSONPath 表达式组成。Kubectl 使用 JSONPath 表达式来过滤 JSON 对象中的特定字段并格式化输出。除了原始的 JSONPath 模板语法,以下函数和语法也是有效的: - 1. 使用双引号将 JSONPath 表达式内的文本引起来。 2. 使用 `range`,`end` 运算符来迭代列表。 3. 使用负片索引后退列表。负索引不会“环绕”列表,并且只要 `-index + listLength> = 0` 就有效。 {{< note >}} - - `$` 运算符是可选的,因为默认情况下表达式总是从根对象开始。 @@ -48,8 +48,8 @@ JSONPath 模板由 {} 包起来的 JSONPath 表达式组成。Kubectl 使用 JSO {{< /note >}} - 给定 JSON 输入: @@ -90,7 +90,7 @@ Given the JSON input: } ``` - 函数 | 描述 | 示例 | 结果 --------------------|---------------------------|-----------------------------------------------------------------|------------------ @@ -117,8 +117,8 @@ Function | Description | Example `range`, `end` | 迭代列表 | `{range .items[*]}[{.metadata.name}, {.status.capacity}] {end}` | `[127.0.0.1, map[cpu:4]] [127.0.0.2, map[cpu:8]]` `''` | 引用解释执行字符串 | `{range .items[*]}{.metadata.name}{'\t'}{end}` | `127.0.0.1 127.0.0.2` - 使用 `kubectl` 和 JSONPath 表达式的示例: @@ -131,7 +131,7 @@ kubectl get pods -o=jsonpath="{.items[*]['metadata.name', 'status.capacity']}" kubectl get pods -o=jsonpath='{range .items[*]}{.metadata.name}{"\t"}{.status.startTime}{"\n"}{end}' ``` - {{< note >}} -在 Windows 上,您必须用双引号把任何包含空格的 JSONPath 模板(不是上面 bash 所示的单引号)。 +在 Windows 上,对于任何包含空格的 JSONPath 模板,您必须使用双引号(不是上面 bash 所示的单引号)。 反过来,这意味着您必须在模板中的所有文字周围使用单引号或转义的双引号。 例如: @@ -176,4 +176,3 @@ kubectl get pods -o jsonpath='{.items[?(@.metadata.name=~/^test$/)].metadata.nam kubectl get pods -o json | jq -r '.items[] | select(.metadata.name | test("test-")).spec.containers[].image' ``` {{< /note >}} -