Merge pull request #33062 from my-git9/examplego

[zh] Sync examples_test.go
This commit is contained in:
Kubernetes Prow Robot 2022-04-20 18:00:58 -07:00 committed by GitHub
commit c1294b4c76
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 31 additions and 25 deletions

View File

@ -149,18 +149,17 @@ func getCodecForObject(obj runtime.Object) (runtime.Codec, error) {
func validateObject(obj runtime.Object) (errors field.ErrorList) { func validateObject(obj runtime.Object) (errors field.ErrorList) {
podValidationOptions := validation.PodValidationOptions{ podValidationOptions := validation.PodValidationOptions{
AllowMultipleHugePageResources: true,
AllowDownwardAPIHugePages: true, AllowDownwardAPIHugePages: true,
AllowInvalidPodDeletionCost: false,
AllowIndivisibleHugePagesValues: true,
AllowWindowsHostProcessField: true,
AllowExpandedDNSConfig: true,
} }
quotaValidationOptions := validation.ResourceQuotaValidationOptions{ quotaValidationOptions := validation.ResourceQuotaValidationOptions{
AllowPodAffinityNamespaceSelector: true, AllowPodAffinityNamespaceSelector: true,
} }
pspValidationOptions := policy_validation.PodSecurityPolicyValidationOptions{
AllowEphemeralVolumeType: true,
}
// Enable CustomPodDNS for testing // Enable CustomPodDNS for testing
// feature.DefaultFeatureGate.Set("CustomPodDNS=true") // feature.DefaultFeatureGate.Set("CustomPodDNS=true")
switch t := obj.(type) { switch t := obj.(type) {
@ -182,20 +181,23 @@ func validateObject(obj runtime.Object) (errors field.ErrorList) {
case *api.Namespace: case *api.Namespace:
errors = validation.ValidateNamespace(t) errors = validation.ValidateNamespace(t)
case *api.PersistentVolume: case *api.PersistentVolume:
errors = validation.ValidatePersistentVolume(t) opts := validation.PersistentVolumeSpecValidationOptions{
AllowReadWriteOncePod: true,
}
errors = validation.ValidatePersistentVolume(t, opts)
case *api.PersistentVolumeClaim: case *api.PersistentVolumeClaim:
if t.Namespace == "" { if t.Namespace == "" {
t.Namespace = api.NamespaceDefault t.Namespace = api.NamespaceDefault
} }
errors = validation.ValidatePersistentVolumeClaim(t) opts := validation.PersistentVolumeClaimSpecValidationOptions{
AllowReadWriteOncePod: true,
}
errors = validation.ValidatePersistentVolumeClaim(t, opts)
case *api.Pod: case *api.Pod:
if t.Namespace == "" { if t.Namespace == "" {
t.Namespace = api.NamespaceDefault t.Namespace = api.NamespaceDefault
} }
opts := validation.PodValidationOptions{ errors = validation.ValidatePodCreate(t, podValidationOptions)
AllowMultipleHugePageResources: true,
}
errors = validation.ValidatePodCreate(t, opts)
case *api.PodList: case *api.PodList:
for i := range t.Items { for i := range t.Items {
errors = append(errors, validateObject(&t.Items[i])...) errors = append(errors, validateObject(&t.Items[i])...)
@ -277,11 +279,7 @@ func validateObject(obj runtime.Object) (errors field.ErrorList) {
if t.Namespace == "" { if t.Namespace == "" {
t.Namespace = api.NamespaceDefault t.Namespace = api.NamespaceDefault
} }
gv := schema.GroupVersion{ errors = networking_validation.ValidateIngressCreate(t)
Group: networking.GroupName,
Version: legacyscheme.Scheme.PrioritizedVersionsForGroup(networking.GroupName)[0].Version,
}
errors = networking_validation.ValidateIngressCreate(t, gv)
case *networking.IngressClass: case *networking.IngressClass:
/* /*
if t.Namespace == "" { if t.Namespace == "" {
@ -295,7 +293,7 @@ func validateObject(obj runtime.Object) (errors field.ErrorList) {
errors = networking_validation.ValidateIngressClass(t) errors = networking_validation.ValidateIngressClass(t)
case *policy.PodSecurityPolicy: case *policy.PodSecurityPolicy:
errors = policy_validation.ValidatePodSecurityPolicy(t, pspValidationOptions) errors = policy_validation.ValidatePodSecurityPolicy(t)
case *apps.ReplicaSet: case *apps.ReplicaSet:
if t.Namespace == "" { if t.Namespace == "" {
t.Namespace = api.NamespaceDefault t.Namespace = api.NamespaceDefault
@ -399,7 +397,7 @@ func TestExampleObjectSchemas(t *testing.T) {
}, },
"admin/dns": { "admin/dns": {
"busybox": {&api.Pod{}}, "busybox": {&api.Pod{}},
"dns-horizontal-autoscaler": {&apps.Deployment{}}, "dns-horizontal-autoscaler": {&api.ServiceAccount{}, &rbac.ClusterRole{}, &rbac.ClusterRoleBinding{}, &apps.Deployment{}},
"dnsutils": {&api.Pod{}}, "dnsutils": {&api.Pod{}},
}, },
"admin/logging": { "admin/logging": {
@ -447,7 +445,7 @@ func TestExampleObjectSchemas(t *testing.T) {
}, },
"admin/sched": { "admin/sched": {
"clusterrole": {&rbac.ClusterRole{}}, "clusterrole": {&rbac.ClusterRole{}},
"my-scheduler": {&api.ServiceAccount{}, &rbac.ClusterRoleBinding{}, &rbac.ClusterRoleBinding{}, &apps.Deployment{}}, "my-scheduler": {&api.ServiceAccount{}, &rbac.ClusterRoleBinding{}, &rbac.ClusterRoleBinding{}, &api.ConfigMap{}, &apps.Deployment{}},
"pod1": {&api.Pod{}}, "pod1": {&api.Pod{}},
"pod2": {&api.Pod{}}, "pod2": {&api.Pod{}},
"pod3": {&api.Pod{}}, "pod3": {&api.Pod{}},
@ -558,6 +556,7 @@ func TestExampleObjectSchemas(t *testing.T) {
"pod-projected-svc-token": {&api.Pod{}}, "pod-projected-svc-token": {&api.Pod{}},
"pod-rs": {&api.Pod{}, &api.Pod{}}, "pod-rs": {&api.Pod{}, &api.Pod{}},
"pod-single-configmap-env-variable": {&api.Pod{}}, "pod-single-configmap-env-variable": {&api.Pod{}},
"pod-with-affinity-anti-affinity": {&api.Pod{}},
"pod-with-node-affinity": {&api.Pod{}}, "pod-with-node-affinity": {&api.Pod{}},
"pod-with-pod-affinity": {&api.Pod{}}, "pod-with-pod-affinity": {&api.Pod{}},
"pod-with-toleration": {&api.Pod{}}, "pod-with-toleration": {&api.Pod{}},
@ -586,6 +585,7 @@ func TestExampleObjectSchemas(t *testing.T) {
}, },
"pods/probe": { "pods/probe": {
"exec-liveness": {&api.Pod{}}, "exec-liveness": {&api.Pod{}},
"grpc-liveness": {&api.Pod{}},
"http-liveness": {&api.Pod{}}, "http-liveness": {&api.Pod{}},
"pod-with-http-healthcheck": {&api.Pod{}}, "pod-with-http-healthcheck": {&api.Pod{}},
"pod-with-tcp-socket-healthcheck": {&api.Pod{}}, "pod-with-tcp-socket-healthcheck": {&api.Pod{}},
@ -615,7 +615,11 @@ func TestExampleObjectSchemas(t *testing.T) {
}, },
"pods/storage": { "pods/storage": {
"projected": {&api.Pod{}}, "projected": {&api.Pod{}},
"projected-secret-downwardapi-configmap": {&api.Pod{}},
"projected-secrets-nondefault-permission-mode": {&api.Pod{}},
"projected-service-account-token": {&api.Pod{}},
"pv-claim": {&api.PersistentVolumeClaim{}}, "pv-claim": {&api.PersistentVolumeClaim{}},
"pv-duplicate": {&api.Pod{}},
"pv-pod": {&api.Pod{}}, "pv-pod": {&api.Pod{}},
"pv-volume": {&api.PersistentVolume{}}, "pv-volume": {&api.PersistentVolume{}},
"redis": {&api.Pod{}}, "redis": {&api.Pod{}},
@ -643,6 +647,7 @@ func TestExampleObjectSchemas(t *testing.T) {
"service/networking": { "service/networking": {
"curlpod": {&apps.Deployment{}}, "curlpod": {&apps.Deployment{}},
"custom-dns": {&api.Pod{}}, "custom-dns": {&api.Pod{}},
"default-ingressclass": {&networking.IngressClass{}},
"dual-stack-default-svc": {&api.Service{}}, "dual-stack-default-svc": {&api.Service{}},
"dual-stack-ipfamilies-ipv6": {&api.Service{}}, "dual-stack-ipfamilies-ipv6": {&api.Service{}},
"dual-stack-ipv6-svc": {&api.Service{}}, "dual-stack-ipv6-svc": {&api.Service{}},
@ -658,6 +663,7 @@ func TestExampleObjectSchemas(t *testing.T) {
"name-virtual-host-ingress": {&networking.Ingress{}}, "name-virtual-host-ingress": {&networking.Ingress{}},
"name-virtual-host-ingress-no-third-host": {&networking.Ingress{}}, "name-virtual-host-ingress-no-third-host": {&networking.Ingress{}},
"namespaced-params": {&networking.IngressClass{}}, "namespaced-params": {&networking.IngressClass{}},
"networkpolicy": {&networking.NetworkPolicy{}},
"network-policy-allow-all-egress": {&networking.NetworkPolicy{}}, "network-policy-allow-all-egress": {&networking.NetworkPolicy{}},
"network-policy-allow-all-ingress": {&networking.NetworkPolicy{}}, "network-policy-allow-all-ingress": {&networking.NetworkPolicy{}},
"network-policy-default-deny-egress": {&networking.NetworkPolicy{}}, "network-policy-default-deny-egress": {&networking.NetworkPolicy{}},