123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170 |
- package testing
- import (
- "testing"
- "k8s.io/api/core/v1"
- "k8s.io/apimachinery/pkg/runtime"
- "k8s.io/apimachinery/pkg/util/validation/field"
- "k8s.io/kubernetes/pkg/api/testing/compat"
- api "k8s.io/kubernetes/pkg/apis/core"
- "k8s.io/kubernetes/pkg/apis/core/validation"
- _ "k8s.io/kubernetes/pkg/apis/core/install"
- )
- func TestCompatibility_v1_PodSecurityContext(t *testing.T) {
- cases := []struct {
- name string
- input string
- expectedKeys map[string]string
- absentKeys []string
- }{
- {
- name: "hostNetwork = true",
- input: `
- {
- "kind":"Pod",
- "apiVersion":"v1",
- "metadata":{"name":"my-pod-name", "namespace":"my-pod-namespace"},
- "spec": {
- "hostNetwork": true,
- "containers":[{
- "name":"a",
- "image":"my-container-image"
- }]
- }
- }
- `,
- expectedKeys: map[string]string{
- "spec.hostNetwork": "true",
- },
- },
- {
- name: "hostNetwork = false",
- input: `
- {
- "kind":"Pod",
- "apiVersion":"v1",
- "metadata":{"name":"my-pod-name", "namespace":"my-pod-namespace"},
- "spec": {
- "hostNetwork": false,
- "containers":[{
- "name":"a",
- "image":"my-container-image"
- }]
- }
- }
- `,
- absentKeys: []string{
- "spec.hostNetwork",
- },
- },
- {
- name: "hostIPC = true",
- input: `
- {
- "kind":"Pod",
- "apiVersion":"v1",
- "metadata":{"name":"my-pod-name", "namespace":"my-pod-namespace"},
- "spec": {
- "hostIPC": true,
- "containers":[{
- "name":"a",
- "image":"my-container-image"
- }]
- }
- }
- `,
- expectedKeys: map[string]string{
- "spec.hostIPC": "true",
- },
- },
- {
- name: "hostIPC = false",
- input: `
- {
- "kind":"Pod",
- "apiVersion":"v1",
- "metadata":{"name":"my-pod-name", "namespace":"my-pod-namespace"},
- "spec": {
- "hostIPC": false,
- "containers":[{
- "name":"a",
- "image":"my-container-image"
- }]
- }
- }
- `,
- absentKeys: []string{
- "spec.hostIPC",
- },
- },
- {
- name: "hostPID = true",
- input: `
- {
- "kind":"Pod",
- "apiVersion":"v1",
- "metadata":{"name":"my-pod-name", "namespace":"my-pod-namespace"},
- "spec": {
- "hostPID": true,
- "containers":[{
- "name":"a",
- "image":"my-container-image"
- }]
- }
- }
- `,
- expectedKeys: map[string]string{
- "spec.hostPID": "true",
- },
- },
- {
- name: "hostPID = false",
- input: `
- {
- "kind":"Pod",
- "apiVersion":"v1",
- "metadata":{"name":"my-pod-name", "namespace":"my-pod-namespace"},
- "spec": {
- "hostPID": false,
- "containers":[{
- "name":"a",
- "image":"my-container-image"
- }]
- }
- }
- `,
- absentKeys: []string{
- "spec.hostPID",
- },
- },
- }
- validator := func(obj runtime.Object) field.ErrorList {
- return validation.ValidatePodSpec(&(obj.(*api.Pod).Spec), field.NewPath("spec"))
- }
- for _, tc := range cases {
- t.Logf("Testing 1.0.0 backward compatibility for %v", tc.name)
- compat.TestCompatibility(t, v1.SchemeGroupVersion, []byte(tc.input), validator, tc.expectedKeys, tc.absentKeys)
- }
- }
|