Skip to content

Commit b2e1629

Browse files
authored
Merge pull request #45990 from windsonsea/apiext
[zh] Add trans to api-extension/custom-resources.md
2 parents bf1a9b2 + 0fe51a8 commit b2e1629

File tree

2 files changed

+109
-0
lines changed

2 files changed

+109
-0
lines changed

content/zh-cn/docs/concepts/extend-kubernetes/api-extension/custom-resources.md

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,79 @@ Kubernetes [客户端库](/zh-cn/docs/reference/using-api/client-libraries/)可
592592
- 使用 [Kubernetes 客户端生成工具](https://github.com/kubernetes/code-generator)所生成的客户端。
593593
生成客户端的工作有些难度,不过某些项目可能会随着 CRD 或聚合 API 一起提供一个客户端。
594594

595+
<!--
596+
## Custom resource field selectors
597+
598+
[Field Selectors](/docs/concepts/overview/working-with-objects/field-selectors/)
599+
let clients select custom resources based on the value of one or more resource
600+
fields.
601+
-->
602+
## 定制资源字段选择算符 {#custom-resource-field-selectors}
603+
604+
[字段选择算符](/zh-cn/docs/concepts/overview/working-with-objects/field-selectors/)允许客户端根据一个或多个资源字段的值选择定制资源。
605+
606+
<!--
607+
All custom resources support the `metadata.name` and `metadata.namespace` field
608+
selectors.
609+
610+
Fields declared in a {{< glossary_tooltip term_id="CustomResourceDefinition" text="CustomResourceDefinition" >}}
611+
may also be used with field selectors when included in the `spec.versions[*].selectableFields` field of the
612+
{{< glossary_tooltip term_id="CustomResourceDefinition" text="CustomResourceDefinition" >}}.
613+
-->
614+
所有定制资源都支持 `metadata.name``metadata.namespace` 字段选择算符。
615+
616+
当 {{< glossary_tooltip term_id="CustomResourceDefinition" text="CustomResourceDefinition" >}}
617+
中声明的字段包含在 {{< glossary_tooltip term_id="CustomResourceDefinition" text="CustomResourceDefinition" >}}
618+
`spec.versions[*].selectableFields` 字段中时,也可以与字段选择算符一起使用。
619+
620+
<!--
621+
### Selectable fields for custom resources {#crd-selectable-fields}
622+
-->
623+
### 定制资源的可选择字段 {#crd-selectable-fields}
624+
625+
{{< feature-state feature_gate_name="CustomResourceFieldSelectors" >}}
626+
627+
<!--
628+
You need to enable the `CustomResourceFieldSelectors`
629+
[feature gate](/docs/reference/command-line-tools-reference/feature-gates/) to
630+
use this behavior, which then applies to all CustomResourceDefinitions in your
631+
cluster.
632+
633+
The `spec.versions[*].selectableFields` field of a {{< glossary_tooltip term_id="CustomResourceDefinition" text="CustomResourceDefinition" >}} may be used to
634+
declare which other fields in a custom resource may be used in field selectors.
635+
The following example adds the `.spec.color` and `.spec.size` fields as
636+
selectable fields.
637+
-->
638+
你需要启用 `CustomResourceFieldSelectors`
639+
[特性门控](/zh-cn/docs/reference/command-line-tools-reference/feature-gates/)
640+
来使用此行为,然后将其应用到集群中的所有 CustomResourceDefinitions。
641+
642+
{{< glossary_tooltip term_id="CustomResourceDefinition" text="CustomResourceDefinition" >}}
643+
`spec.versions[*].selectableFields` 字段可以用来声明可以在字段选择算符中使用定制资源中的其他哪些字段。
644+
以下示例将 `.spec.color``.spec.size` 字段添加为可选择字段。
645+
646+
{{% code_sample file="customresourcedefinition/shirt-resource-definition.yaml" %}}
647+
648+
<!--
649+
Field selectors can then be used to get only resources with with a `color` of `blue`:
650+
-->
651+
字段选择算符随后可用于仅获取 `color``blue` 的资源:
652+
653+
```shell
654+
kubectl get shirts.stable.example.com --field-selector spec.color=blue
655+
```
656+
657+
<!--
658+
The output should be:
659+
-->
660+
输出应该是:
661+
662+
```
663+
NAME COLOR SIZE
664+
example1 blue S
665+
example2 blue M
666+
```
667+
595668
## {{% heading "whatsnext" %}}
596669

597670
<!--
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
apiVersion: apiextensions.k8s.io/v1
2+
kind: CustomResourceDefinition
3+
metadata:
4+
name: shirts.stable.example.com
5+
spec:
6+
group: stable.example.com
7+
scope: Namespaced
8+
names:
9+
plural: shirts
10+
singular: shirt
11+
kind: Shirt
12+
versions:
13+
- name: v1
14+
served: true
15+
storage: true
16+
schema:
17+
openAPIV3Schema:
18+
type: object
19+
properties:
20+
spec:
21+
type: object
22+
properties:
23+
color:
24+
type: string
25+
size:
26+
type: string
27+
selectableFields:
28+
- jsonPath: .spec.color
29+
- jsonPath: .spec.size
30+
additionalPrinterColumns:
31+
- jsonPath: .spec.color
32+
name: Color
33+
type: string
34+
- jsonPath: .spec.size
35+
name: Size
36+
type: string

0 commit comments

Comments
 (0)