mirror of
				https://github.com/optim-enterprises-bv/kubernetes.git
				synced 2025-11-03 19:58:17 +00:00 
			
		
		
		
	add v1 tests to hack/test-go; let default value of Container.SecurityContext to be nil
This commit is contained in:
		@@ -623,6 +623,23 @@ func runPatchTest(c *client.Client) {
 | 
			
		||||
				[]byte(`{"metadata":{"labels":{"$patch":"replace"}}}`),
 | 
			
		||||
			},
 | 
			
		||||
		},
 | 
			
		||||
		"v1": {
 | 
			
		||||
			api.JSONPatchType: {
 | 
			
		||||
				[]byte(`[{"op":"add","path":"/metadata/labels","value":{"foo":"bar","baz":"qux"}}]`),
 | 
			
		||||
				[]byte(`[{"op":"remove","path":"/metadata/labels/foo"}]`),
 | 
			
		||||
				[]byte(`[{"op":"remove","path":"/metadata/labels"}]`),
 | 
			
		||||
			},
 | 
			
		||||
			api.MergePatchType: {
 | 
			
		||||
				[]byte(`{"metadata":{"labels":{"foo":"bar","baz":"qux"}}}`),
 | 
			
		||||
				[]byte(`{"metadata":{"labels":{"foo":null}}}`),
 | 
			
		||||
				[]byte(`{"metadata":{"labels":null}}`),
 | 
			
		||||
			},
 | 
			
		||||
			api.StrategicMergePatchType: {
 | 
			
		||||
				[]byte(`{"metadata":{"labels":{"foo":"bar","baz":"qux"}}}`),
 | 
			
		||||
				[]byte(`{"metadata":{"labels":{"foo":null}}}`),
 | 
			
		||||
				[]byte(`{"metadata":{"labels":{"$patch":"replace"}}}`),
 | 
			
		||||
			},
 | 
			
		||||
		},
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	pb := patchBodies[c.APIVersion()]
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										24
									
								
								cmd/integration/v1-controller.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										24
									
								
								cmd/integration/v1-controller.json
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,24 @@
 | 
			
		||||
{
 | 
			
		||||
  "kind": "ReplicationController",
 | 
			
		||||
  "apiVersion": "v1",
 | 
			
		||||
  "metadata": {
 | 
			
		||||
     "name": "nginx-controller",
 | 
			
		||||
     "labels": {"name": "nginx"}
 | 
			
		||||
  },
 | 
			
		||||
  "spec": {
 | 
			
		||||
    "replicas": 2,
 | 
			
		||||
    "selector": {"name": "nginx"},
 | 
			
		||||
    "template": {
 | 
			
		||||
       "metadata": {
 | 
			
		||||
          "labels": {"name": "nginx"}
 | 
			
		||||
       },
 | 
			
		||||
       "spec": {
 | 
			
		||||
           "containers": [{
 | 
			
		||||
             "name": "nginx",
 | 
			
		||||
             "image": "nginx",
 | 
			
		||||
             "ports": [{"containerPort": 80}]
 | 
			
		||||
           }]
 | 
			
		||||
       }
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
@@ -140,6 +140,7 @@ func TestExampleObjectSchemas(t *testing.T) {
 | 
			
		||||
	cases := map[string]map[string]runtime.Object{
 | 
			
		||||
		"../cmd/integration": {
 | 
			
		||||
			"v1beta3-controller": &api.ReplicationController{},
 | 
			
		||||
			"v1-controller":      &api.ReplicationController{},
 | 
			
		||||
		},
 | 
			
		||||
		"../examples/guestbook": {
 | 
			
		||||
			"frontend-controller":     &api.ReplicationController{},
 | 
			
		||||
 
 | 
			
		||||
@@ -52,7 +52,7 @@ KUBE_RACE=${KUBE_RACE:-}   # use KUBE_RACE="-race" to enable race testing
 | 
			
		||||
# Set to the goveralls binary path to report coverage results to Coveralls.io.
 | 
			
		||||
KUBE_GOVERALLS_BIN=${KUBE_GOVERALLS_BIN:-}
 | 
			
		||||
# Comma separated list of API Versions that should be tested.
 | 
			
		||||
KUBE_TEST_API_VERSIONS=${KUBE_TEST_API_VERSIONS:-"v1beta3"}
 | 
			
		||||
KUBE_TEST_API_VERSIONS=${KUBE_TEST_API_VERSIONS:-"v1beta3,v1"}
 | 
			
		||||
# Run tests with the standard (registry) and a custom etcd prefix
 | 
			
		||||
# (kubernetes.io/registry).
 | 
			
		||||
KUBE_TEST_ETCD_PREFIXES=${KUBE_TEST_ETCD_PREFIXES:-"registry,kubernetes.io/registry"}
 | 
			
		||||
 
 | 
			
		||||
@@ -171,6 +171,9 @@ func defaultHostNetworkPorts(containers *[]Container) {
 | 
			
		||||
// defaultSecurityContext performs the downward and upward merges of a pod definition
 | 
			
		||||
func defaultSecurityContext(container *Container) {
 | 
			
		||||
	if container.SecurityContext == nil {
 | 
			
		||||
		if (len(container.Capabilities.Add) == 0) && (len(container.Capabilities.Drop) == 0) && (container.Privileged == false) {
 | 
			
		||||
			return
 | 
			
		||||
		}
 | 
			
		||||
		glog.V(5).Infof("creating security context for container %s", container.Name)
 | 
			
		||||
		container.SecurityContext = &SecurityContext{}
 | 
			
		||||
	}
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										11
									
								
								pkg/api/validation/testdata/v1/invalidPod.yaml
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								pkg/api/validation/testdata/v1/invalidPod.yaml
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,11 @@
 | 
			
		||||
apiVersion: v1
 | 
			
		||||
kind: Pod
 | 
			
		||||
metadata:
 | 
			
		||||
  labels:
 | 
			
		||||
    name: redis-master
 | 
			
		||||
  name: name
 | 
			
		||||
spec:
 | 
			
		||||
  containers:
 | 
			
		||||
  - args: "this is a bad command"
 | 
			
		||||
    image: redis
 | 
			
		||||
    name: master
 | 
			
		||||
							
								
								
									
										19
									
								
								pkg/api/validation/testdata/v1/invalidPod1.json
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								pkg/api/validation/testdata/v1/invalidPod1.json
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,19 @@
 | 
			
		||||
{
 | 
			
		||||
  "kind": "Pod",
 | 
			
		||||
  "apiVersion": "v1",
 | 
			
		||||
  "metadata": {
 | 
			
		||||
    "name": "name",
 | 
			
		||||
    "labels": {
 | 
			
		||||
      "name": "redis-master"
 | 
			
		||||
    }
 | 
			
		||||
  },
 | 
			
		||||
  "spec": {
 | 
			
		||||
    "containers": [
 | 
			
		||||
      {
 | 
			
		||||
        "name": "master",
 | 
			
		||||
        "image": "redis",
 | 
			
		||||
        "args": "this is a bad command"
 | 
			
		||||
      }
 | 
			
		||||
    ]
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										35
									
								
								pkg/api/validation/testdata/v1/invalidPod2.json
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										35
									
								
								pkg/api/validation/testdata/v1/invalidPod2.json
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,35 @@
 | 
			
		||||
{
 | 
			
		||||
  "kind": "Pod",
 | 
			
		||||
  "apiVersion": "v1",
 | 
			
		||||
  "metadata": {
 | 
			
		||||
    "name": "apache-php",
 | 
			
		||||
    "labels": {
 | 
			
		||||
      "name": "apache-php"
 | 
			
		||||
    }
 | 
			
		||||
  },
 | 
			
		||||
  "spec": {
 | 
			
		||||
    "volumes": [{
 | 
			
		||||
        "name": "shared-disk"
 | 
			
		||||
    }],
 | 
			
		||||
    "containers": [
 | 
			
		||||
      {
 | 
			
		||||
        "name": "apache-php",
 | 
			
		||||
        "image": "php:5.6.2-apache",
 | 
			
		||||
        "ports": [
 | 
			
		||||
          {
 | 
			
		||||
            "name": "apache",
 | 
			
		||||
            "hostPort": "13380",
 | 
			
		||||
            "containerPort": 80,
 | 
			
		||||
            "protocol": "TCP"
 | 
			
		||||
          }
 | 
			
		||||
        ],
 | 
			
		||||
        "volumeMounts": [
 | 
			
		||||
          {
 | 
			
		||||
            "name": "shared-disk",
 | 
			
		||||
            "mountPath": "/var/www/html"
 | 
			
		||||
          }
 | 
			
		||||
        ]
 | 
			
		||||
      }
 | 
			
		||||
    ]
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										35
									
								
								pkg/api/validation/testdata/v1/invalidPod3.json
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										35
									
								
								pkg/api/validation/testdata/v1/invalidPod3.json
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,35 @@
 | 
			
		||||
{
 | 
			
		||||
  "kind": "Pod",
 | 
			
		||||
  "apiVersion": "v1",
 | 
			
		||||
  "metadata": {
 | 
			
		||||
    "name": "apache-php",
 | 
			
		||||
    "labels": {
 | 
			
		||||
      "name": "apache-php"
 | 
			
		||||
    }
 | 
			
		||||
  },
 | 
			
		||||
  "spec": {
 | 
			
		||||
    "volumes": [
 | 
			
		||||
        "name": "shared-disk"
 | 
			
		||||
    ],
 | 
			
		||||
    "containers": [
 | 
			
		||||
      {
 | 
			
		||||
        "name": "apache-php",
 | 
			
		||||
        "image": "php:5.6.2-apache",
 | 
			
		||||
        "ports": [
 | 
			
		||||
          {
 | 
			
		||||
            "name": "apache",
 | 
			
		||||
            "hostPort": 13380,
 | 
			
		||||
            "containerPort": 80,
 | 
			
		||||
            "protocol": "TCP"
 | 
			
		||||
          }
 | 
			
		||||
        ],
 | 
			
		||||
        "volumeMounts": [
 | 
			
		||||
          {
 | 
			
		||||
            "name": "shared-disk",
 | 
			
		||||
            "mountPath": "/var/www/html"
 | 
			
		||||
          }
 | 
			
		||||
        ]
 | 
			
		||||
      }
 | 
			
		||||
    ]
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										16
									
								
								pkg/api/validation/testdata/v1/validPod.yaml
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								pkg/api/validation/testdata/v1/validPod.yaml
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,16 @@
 | 
			
		||||
apiVersion: v1
 | 
			
		||||
kind: Pod
 | 
			
		||||
metadata:
 | 
			
		||||
  labels:
 | 
			
		||||
    name: redis-master
 | 
			
		||||
  name: name
 | 
			
		||||
spec:
 | 
			
		||||
  containers:
 | 
			
		||||
  - args:
 | 
			
		||||
    - this
 | 
			
		||||
    - is
 | 
			
		||||
    - an
 | 
			
		||||
    - ok
 | 
			
		||||
    - command
 | 
			
		||||
    image: redis
 | 
			
		||||
    name: master
 | 
			
		||||
@@ -27,7 +27,6 @@ import (
 | 
			
		||||
	"github.com/GoogleCloudPlatform/kubernetes/pkg/api/validation"
 | 
			
		||||
	"github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet"
 | 
			
		||||
	"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
 | 
			
		||||
	"github.com/GoogleCloudPlatform/kubernetes/pkg/securitycontext"
 | 
			
		||||
	"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
 | 
			
		||||
	"github.com/GoogleCloudPlatform/kubernetes/pkg/util/errors"
 | 
			
		||||
)
 | 
			
		||||
@@ -161,7 +160,7 @@ func TestExtractPodsFromHTTP(t *testing.T) {
 | 
			
		||||
							Image: "foo",
 | 
			
		||||
							TerminationMessagePath: "/dev/termination-log",
 | 
			
		||||
							ImagePullPolicy:        "Always",
 | 
			
		||||
							SecurityContext:        securitycontext.ValidSecurityContextWithContainerDefaults()}},
 | 
			
		||||
						}},
 | 
			
		||||
					},
 | 
			
		||||
				}),
 | 
			
		||||
		},
 | 
			
		||||
@@ -214,7 +213,7 @@ func TestExtractPodsFromHTTP(t *testing.T) {
 | 
			
		||||
							Image: "foo",
 | 
			
		||||
							TerminationMessagePath: "/dev/termination-log",
 | 
			
		||||
							ImagePullPolicy:        "Always",
 | 
			
		||||
							SecurityContext:        securitycontext.ValidSecurityContextWithContainerDefaults()}},
 | 
			
		||||
						}},
 | 
			
		||||
					},
 | 
			
		||||
				},
 | 
			
		||||
				&api.Pod{
 | 
			
		||||
@@ -234,7 +233,7 @@ func TestExtractPodsFromHTTP(t *testing.T) {
 | 
			
		||||
							Image: "bar",
 | 
			
		||||
							TerminationMessagePath: "/dev/termination-log",
 | 
			
		||||
							ImagePullPolicy:        "IfNotPresent",
 | 
			
		||||
							SecurityContext:        securitycontext.ValidSecurityContextWithContainerDefaults()}},
 | 
			
		||||
						}},
 | 
			
		||||
					},
 | 
			
		||||
				}),
 | 
			
		||||
		},
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user