Merge pull request #26086 from tengqm/fix-example-tests
Fix example tests
This commit is contained in:
@@ -148,6 +148,11 @@ 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{
|
||||||
|
AllowMultipleHugePageResources: true,
|
||||||
|
AllowDownwardAPIHugePages: 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,7 +187,7 @@ func validateObject(obj runtime.Object) (errors field.ErrorList) {
|
|||||||
opts := validation.PodValidationOptions{
|
opts := validation.PodValidationOptions{
|
||||||
AllowMultipleHugePageResources: true,
|
AllowMultipleHugePageResources: true,
|
||||||
}
|
}
|
||||||
errors = validation.ValidatePod(t, opts)
|
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])...)
|
||||||
@@ -191,12 +196,12 @@ func validateObject(obj runtime.Object) (errors field.ErrorList) {
|
|||||||
if t.Namespace == "" {
|
if t.Namespace == "" {
|
||||||
t.Namespace = api.NamespaceDefault
|
t.Namespace = api.NamespaceDefault
|
||||||
}
|
}
|
||||||
errors = validation.ValidatePodTemplate(t)
|
errors = validation.ValidatePodTemplate(t, podValidationOptions)
|
||||||
case *api.ReplicationController:
|
case *api.ReplicationController:
|
||||||
if t.Namespace == "" {
|
if t.Namespace == "" {
|
||||||
t.Namespace = api.NamespaceDefault
|
t.Namespace = api.NamespaceDefault
|
||||||
}
|
}
|
||||||
errors = validation.ValidateReplicationController(t)
|
errors = validation.ValidateReplicationController(t, podValidationOptions)
|
||||||
case *api.ReplicationControllerList:
|
case *api.ReplicationControllerList:
|
||||||
for i := range t.Items {
|
for i := range t.Items {
|
||||||
errors = append(errors, validateObject(&t.Items[i])...)
|
errors = append(errors, validateObject(&t.Items[i])...)
|
||||||
@@ -215,7 +220,11 @@ func validateObject(obj runtime.Object) (errors field.ErrorList) {
|
|||||||
if t.Namespace == "" {
|
if t.Namespace == "" {
|
||||||
t.Namespace = api.NamespaceDefault
|
t.Namespace = api.NamespaceDefault
|
||||||
}
|
}
|
||||||
errors = validation.ValidateService(t, true)
|
// handle clusterIPs, logic copied from service strategy
|
||||||
|
if len(t.Spec.ClusterIP) > 0 && len(t.Spec.ClusterIPs) == 0 {
|
||||||
|
t.Spec.ClusterIPs = []string{t.Spec.ClusterIP}
|
||||||
|
}
|
||||||
|
errors = validation.ValidateService(t)
|
||||||
case *api.ServiceAccount:
|
case *api.ServiceAccount:
|
||||||
if t.Namespace == "" {
|
if t.Namespace == "" {
|
||||||
t.Namespace = api.NamespaceDefault
|
t.Namespace = api.NamespaceDefault
|
||||||
@@ -250,12 +259,12 @@ func validateObject(obj runtime.Object) (errors field.ErrorList) {
|
|||||||
if t.Namespace == "" {
|
if t.Namespace == "" {
|
||||||
t.Namespace = api.NamespaceDefault
|
t.Namespace = api.NamespaceDefault
|
||||||
}
|
}
|
||||||
errors = apps_validation.ValidateDaemonSet(t)
|
errors = apps_validation.ValidateDaemonSet(t, podValidationOptions)
|
||||||
case *apps.Deployment:
|
case *apps.Deployment:
|
||||||
if t.Namespace == "" {
|
if t.Namespace == "" {
|
||||||
t.Namespace = api.NamespaceDefault
|
t.Namespace = api.NamespaceDefault
|
||||||
}
|
}
|
||||||
errors = apps_validation.ValidateDeployment(t)
|
errors = apps_validation.ValidateDeployment(t, podValidationOptions)
|
||||||
case *networking.Ingress:
|
case *networking.Ingress:
|
||||||
if t.Namespace == "" {
|
if t.Namespace == "" {
|
||||||
t.Namespace = api.NamespaceDefault
|
t.Namespace = api.NamespaceDefault
|
||||||
@@ -265,18 +274,30 @@ func validateObject(obj runtime.Object) (errors field.ErrorList) {
|
|||||||
Version: legacyscheme.Scheme.PrioritizedVersionsForGroup(networking.GroupName)[0].Version,
|
Version: legacyscheme.Scheme.PrioritizedVersionsForGroup(networking.GroupName)[0].Version,
|
||||||
}
|
}
|
||||||
errors = networking_validation.ValidateIngressCreate(t, gv)
|
errors = networking_validation.ValidateIngressCreate(t, gv)
|
||||||
|
case *networking.IngressClass:
|
||||||
|
/*
|
||||||
|
if t.Namespace == "" {
|
||||||
|
t.Namespace = api.NamespaceDefault
|
||||||
|
}
|
||||||
|
gv := schema.GroupVersion{
|
||||||
|
Group: networking.GroupName,
|
||||||
|
Version: legacyscheme.Scheme.PrioritizedVersionsForGroup(networking.GroupName)[0].Version,
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
errors = networking_validation.ValidateIngressClass(t)
|
||||||
|
|
||||||
case *policy.PodSecurityPolicy:
|
case *policy.PodSecurityPolicy:
|
||||||
errors = policy_validation.ValidatePodSecurityPolicy(t)
|
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
|
||||||
}
|
}
|
||||||
errors = apps_validation.ValidateReplicaSet(t)
|
errors = apps_validation.ValidateReplicaSet(t, podValidationOptions)
|
||||||
case *batch.CronJob:
|
case *batch.CronJob:
|
||||||
if t.Namespace == "" {
|
if t.Namespace == "" {
|
||||||
t.Namespace = api.NamespaceDefault
|
t.Namespace = api.NamespaceDefault
|
||||||
}
|
}
|
||||||
errors = batch_validation.ValidateCronJob(t)
|
errors = batch_validation.ValidateCronJob(t, podValidationOptions)
|
||||||
case *networking.NetworkPolicy:
|
case *networking.NetworkPolicy:
|
||||||
if t.Namespace == "" {
|
if t.Namespace == "" {
|
||||||
t.Namespace = api.NamespaceDefault
|
t.Namespace = api.NamespaceDefault
|
||||||
@@ -287,6 +308,9 @@ func validateObject(obj runtime.Object) (errors field.ErrorList) {
|
|||||||
t.Namespace = api.NamespaceDefault
|
t.Namespace = api.NamespaceDefault
|
||||||
}
|
}
|
||||||
errors = policy_validation.ValidatePodDisruptionBudget(t)
|
errors = policy_validation.ValidatePodDisruptionBudget(t)
|
||||||
|
case *rbac.ClusterRole:
|
||||||
|
// clusterole does not accept namespace
|
||||||
|
errors = rbac_validation.ValidateClusterRole(t)
|
||||||
case *rbac.ClusterRoleBinding:
|
case *rbac.ClusterRoleBinding:
|
||||||
// clusterolebinding does not accept namespace
|
// clusterolebinding does not accept namespace
|
||||||
errors = rbac_validation.ValidateClusterRoleBinding(t)
|
errors = rbac_validation.ValidateClusterRoleBinding(t)
|
||||||
@@ -414,6 +438,7 @@ func TestExampleObjectSchemas(t *testing.T) {
|
|||||||
"storagelimits": {&api.LimitRange{}},
|
"storagelimits": {&api.LimitRange{}},
|
||||||
},
|
},
|
||||||
"admin/sched": {
|
"admin/sched": {
|
||||||
|
"clusterrole": {&rbac.ClusterRole{}},
|
||||||
"my-scheduler": {&api.ServiceAccount{}, &rbac.ClusterRoleBinding{}, &rbac.ClusterRoleBinding{}, &apps.Deployment{}},
|
"my-scheduler": {&api.ServiceAccount{}, &rbac.ClusterRoleBinding{}, &rbac.ClusterRoleBinding{}, &apps.Deployment{}},
|
||||||
"pod1": {&api.Pod{}},
|
"pod1": {&api.Pod{}},
|
||||||
"pod2": {&api.Pod{}},
|
"pod2": {&api.Pod{}},
|
||||||
@@ -539,6 +564,7 @@ func TestExampleObjectSchemas(t *testing.T) {
|
|||||||
"dapi-envars-pod": {&api.Pod{}},
|
"dapi-envars-pod": {&api.Pod{}},
|
||||||
"dapi-volume": {&api.Pod{}},
|
"dapi-volume": {&api.Pod{}},
|
||||||
"dapi-volume-resources": {&api.Pod{}},
|
"dapi-volume-resources": {&api.Pod{}},
|
||||||
|
"dependent-envars": {&api.Pod{}},
|
||||||
"envars": {&api.Pod{}},
|
"envars": {&api.Pod{}},
|
||||||
"pod-multiple-secret-env-variable": {&api.Pod{}},
|
"pod-multiple-secret-env-variable": {&api.Pod{}},
|
||||||
"pod-secret-envFrom": {&api.Pod{}},
|
"pod-secret-envFrom": {&api.Pod{}},
|
||||||
@@ -596,29 +622,41 @@ func TestExampleObjectSchemas(t *testing.T) {
|
|||||||
"load-balancer-example": {&apps.Deployment{}},
|
"load-balancer-example": {&apps.Deployment{}},
|
||||||
},
|
},
|
||||||
"service/access": {
|
"service/access": {
|
||||||
"frontend": {&api.Service{}, &apps.Deployment{}},
|
"backend-deployment": {&apps.Deployment{}},
|
||||||
"hello-application": {&apps.Deployment{}},
|
"backend-service": {&api.Service{}},
|
||||||
"hello-service": {&api.Service{}},
|
"frontend-deployment": {&apps.Deployment{}},
|
||||||
"hello": {&apps.Deployment{}},
|
"frontend-service": {&api.Service{}},
|
||||||
|
"hello-application": {&apps.Deployment{}},
|
||||||
},
|
},
|
||||||
"service/networking": {
|
"service/networking": {
|
||||||
"curlpod": {&apps.Deployment{}},
|
"curlpod": {&apps.Deployment{}},
|
||||||
"custom-dns": {&api.Pod{}},
|
"custom-dns": {&api.Pod{}},
|
||||||
"dual-stack-default-svc": {&api.Service{}},
|
"dual-stack-default-svc": {&api.Service{}},
|
||||||
"dual-stack-ipv4-svc": {&api.Service{}},
|
"dual-stack-ipfamilies-ipv6": {&api.Service{}},
|
||||||
"dual-stack-ipv6-lb-svc": {&api.Service{}},
|
"dual-stack-ipv6-svc": {&api.Service{}},
|
||||||
"dual-stack-ipv6-svc": {&api.Service{}},
|
"dual-stack-prefer-ipv6-lb-svc": {&api.Service{}},
|
||||||
"hostaliases-pod": {&api.Pod{}},
|
"dual-stack-preferred-ipfamilies-svc": {&api.Service{}},
|
||||||
"ingress": {&networking.Ingress{}},
|
"dual-stack-preferred-svc": {&api.Service{}},
|
||||||
"network-policy-allow-all-egress": {&networking.NetworkPolicy{}},
|
"external-lb": {&networking.IngressClass{}},
|
||||||
"network-policy-allow-all-ingress": {&networking.NetworkPolicy{}},
|
"example-ingress": {&networking.Ingress{}},
|
||||||
"network-policy-default-deny-egress": {&networking.NetworkPolicy{}},
|
"hostaliases-pod": {&api.Pod{}},
|
||||||
"network-policy-default-deny-ingress": {&networking.NetworkPolicy{}},
|
"ingress-resource-backend": {&networking.Ingress{}},
|
||||||
"network-policy-default-deny-all": {&networking.NetworkPolicy{}},
|
"ingress-wildcard-host": {&networking.Ingress{}},
|
||||||
"nginx-policy": {&networking.NetworkPolicy{}},
|
"minimal-ingress": {&networking.Ingress{}},
|
||||||
"nginx-secure-app": {&api.Service{}, &apps.Deployment{}},
|
"name-virtual-host-ingress": {&networking.Ingress{}},
|
||||||
"nginx-svc": {&api.Service{}},
|
"name-virtual-host-ingress-no-third-host": {&networking.Ingress{}},
|
||||||
"run-my-nginx": {&apps.Deployment{}},
|
"network-policy-allow-all-egress": {&networking.NetworkPolicy{}},
|
||||||
|
"network-policy-allow-all-ingress": {&networking.NetworkPolicy{}},
|
||||||
|
"network-policy-default-deny-egress": {&networking.NetworkPolicy{}},
|
||||||
|
"network-policy-default-deny-ingress": {&networking.NetworkPolicy{}},
|
||||||
|
"network-policy-default-deny-all": {&networking.NetworkPolicy{}},
|
||||||
|
"nginx-policy": {&networking.NetworkPolicy{}},
|
||||||
|
"nginx-secure-app": {&api.Service{}, &apps.Deployment{}},
|
||||||
|
"nginx-svc": {&api.Service{}},
|
||||||
|
"run-my-nginx": {&apps.Deployment{}},
|
||||||
|
"simple-fanout-example": {&networking.Ingress{}},
|
||||||
|
"test-ingress": {&networking.Ingress{}},
|
||||||
|
"tls-example-ingress": {&networking.Ingress{}},
|
||||||
},
|
},
|
||||||
"windows": {
|
"windows": {
|
||||||
"configmap-pod": {&api.ConfigMap{}, &api.Pod{}},
|
"configmap-pod": {&api.ConfigMap{}, &api.Pod{}},
|
||||||
|
|||||||
@@ -1,34 +1,38 @@
|
|||||||
module k8s.io/website
|
module k8s.io/website
|
||||||
|
|
||||||
go 1.14
|
go 1.15
|
||||||
|
|
||||||
require (
|
require (
|
||||||
k8s.io/apimachinery v0.18.4
|
k8s.io/apimachinery v0.20.0
|
||||||
k8s.io/kubernetes v1.18.4
|
k8s.io/kubernetes v1.20.0
|
||||||
)
|
)
|
||||||
|
|
||||||
replace (
|
replace (
|
||||||
k8s.io/api => k8s.io/api v0.18.4
|
k8s.io/api => k8s.io/api v0.20.0
|
||||||
k8s.io/apiextensions-apiserver => k8s.io/apiextensions-apiserver v0.18.4
|
k8s.io/apiextensions-apiserver => k8s.io/apiextensions-apiserver v0.20.0
|
||||||
k8s.io/apimachinery => k8s.io/apimachinery v0.18.4
|
k8s.io/apimachinery => k8s.io/apimachinery v0.20.0
|
||||||
k8s.io/apiserver => k8s.io/apiserver v0.18.4
|
k8s.io/apiserver => k8s.io/apiserver v0.20.0
|
||||||
k8s.io/cli-runtime => k8s.io/cli-runtime v0.18.4
|
k8s.io/cli-runtime => k8s.io/cli-runtime v0.20.0
|
||||||
k8s.io/client-go => k8s.io/client-go v0.18.4
|
k8s.io/client-go => k8s.io/client-go v0.20.0
|
||||||
k8s.io/cloud-provider => k8s.io/cloud-provider v0.18.4
|
k8s.io/cloud-provider => k8s.io/cloud-provider v0.20.0
|
||||||
k8s.io/cluster-bootstrap => k8s.io/cluster-bootstrap v0.18.4
|
k8s.io/cluster-bootstrap => k8s.io/cluster-bootstrap v0.20.0
|
||||||
k8s.io/code-generator => k8s.io/code-generator v0.18.4
|
k8s.io/code-generator => k8s.io/code-generator v0.20.0
|
||||||
k8s.io/component-base => k8s.io/component-base v0.18.4
|
k8s.io/component-base => k8s.io/component-base v0.20.0
|
||||||
k8s.io/cri-api => k8s.io/cri-api v0.18.4
|
k8s.io/component-helpers => k8s.io/component-helpers v0.20.0
|
||||||
k8s.io/csi-translation-lib => k8s.io/csi-translation-lib v0.18.4
|
k8s.io/controller-manager => k8s.io/controller-manager v0.20.0
|
||||||
k8s.io/kube-aggregator => k8s.io/kube-aggregator v0.18.4
|
k8s.io/cri-api => k8s.io/cri-api v0.20.0
|
||||||
k8s.io/kube-controller-manager => k8s.io/kube-controller-manager v0.18.4
|
k8s.io/csi-translation-lib => k8s.io/csi-translation-lib v0.20.0
|
||||||
k8s.io/kube-proxy => k8s.io/kube-proxy v0.18.4
|
k8s.io/kube-aggregator => k8s.io/kube-aggregator v0.20.0
|
||||||
k8s.io/kube-scheduler => k8s.io/kube-scheduler v0.18.4
|
k8s.io/kube-controller-manager => k8s.io/kube-controller-manager v0.20.0
|
||||||
k8s.io/kubectl => k8s.io/kubectl v0.18.4
|
k8s.io/kube-proxy => k8s.io/kube-proxy v0.20.0
|
||||||
k8s.io/kubelet => k8s.io/kubelet v0.18.4
|
k8s.io/kube-scheduler => k8s.io/kube-scheduler v0.20.0
|
||||||
k8s.io/legacy-cloud-providers => k8s.io/legacy-cloud-providers v0.18.4
|
k8s.io/kubectl => k8s.io/kubectl v0.20.0
|
||||||
k8s.io/metrics => k8s.io/metrics v0.18.4
|
k8s.io/kubelet => k8s.io/kubelet v0.20.0
|
||||||
k8s.io/sample-apiserver => k8s.io/sample-apiserver v0.18.4
|
k8s.io/kubernetes => k8s.io/kubernetes v1.20.0
|
||||||
k8s.io/sample-cli-plugin => k8s.io/sample-cli-plugin v0.18.4
|
k8s.io/legacy-cloud-providers => k8s.io/legacy-cloud-providers v0.20.0
|
||||||
k8s.io/sample-controller => k8s.io/sample-controller v0.18.4
|
k8s.io/metrics => k8s.io/metrics v0.20.0
|
||||||
|
k8s.io/mount-utils => k8s.io/mount-utils v0.20.0
|
||||||
|
k8s.io/sample-apiserver => k8s.io/sample-apiserver v0.20.0
|
||||||
|
k8s.io/sample-cli-plugin => k8s.io/sample-cli-plugin v0.20.0
|
||||||
|
k8s.io/sample-controller => k8s.io/sample-controller v0.20.0
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user