Fix examples tests

This PR updates the go.mod file so that tests of the example manifests
are run against the 1.20 branch. The missing test cases for newly added
examples are also added. To perform tests on your local machine, run the
following command on the root of your local clone:

```
go test k8s.io/website/content/en/examples
```
pull/26086/head
Qiming Teng 2020-10-26 22:13:24 +08:00 committed by Qiming Teng
parent a0d5681271
commit 06228c06a9
3 changed files with 624 additions and 55 deletions

View File

@ -148,6 +148,11 @@ func getCodecForObject(obj runtime.Object) (runtime.Codec, error) {
}
func validateObject(obj runtime.Object) (errors field.ErrorList) {
podValidationOptions := validation.PodValidationOptions{
AllowMultipleHugePageResources: true,
AllowDownwardAPIHugePages: true,
}
// Enable CustomPodDNS for testing
// feature.DefaultFeatureGate.Set("CustomPodDNS=true")
switch t := obj.(type) {
@ -182,7 +187,7 @@ func validateObject(obj runtime.Object) (errors field.ErrorList) {
opts := validation.PodValidationOptions{
AllowMultipleHugePageResources: true,
}
errors = validation.ValidatePod(t, opts)
errors = validation.ValidatePodCreate(t, opts)
case *api.PodList:
for i := range t.Items {
errors = append(errors, validateObject(&t.Items[i])...)
@ -191,12 +196,12 @@ func validateObject(obj runtime.Object) (errors field.ErrorList) {
if t.Namespace == "" {
t.Namespace = api.NamespaceDefault
}
errors = validation.ValidatePodTemplate(t)
errors = validation.ValidatePodTemplate(t, podValidationOptions)
case *api.ReplicationController:
if t.Namespace == "" {
t.Namespace = api.NamespaceDefault
}
errors = validation.ValidateReplicationController(t)
errors = validation.ValidateReplicationController(t, podValidationOptions)
case *api.ReplicationControllerList:
for i := range t.Items {
errors = append(errors, validateObject(&t.Items[i])...)
@ -215,7 +220,11 @@ func validateObject(obj runtime.Object) (errors field.ErrorList) {
if t.Namespace == "" {
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:
if t.Namespace == "" {
t.Namespace = api.NamespaceDefault
@ -250,12 +259,12 @@ func validateObject(obj runtime.Object) (errors field.ErrorList) {
if t.Namespace == "" {
t.Namespace = api.NamespaceDefault
}
errors = apps_validation.ValidateDaemonSet(t)
errors = apps_validation.ValidateDaemonSet(t, podValidationOptions)
case *apps.Deployment:
if t.Namespace == "" {
t.Namespace = api.NamespaceDefault
}
errors = apps_validation.ValidateDeployment(t)
errors = apps_validation.ValidateDeployment(t, podValidationOptions)
case *networking.Ingress:
if t.Namespace == "" {
t.Namespace = api.NamespaceDefault
@ -265,18 +274,30 @@ func validateObject(obj runtime.Object) (errors field.ErrorList) {
Version: legacyscheme.Scheme.PrioritizedVersionsForGroup(networking.GroupName)[0].Version,
}
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:
errors = policy_validation.ValidatePodSecurityPolicy(t)
case *apps.ReplicaSet:
if t.Namespace == "" {
t.Namespace = api.NamespaceDefault
}
errors = apps_validation.ValidateReplicaSet(t)
errors = apps_validation.ValidateReplicaSet(t, podValidationOptions)
case *batch.CronJob:
if t.Namespace == "" {
t.Namespace = api.NamespaceDefault
}
errors = batch_validation.ValidateCronJob(t)
errors = batch_validation.ValidateCronJob(t, podValidationOptions)
case *networking.NetworkPolicy:
if t.Namespace == "" {
t.Namespace = api.NamespaceDefault
@ -287,6 +308,9 @@ func validateObject(obj runtime.Object) (errors field.ErrorList) {
t.Namespace = api.NamespaceDefault
}
errors = policy_validation.ValidatePodDisruptionBudget(t)
case *rbac.ClusterRole:
// clusterole does not accept namespace
errors = rbac_validation.ValidateClusterRole(t)
case *rbac.ClusterRoleBinding:
// clusterolebinding does not accept namespace
errors = rbac_validation.ValidateClusterRoleBinding(t)
@ -414,6 +438,7 @@ func TestExampleObjectSchemas(t *testing.T) {
"storagelimits": {&api.LimitRange{}},
},
"admin/sched": {
"clusterrole": {&rbac.ClusterRole{}},
"my-scheduler": {&api.ServiceAccount{}, &rbac.ClusterRoleBinding{}, &rbac.ClusterRoleBinding{}, &apps.Deployment{}},
"pod1": {&api.Pod{}},
"pod2": {&api.Pod{}},
@ -539,6 +564,7 @@ func TestExampleObjectSchemas(t *testing.T) {
"dapi-envars-pod": {&api.Pod{}},
"dapi-volume": {&api.Pod{}},
"dapi-volume-resources": {&api.Pod{}},
"dependent-envars": {&api.Pod{}},
"envars": {&api.Pod{}},
"pod-multiple-secret-env-variable": {&api.Pod{}},
"pod-secret-envFrom": {&api.Pod{}},
@ -596,29 +622,41 @@ func TestExampleObjectSchemas(t *testing.T) {
"load-balancer-example": {&apps.Deployment{}},
},
"service/access": {
"frontend": {&api.Service{}, &apps.Deployment{}},
"hello-application": {&apps.Deployment{}},
"hello-service": {&api.Service{}},
"hello": {&apps.Deployment{}},
"backend-deployment": {&apps.Deployment{}},
"backend-service": {&api.Service{}},
"frontend-deployment": {&apps.Deployment{}},
"frontend-service": {&api.Service{}},
"hello-application": {&apps.Deployment{}},
},
"service/networking": {
"curlpod": {&apps.Deployment{}},
"custom-dns": {&api.Pod{}},
"dual-stack-default-svc": {&api.Service{}},
"dual-stack-ipv4-svc": {&api.Service{}},
"dual-stack-ipv6-lb-svc": {&api.Service{}},
"dual-stack-ipv6-svc": {&api.Service{}},
"hostaliases-pod": {&api.Pod{}},
"ingress": {&networking.Ingress{}},
"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{}},
"curlpod": {&apps.Deployment{}},
"custom-dns": {&api.Pod{}},
"dual-stack-default-svc": {&api.Service{}},
"dual-stack-ipfamilies-ipv6": {&api.Service{}},
"dual-stack-ipv6-svc": {&api.Service{}},
"dual-stack-prefer-ipv6-lb-svc": {&api.Service{}},
"dual-stack-preferred-ipfamilies-svc": {&api.Service{}},
"dual-stack-preferred-svc": {&api.Service{}},
"external-lb": {&networking.IngressClass{}},
"example-ingress": {&networking.Ingress{}},
"hostaliases-pod": {&api.Pod{}},
"ingress-resource-backend": {&networking.Ingress{}},
"ingress-wildcard-host": {&networking.Ingress{}},
"minimal-ingress": {&networking.Ingress{}},
"name-virtual-host-ingress": {&networking.Ingress{}},
"name-virtual-host-ingress-no-third-host": {&networking.Ingress{}},
"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": {
"configmap-pod": {&api.ConfigMap{}, &api.Pod{}},

56
go.mod
View File

@ -1,34 +1,38 @@
module k8s.io/website
go 1.14
go 1.15
require (
k8s.io/apimachinery v0.18.4
k8s.io/kubernetes v1.18.4
k8s.io/apimachinery v0.20.0
k8s.io/kubernetes v1.20.0
)
replace (
k8s.io/api => k8s.io/api v0.18.4
k8s.io/apiextensions-apiserver => k8s.io/apiextensions-apiserver v0.18.4
k8s.io/apimachinery => k8s.io/apimachinery v0.18.4
k8s.io/apiserver => k8s.io/apiserver v0.18.4
k8s.io/cli-runtime => k8s.io/cli-runtime v0.18.4
k8s.io/client-go => k8s.io/client-go v0.18.4
k8s.io/cloud-provider => k8s.io/cloud-provider v0.18.4
k8s.io/cluster-bootstrap => k8s.io/cluster-bootstrap v0.18.4
k8s.io/code-generator => k8s.io/code-generator v0.18.4
k8s.io/component-base => k8s.io/component-base v0.18.4
k8s.io/cri-api => k8s.io/cri-api v0.18.4
k8s.io/csi-translation-lib => k8s.io/csi-translation-lib v0.18.4
k8s.io/kube-aggregator => k8s.io/kube-aggregator v0.18.4
k8s.io/kube-controller-manager => k8s.io/kube-controller-manager v0.18.4
k8s.io/kube-proxy => k8s.io/kube-proxy v0.18.4
k8s.io/kube-scheduler => k8s.io/kube-scheduler v0.18.4
k8s.io/kubectl => k8s.io/kubectl v0.18.4
k8s.io/kubelet => k8s.io/kubelet v0.18.4
k8s.io/legacy-cloud-providers => k8s.io/legacy-cloud-providers v0.18.4
k8s.io/metrics => k8s.io/metrics v0.18.4
k8s.io/sample-apiserver => k8s.io/sample-apiserver v0.18.4
k8s.io/sample-cli-plugin => k8s.io/sample-cli-plugin v0.18.4
k8s.io/sample-controller => k8s.io/sample-controller v0.18.4
k8s.io/api => k8s.io/api v0.20.0
k8s.io/apiextensions-apiserver => k8s.io/apiextensions-apiserver v0.20.0
k8s.io/apimachinery => k8s.io/apimachinery v0.20.0
k8s.io/apiserver => k8s.io/apiserver v0.20.0
k8s.io/cli-runtime => k8s.io/cli-runtime v0.20.0
k8s.io/client-go => k8s.io/client-go v0.20.0
k8s.io/cloud-provider => k8s.io/cloud-provider v0.20.0
k8s.io/cluster-bootstrap => k8s.io/cluster-bootstrap v0.20.0
k8s.io/code-generator => k8s.io/code-generator v0.20.0
k8s.io/component-base => k8s.io/component-base v0.20.0
k8s.io/component-helpers => k8s.io/component-helpers v0.20.0
k8s.io/controller-manager => k8s.io/controller-manager v0.20.0
k8s.io/cri-api => k8s.io/cri-api v0.20.0
k8s.io/csi-translation-lib => k8s.io/csi-translation-lib v0.20.0
k8s.io/kube-aggregator => k8s.io/kube-aggregator v0.20.0
k8s.io/kube-controller-manager => k8s.io/kube-controller-manager v0.20.0
k8s.io/kube-proxy => k8s.io/kube-proxy v0.20.0
k8s.io/kube-scheduler => k8s.io/kube-scheduler v0.20.0
k8s.io/kubectl => k8s.io/kubectl v0.20.0
k8s.io/kubelet => k8s.io/kubelet v0.20.0
k8s.io/kubernetes => k8s.io/kubernetes v1.20.0
k8s.io/legacy-cloud-providers => k8s.io/legacy-cloud-providers v0.20.0
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
)

527
go.sum

File diff suppressed because it is too large Load Diff