@@ -115,24 +115,32 @@ The following is an example of a ValidatingAdmissionPolicy.
115
115
116
116
以下是一个 ValidatingAdmissionPolicy 的示例:
117
117
118
- {{% codenew language="yaml" file="validatingadmissionpolicy/basic-example-policy.yaml" %}}
118
+ {{% code_sample language="yaml" file="validatingadmissionpolicy/basic-example-policy.yaml" %}}
119
119
120
120
<!--
121
121
`spec.validations` contains CEL expressions which use the [Common Expression Language (CEL)](https://github.com/google/cel-spec)
122
122
to validate the request. If an expression evaluates to false, the validation check is enforced
123
123
according to the `spec.failurePolicy` field.
124
-
125
- To configure a validating admission policy for use in a cluster, a binding is required.
126
- The following is an example of a ValidatingAdmissionPolicyBinding.:
127
124
-->
128
125
` spec.validations ` 包含使用[ 通用表达式语言 (CEL)] ( https://github.com/google/cel-spec )
129
126
来验证请求的 CEL 表达式。
130
127
如果表达式的计算结果为 false,则根据 ` spec.failurePolicy ` 字段强制执行验证检查处理。
131
128
129
+ {{< note >}}
130
+ <!--
131
+ You can quickly test CEL expressions in [CEL Playground](https://playcel.undistro.io).
132
+ -->
133
+ 你可以在 [ CEL Playground] ( https://playcel.undistro.io ) 中快速验证 CEL 表达式。
134
+ {{< /note >}}
135
+
136
+ <!--
137
+ To configure a validating admission policy for use in a cluster, a binding is required.
138
+ The following is an example of a ValidatingAdmissionPolicyBinding:
139
+ -->
132
140
要配置一个在某集群中使用的验证准入策略,需要一个绑定。
133
141
以下是一个 ValidatingAdmissionPolicyBinding 的示例:
134
142
135
- {{% codenew language="yaml" file="validatingadmissionpolicy/basic-example-binding.yaml" %}}
143
+ {{% code_sample language="yaml" file="validatingadmissionpolicy/basic-example-binding.yaml" %}}
136
144
137
145
<!--
138
146
When trying to create a deployment with replicas set not satisfying the validation expression, an
@@ -226,7 +234,7 @@ with parameter configuration.
226
234
227
235
如果需要参数配置,下面是一个带有参数配置的 ValidatingAdmissionPolicy 的例子:
228
236
229
- {{% codenew language="yaml" file="validatingadmissionpolicy/policy-with-param.yaml" %}}
237
+ {{% code_sample language="yaml" file="validatingadmissionpolicy/policy-with-param.yaml" %}}
230
238
231
239
<!--
232
240
The `spec.paramKind` field of the ValidatingAdmissionPolicy specifies the kind of resources used
@@ -261,7 +269,7 @@ every resource request that matches the binding:
261
269
要配置一个在某集群中使用的验证准入策略,需要创建绑定和参数资源。
262
270
以下是 ValidatingAdmissionPolicyBinding **集群范围**参数的示例 - 相同的参数将用于验证与绑定匹配的每个资源请求:
263
271
264
- {{% codenew language="yaml" file="validatingadmissionpolicy/binding-with-param.yaml" %}}
272
+ {{% code_sample language="yaml" file="validatingadmissionpolicy/binding-with-param.yaml" %}}
265
273
266
274
<!--
267
275
Notice this binding applies a parameter to the policy for all resources which
@@ -274,7 +282,7 @@ The parameter resource could be as following:
274
282
-->
275
283
参数资源可以如下:
276
284
277
- {{% codenew language="yaml" file="validatingadmissionpolicy/replicalimit-param.yaml" %}}
285
+ {{% code_sample language="yaml" file="validatingadmissionpolicy/replicalimit-param.yaml" %}}
278
286
279
287
<!--
280
288
This policy parameter resource limits deployments to a max of 3 replicas.
@@ -285,7 +293,7 @@ to have a maxReplicas limit of 100, create another ValidatingAdmissionPolicyBind
285
293
一个准入策略可以有多个绑定。
286
294
要绑定所有的其他环境,限制 maxReplicas 为 100,请创建另一个 ValidatingAdmissionPolicyBinding:
287
295
288
- {{% codenew language="yaml" file="validatingadmissionpolicy/binding-with-param-prod.yaml" %}}
296
+ {{% code_sample language="yaml" file="validatingadmissionpolicy/binding-with-param-prod.yaml" %}}
289
297
290
298
<!--
291
299
Notice this binding applies a different parameter to resources which
@@ -298,7 +306,7 @@ And have a parameter resource:
298
306
-->
299
307
并有一个参数资源:
300
308
301
- {{% codenew language="yaml" file="validatingadmissionpolicy/replicalimit-param-prod.yaml" %}}
309
+ {{% code_sample language="yaml" file="validatingadmissionpolicy/replicalimit-param-prod.yaml" %}}
302
310
303
311
<!--
304
312
For each admission request, the API server evaluates CEL expressions of each
@@ -415,7 +423,7 @@ searches for parameters in that namespace.
415
423
416
424
作为 ValidatingAdmissionPolicy 及其 ValidatingAdmissionPolicyBinding 的作者,
417
425
你可以选择指定其作用于集群范围还是某个命名空间。如果你为绑定的 `paramRef` 指定 `namespace`,
418
- 则控制平面仅在该名字空间中搜索参数 。
426
+ 则控制平面仅在该命名空间中搜索参数 。
419
427
420
428
<!--
421
429
However, if `namespace` is not specified in the ValidatingAdmissionPolicyBinding, the
@@ -504,7 +512,7 @@ Note that the `failurePolicy` is defined inside `ValidatingAdmissionPolicy`:
504
512
505
513
请注意,`failurePolicy` 是在 `ValidatingAdmissionPolicy` 中定义的:
506
514
507
- {{% codenew language="yaml" file="validatingadmissionpolicy/failure-policy-ignore.yaml" %}}
515
+ {{% code_sample language="yaml" file="validatingadmissionpolicy/failure-policy-ignore.yaml" %}}
508
516
509
517
<!--
510
518
### Validation Expression
@@ -662,7 +670,7 @@ Here is an example illustrating a few different uses for match conditions:
662
670
-->
663
671
以下示例说明了匹配条件的几个不同用法:
664
672
665
- {{% codenew file="access/validating-admission-policy-match-conditions.yaml" %}}
673
+ {{% code_sample file="access/validating-admission-policy-match-conditions.yaml" %}}
666
674
667
675
<!--
668
676
Match conditions have access to the same CEL variables as validation expressions.
@@ -698,7 +706,7 @@ For example, here is an admission policy with an audit annotation:
698
706
699
707
例如,以下是带有审计注解的准入策略:
700
708
701
- {{% codenew file="access/validating-admission-policy-audit-annotation.yaml" %}}
709
+ {{% code_sample file="access/validating-admission-policy-audit-annotation.yaml" %}}
702
710
703
711
<!--
704
712
When an API request is validated with this admission policy, the resulting audit event will look like:
@@ -772,7 +780,7 @@ we can have the following validation:
772
780
773
781
例如,为了在策略引用参数时更好地告知用户拒绝原因,我们可以有以下验证:
774
782
775
- {{% codenew file="access/deployment-replicas-policy.yaml" %}}
783
+ {{% code_sample file="access/deployment-replicas-policy.yaml" %}}
776
784
777
785
<!--
778
786
After creating a params object that limits the replicas to 3 and setting up the binding,
@@ -825,7 +833,7 @@ For example, given the following policy definition:
825
833
826
834
例如,给定以下策略定义:
827
835
828
- {{% codenew language="yaml" file="validatingadmissionpolicy/typechecking.yaml" %}}
836
+ {{% code_sample language="yaml" file="validatingadmissionpolicy/typechecking.yaml" %}}
829
837
830
838
<!--
831
839
The status will yield the following information:
@@ -850,7 +858,7 @@ For example, the following policy definition
850
858
如果在 ` spec.matchConstraints ` 中匹配了多个资源,则所有匹配的资源都将进行检查。
851
859
例如,以下策略定义:
852
860
853
- {{% codenew language="yaml" file="validatingadmissionpolicy/typechecking-multiple-match.yaml" %}}
861
+ {{% code_sample language="yaml" file="validatingadmissionpolicy/typechecking-multiple-match.yaml" %}}
854
862
855
863
<!--
856
864
will have multiple types and type checking result of each type in the warning message.
@@ -932,7 +940,7 @@ The following is a more complex example of enforcing that image repo names match
932
940
933
941
以下是强制镜像仓库名称与其命名空间中定义的环境相匹配的一个较复杂示例。
934
942
935
- {{< codenew file="access/image-matches-namespace-environment.policy.yaml" >}}
943
+ {{< code_sample file="access/image-matches-namespace-environment.policy.yaml" >}}
936
944
937
945
<!--
938
946
With the policy bound to the namespace `default`, which is labeled `environment : prod`,
0 commit comments