Skip to content

Commit d1f6abf

Browse files
authored
Merge pull request #40711 from tengqm/fix-examples-test
Fix examples test for 1.27
2 parents 07ffcd1 + ad7c071 commit d1f6abf

9 files changed

+292
-224
lines changed

content/en/docs/reference/access-authn-authz/extensible-admission-controllers.md

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -736,7 +736,55 @@ webhook to be called.
736736

737737
Here is an example illustrating a few different uses for match conditions:
738738

739-
{{< codenew file="access/admission-webhook-match-conditions.yaml" >}}
739+
```yaml
740+
apiVersion: admissionregistration.k8s.io/v1
741+
kind: ValidatingWebhookConfiguration
742+
webhooks:
743+
- name: my-webhook.example.com
744+
matchPolicy: Equivalent
745+
rules:
746+
- operations: ['CREATE','UPDATE']
747+
apiGroups: ['*']
748+
apiVersions: ['*']
749+
resources: ['*']
750+
failurePolicy: 'Ignore' # Fail-open (optional)
751+
sideEffects: None
752+
clientConfig:
753+
service:
754+
namespace: my-namespace
755+
name: my-webhook
756+
caBundle: '<omitted>'
757+
matchConditions:
758+
- name: 'exclude-leases' # Each match condition must have a unique name
759+
expression: '!(request.resource.group == "coordination.k8s.io" && request.resource.resource == "leases")' # Match non-lease resources.
760+
- name: 'exclude-kubelet-requests'
761+
expression: '!("system:nodes" in request.userInfo.groups)' # Match requests made by non-node users.
762+
- name: 'rbac' # Skip RBAC requests, which are handled by the second webhook.
763+
expression: 'request.resource.group != "rbac.authorization.k8s.io"'
764+
765+
# This example illustrates the use of the 'authorizer'. The authorization check is more expensive
766+
# than a simple expression, so in this example it is scoped to only RBAC requests by using a second
767+
# webhook. Both webhooks can be served by the same endpoint.
768+
- name: rbac.my-webhook.example.com
769+
matchPolicy: Equivalent
770+
rules:
771+
- operations: ['CREATE','UPDATE']
772+
apiGroups: ['rbac.authorization.k8s.io']
773+
apiVersions: ['*']
774+
resources: ['*']
775+
failurePolicy: 'Fail' # Fail-closed (the default)
776+
sideEffects: None
777+
clientConfig:
778+
service:
779+
namespace: my-namespace
780+
name: my-webhook
781+
caBundle: '<omitted>'
782+
matchConditions:
783+
- name: 'breakglass'
784+
# Skip requests made by users authorized to 'breakglass' on this webhook.
785+
# The 'breakglass' API verb does not need to exist outside this check.
786+
expression: '!authorizer.group("admissionregistration.k8s.io").resource("validatingwebhookconfigurations").name("my-webhook.example.com").check("breakglass").allowed()'
787+
```
740788

741789
Match conditions have access to the following CEL variables:
742790

content/en/docs/reference/access-authn-authz/validating-admission-policy.md

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,20 @@ For example, here is an admission policy with an audit annotation:
438438

439439
When an API request is validated with this admission policy, the resulting audit event will look like:
440440

441-
{{< codenew file="access/audit-event-with-audit-annotation.yaml" >}}
441+
```
442+
# the audit event recorded
443+
{
444+
"kind": "Event",
445+
"apiVersion": "audit.k8s.io/v1",
446+
"annotations": {
447+
"demo-policy.example.com/high-replica-count": "Deployment spec.replicas set to 128"
448+
# other annotations
449+
...
450+
}
451+
# other fields
452+
...
453+
}
454+
```
442455

443456
In this example the annotation will only be included if the `spec.replicas` of the Deployment is more than
444457
50, otherwise the CEL expression evalutes to null and the annotation will not be included.
@@ -564,4 +577,4 @@ Type Checking has the following limitation:
564577
to consume excessive computing resources. In the order of ascending group, version, and then resource, 11th combination and beyond are ignored.
565578
- Type Checking does not affect the policy behavior in any way. Even if the type checking detects errors, the policy will continue
566579
to evaluate. If errors do occur during evaluate, the failure policy will decide its outcome.
567-
- Type Checking does not apply to CRDs, including matched CRD types and reference of paramKind. The support for CRDs will come in future release.
580+
- Type Checking does not apply to CRDs, including matched CRD types and reference of paramKind. The support for CRDs will come in future release.

content/en/examples/access/admission-webhook-match-conditions.yaml

Lines changed: 0 additions & 47 deletions
This file was deleted.

content/en/examples/access/audit-event-with-audit-annotation.yaml

Lines changed: 0 additions & 12 deletions
This file was deleted.

content/en/examples/access/deployment-replicas-policy.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@ metadata:
44
name: "deploy-replica-policy.example.com"
55
spec:
66
paramKind:
7-
group: rules.example.com
7+
apiVersion: rules.example.com/v1
88
kind: ReplicaLimit
9-
version: v1
109
matchConstraints:
1110
resourceRules:
1211
- apiGroups: ["apps"]

content/en/examples/access/validating-admission-policy-audit-annotation.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@ spec:
1212
resources: ["deployments"]
1313
validations:
1414
- key: "high-replica-count"
15-
valueExpression: "object.spec.replicas > 50 ? 'Deployment spec.replicas set to ' + string(object.spec.replicas) : null"
15+
expression: "object.spec.replicas > 50"
16+
messageExpression: "'Deployment spec.replicas set to ' + string(object.spec.replicas)"

content/en/examples/examples_test.go

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ import (
3434
"k8s.io/apimachinery/pkg/util/yaml"
3535
"k8s.io/kubernetes/pkg/api/legacyscheme"
3636

37+
"k8s.io/kubernetes/pkg/apis/admissionregistration"
38+
admreg_validation "k8s.io/kubernetes/pkg/apis/admissionregistration/validation"
39+
3740
"k8s.io/kubernetes/pkg/apis/apps"
3841
apps_validation "k8s.io/kubernetes/pkg/apis/apps/validation"
3942

@@ -65,6 +68,7 @@ import (
6568
"k8s.io/kubernetes/pkg/registry/batch/job"
6669

6770
// initialize install packages
71+
_ "k8s.io/kubernetes/pkg/apis/admissionregistration/install"
6872
_ "k8s.io/kubernetes/pkg/apis/apps/install"
6973
_ "k8s.io/kubernetes/pkg/apis/autoscaling/install"
7074
_ "k8s.io/kubernetes/pkg/apis/batch/install"
@@ -102,6 +106,7 @@ func (g TestGroup) Codec() runtime.Codec {
102106
func initGroups() {
103107
Groups = make(map[string]TestGroup)
104108
groupNames := []string{
109+
admissionregistration.GroupName,
105110
api.GroupName,
106111
apps.GroupName,
107112
autoscaling.GroupName,
@@ -152,7 +157,6 @@ func getCodecForObject(obj runtime.Object) (runtime.Codec, error) {
152157

153158
func validateObject(obj runtime.Object) (errors field.ErrorList) {
154159
podValidationOptions := validation.PodValidationOptions{
155-
AllowDownwardAPIHugePages: true,
156160
AllowInvalidPodDeletionCost: false,
157161
AllowIndivisibleHugePagesValues: true,
158162
AllowExpandedDNSConfig: true,
@@ -170,6 +174,10 @@ func validateObject(obj runtime.Object) (errors field.ErrorList) {
170174
// Enable CustomPodDNS for testing
171175
// feature.DefaultFeatureGate.Set("CustomPodDNS=true")
172176
switch t := obj.(type) {
177+
case *admissionregistration.ValidatingWebhookConfiguration:
178+
errors = admreg_validation.ValidateValidatingWebhookConfiguration(t)
179+
case *admissionregistration.ValidatingAdmissionPolicy:
180+
errors = admreg_validation.ValidateValidatingAdmissionPolicy(t)
173181
case *api.ConfigMap:
174182
if t.Namespace == "" {
175183
t.Namespace = api.NamespaceDefault
@@ -390,7 +398,10 @@ func TestExampleObjectSchemas(t *testing.T) {
390398
// Please help maintain the alphabeta order in the map
391399
cases := map[string]map[string][]runtime.Object{
392400
"access": {
393-
"endpoints-aggregated": {&rbac.ClusterRole{}},
401+
"deployment-replicas-policy": {&admissionregistration.ValidatingAdmissionPolicy{}},
402+
"endpoints-aggregated": {&rbac.ClusterRole{}},
403+
"validating-admission-policy-audit-annotation": {&admissionregistration.ValidatingAdmissionPolicy{}},
404+
"validating-admission-policy-match-conditions": {&admissionregistration.ValidatingAdmissionPolicy{}},
394405
},
395406
"access/certificate-signing-request": {
396407
"clusterrole-approve": {&rbac.ClusterRole{}},
@@ -544,20 +555,21 @@ func TestExampleObjectSchemas(t *testing.T) {
544555
"configure-pod": {&api.Pod{}},
545556
},
546557
"controllers": {
547-
"daemonset": {&apps.DaemonSet{}},
548-
"fluentd-daemonset": {&apps.DaemonSet{}},
549-
"fluentd-daemonset-update": {&apps.DaemonSet{}},
550-
"frontend": {&apps.ReplicaSet{}},
551-
"hpa-rs": {&autoscaling.HorizontalPodAutoscaler{}},
552-
"job": {&batch.Job{}},
553-
"job-pod-failure-policy-example": {&batch.Job{}},
554-
"job-pod-failure-policy-failjob": {&batch.Job{}},
555-
"job-pod-failure-policy-ignore": {&batch.Job{}},
556-
"replicaset": {&apps.ReplicaSet{}},
557-
"replication": {&api.ReplicationController{}},
558-
"replication-nginx-1.14.2": {&api.ReplicationController{}},
559-
"replication-nginx-1.16.1": {&api.ReplicationController{}},
560-
"nginx-deployment": {&apps.Deployment{}},
558+
"daemonset": {&apps.DaemonSet{}},
559+
"fluentd-daemonset": {&apps.DaemonSet{}},
560+
"fluentd-daemonset-update": {&apps.DaemonSet{}},
561+
"frontend": {&apps.ReplicaSet{}},
562+
"hpa-rs": {&autoscaling.HorizontalPodAutoscaler{}},
563+
"job": {&batch.Job{}},
564+
"job-pod-failure-policy-config-issue": {&batch.Job{}},
565+
"job-pod-failure-policy-example": {&batch.Job{}},
566+
"job-pod-failure-policy-failjob": {&batch.Job{}},
567+
"job-pod-failure-policy-ignore": {&batch.Job{}},
568+
"replicaset": {&apps.ReplicaSet{}},
569+
"replication": {&api.ReplicationController{}},
570+
"replication-nginx-1.14.2": {&api.ReplicationController{}},
571+
"replication-nginx-1.16.1": {&api.ReplicationController{}},
572+
"nginx-deployment": {&apps.Deployment{}},
561573
},
562574
"debug": {
563575
"counter-pod": {&api.Pod{}},
@@ -627,6 +639,7 @@ func TestExampleObjectSchemas(t *testing.T) {
627639
"qos-pod-2": {&api.Pod{}},
628640
"qos-pod-3": {&api.Pod{}},
629641
"qos-pod-4": {&api.Pod{}},
642+
"qos-pod-5": {&api.Pod{}},
630643
},
631644
"pods/resource": {
632645
"cpu-request-limit": {&api.Pod{}},
@@ -678,13 +691,15 @@ func TestExampleObjectSchemas(t *testing.T) {
678691
"mysecretname": {&api.Secret{}},
679692
},
680693
"security": {
694+
"example-baseline-pod": {&api.Pod{}},
681695
"podsecurity-baseline": {&api.Namespace{}},
682696
"podsecurity-privileged": {&api.Namespace{}},
683697
"podsecurity-restricted": {&api.Namespace{}},
684698
},
685699
"service": {
686-
"nginx-service": {&api.Service{}},
687-
"load-balancer-example": {&apps.Deployment{}},
700+
"nginx-service": {&api.Service{}},
701+
"load-balancer-example": {&apps.Deployment{}},
702+
"pod-with-graceful-termination": {&apps.Deployment{}},
688703
},
689704
"service/access": {
690705
"backend-deployment": {&apps.Deployment{}},

0 commit comments

Comments
 (0)