From 9bebc0e4fa732f1a4ac6a129cd6476ad55c6eaa7 Mon Sep 17 00:00:00 2001 From: 0xff-dev Date: Thu, 21 Jul 2022 14:34:28 +0800 Subject: [PATCH] fix rendering errors --- .../custom-resource-definitions.md | 126 +++++++++++------- 1 file changed, 78 insertions(+), 48 deletions(-) diff --git a/content/zh-cn/docs/tasks/extend-kubernetes/custom-resources/custom-resource-definitions.md b/content/zh-cn/docs/tasks/extend-kubernetes/custom-resources/custom-resource-definitions.md index df078bdb74..67db6aa683 100644 --- a/content/zh-cn/docs/tasks/extend-kubernetes/custom-resources/custom-resource-definitions.md +++ b/content/zh-cn/docs/tasks/extend-kubernetes/custom-resources/custom-resource-definitions.md @@ -310,7 +310,8 @@ kubectl get crontabs ``` ```none -Error from server (NotFound): Unable to list {"stable.example.com" "v1" "crontabs"}: the server could not find the requested resource (get crontabs.stable.example.com) +Error from server (NotFound): Unable to list {"stable.example.com" "v1" "crontabs"}: the server could not +find the requested resource (get crontabs.stable.example.com) ``` 结构化模式本身是一个 [OpenAPI v3.0 验证模式](#validation),其中: @@ -509,7 +514,9 @@ Violations of the structural schema rules are reported in the `NonStructural` co ### 字段剪裁 {#field-pruning} @@ -521,9 +528,8 @@ CustomResourceDefinition 在集群的持久性存储 被 _剪裁(Pruned)_ 掉(删除)。 输出类似于: -```console +```yaml apiVersion: stable.example.com/v1 kind: CronTab metadata: @@ -618,7 +624,9 @@ to clients, `kubectl` also checks for unknown fields and rejects those objects w #### 控制剪裁 {#controlling-pruning} @@ -731,9 +739,8 @@ properties: ``` 此外,所有这类节点也不再受规则 3 约束,也就是说,下面两种模式是被允许的 (注意,仅限于这两种模式,不支持添加新字段的任何其他变种): @@ -776,7 +783,8 @@ RawExtensions (as in `runtime.RawExtension` defined in [k8s.io/apimachinery](https://github.com/kubernetes/apimachinery/blob/03ac7a9ade429d715a1a46ceaa3724c18ebae54f/pkg/runtime/types.go#L94)) holds complete Kubernetes objects, i.e. with `apiVersion` and `kind` fields. -It is possible to specify those embedded objects (both completely without constraints or partially specified) by setting `x-kubernetes-embedded-resource: true`. For example: +It is possible to specify those embedded objects (both completely without constraints or partially specified) +by setting `x-kubernetes-embedded-resource: true`. For example: --> RawExtensions(就像在 [k8s.io/apimachinery](https://github.com/kubernetes/apimachinery/blob/03ac7a9ade429d715a1a46ceaa3724c18ebae54f/pkg/runtime/types.go#L94) @@ -809,9 +817,8 @@ foo: ``` @@ -1250,14 +1257,14 @@ Compilation process includes type checking as well. The compilation failure: - `no_matching_overload`: this function has no overload for the types of the arguments. - e.g. Rule like `self == true` against a field of integer type will get error: + e.g. Rule like `self == true` against a field of integer type will get error: ``` Invalid value: apiextensions.ValidationRule{Rule:"self == true", Message:""}: compilation failed: ERROR: \:1:6: found no matching overload for '_==_' applied to '(int, bool)' ``` - `no_such_field`: does not contain the desired field. - e.g. Rule like `self.nonExistingField > 0` against a non-existing field will return the error: + e.g. Rule like `self.nonExistingField > 0` against a non-existing field will return the error: ``` Invalid value: apiextensions.ValidationRule{Rule:"self.nonExistingField > 0", Message:""}: compilation failed: ERROR: \:1:5: undefined field 'nonExistingField' ``` @@ -1303,7 +1310,7 @@ Validation Rules Examples: | `has(self.expired) && self.created + self.ttl < self.expired` | Validate that 'expired' date is after a 'create' date plus a 'ttl' duration | | `self.health.startsWith('ok')` | Validate a 'health' string field has the prefix 'ok' | | `self.widgets.exists(w, w.key == 'x' && w.foo < 10)` | Validate that the 'foo' property of a listMap item with a key 'x' is less than 10 | -| `type(self) == string ? self == '100%' : self == 1000` | Validate an int-or-string field for both the the int and string cases | +| `type(self) == string ? self == '100%' : self == 1000` | Validate an int-or-string field for both the int and string cases | | `self.metadata.name.startsWith(self.prefix)` | Validate that an object's name has the prefix of another field value | | `self.set1.all(e, !(e in self.set2))` | Validate that two listSets are disjoint | | `size(self.names) == size(self.details) && self.names.all(n, n in self.details)` | Validate the 'details' map is keyed by the items in the 'names' listSet | @@ -1469,7 +1476,7 @@ Examples: The `apiVersion`, `kind`, `metadata.name` and `metadata.generateName` are always accessible from the root of the object and from any x-kubernetes-embedded-resource annotated objects. No other metadata properties are accessible. --> -`apiVersion`、`kind``metadata.name` 和 `metadata.generateName` 始终可以从对象的根目录和任何 +`apiVersion`、`kind`、`metadata.name` 和 `metadata.generateName` 始终可以从对象的根目录和任何 带有 `x-kubernetes-embedded-resource` 注解的对象访问。 其他元数据属性都不可访问。 @@ -1605,8 +1612,9 @@ Here is the declarations type mapping between OpenAPIv3 and CEL type: | 带有 format=duration 字符串 | duration (google.protobuf.Duration) | 参考:[CEL 类型](https://github.com/google/cel-spec/blob/v0.6.0/doc/langdef.md#values), [OpenAPI 类型](https://swagger.io/specification/#data-types), @@ -1619,10 +1627,10 @@ types](https://swagger.io/specification/#data-types), [Kubernetes Structural Sch 可用的函数包括: - CEL 标准函数,在[标准定义列表](https://github.com/google/cel-spec/blob/v0.7.0/doc/langdef.md#list-of-standard-definitions)中定义 @@ -1690,7 +1698,8 @@ schema is not mergeable"。 转换规则只允许在模式的“可关联部分(Correlatable Portions)”中使用。 如果所有 `array` 父模式都是 `x-kubernetes-list-type=map`类型的,那么该模式的一部分就是可关联的; @@ -1766,16 +1775,17 @@ longer to execute depending on how long `foo` is. 但是,如果 `foo` 是一个字符串,而你定义了一个验证规则 `self.foo.contains("someString")`, 这个规则需要更长的时间来执行,取决于 `foo` 有多长。 另一个例子是如果 `foo` 是一个数组,而你指定了验证规则 `self.foo.all(x, x > 5)`。 如果没有给出 `foo` 的长度限制,成本系统总是假设最坏的情况,这将发生在任何可以被迭代的事物上(list、map 等)。 因此,通过 `maxItems`,`maxProperties` 和 `maxLength` 进行限制被认为是最佳实践, 以在验证规则中处理任何内容,以防止在成本估算期间验证错误。例如,给定具有一个规则的模式: @@ -1797,9 +1807,9 @@ then the API server rejects this rule on validation budget grounds with error: --> API 服务器以验证预算为由拒绝该规则,并显示错误: ``` - spec.validation.openAPIV3Schema.properties[spec].properties[foo].x-kubernetes-validations[0].rule: Forbidden: - CEL rule exceeded budget by more than 100x (try simplifying the rule, or adding maxItems, maxProperties, and - maxLength where arrays, maps, and strings are used) +spec.validation.openAPIV3Schema.properties[spec].properties[foo].x-kubernetes-validations[0].rule: Forbidden: +CEL rule exceeded budget by more than 100x (try simplifying the rule, or adding maxItems, maxProperties, and +maxLength where arrays, maps, and strings are used) ``` 如果在一个列表内部的一个列表有一个使用 `self.all` 的验证规则,那就会比具有相同规则的非嵌套列表的成本高得多。 @@ -1993,7 +2004,8 @@ Defaulting happens on the object * when reading from etcd using the storage version defaults, * after mutating admission plugins with non-empty patches using the admission webhook object version defaults. -Defaults applied when reading data from etcd are not automatically written back to etcd. An update request via the API is required to persist those defaults back into etcd. +Defaults applied when reading data from etcd are not automatically written back to etcd. +An update request via the API is required to persist those defaults back into etcd. --> 默认值设定的行为发生在定制对象上: @@ -2008,7 +2020,9 @@ Defaults applied when reading data from etcd are not automatically written back 默认值一定会被剪裁(除了 `metadata` 字段的默认值设置),且必须通过所提供 的模式定义的检查。 @@ -2020,7 +2034,9 @@ Default values for `metadata` fields of `x-kubernetes-embedded-resources: true` @@ -2074,7 +2090,9 @@ spec: ``` 其中的 `foo` 字段被剪裁掉并重新设置默认值,因为该字段是不可为空的。 `bar` 字段的 `nullable: true` 使得其能够保有其空值。 @@ -2083,9 +2101,14 @@ with `foo` pruned and defaulted because the field is non-nullable, `bar` maintai ### 以 OpenAPI v2 形式发布合法性检查模式 {#publish-validation-schema-in-openapi-v2} @@ -2117,9 +2140,13 @@ OpenAPI v3 合法性检查模式定义会被转换为 OpenAPI v2 模式定义, 的[合法性检查](#validation)。 1. 以下字段会被移除,因为它们在 OpenAPI v2 中不支持(在将来版本中将使用 OpenAPI v3, 因而不会有这些限制) @@ -2251,7 +2278,8 @@ View)和宽视图(Wide View)(使用 `-o wide` 标志)中显示的列 - `labelSelectorPath` 指定定制资源内与 `scale.status.selector` 对应的 JSON 路径。 @@ -2695,6 +2724,7 @@ crontabs/my-new-cron-object 3s * Serve [multiple versions](/docs/tasks/extend-kubernetes/custom-resources/custom-resource-definition-versioning/) of a CustomResourceDefinition. + --> * 阅读了解[定制资源](/zh-cn/docs/concepts/extend-kubernetes/api-extension/custom-resources/) * 参阅 [CustomResourceDefinition](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#customresourcedefinition-v1-apiextensions-k8s-io)