diff --git a/cmd/integration/integration.go b/cmd/integration/integration.go index 33b9cd64cff..2ce6376e42d 100644 --- a/cmd/integration/integration.go +++ b/cmd/integration/integration.go @@ -622,6 +622,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()] diff --git a/examples/examples_test.go b/examples/examples_test.go index 332ed89a8b0..877d84829e8 100644 --- a/examples/examples_test.go +++ b/examples/examples_test.go @@ -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{}, diff --git a/hack/test-go.sh b/hack/test-go.sh index 0604a092356..3cb94d88b0c 100755 --- a/hack/test-go.sh +++ b/hack/test-go.sh @@ -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"} diff --git a/pkg/api/latest/latest_test.go b/pkg/api/latest/latest_test.go index 881ac4b8558..8169443ae58 100644 --- a/pkg/api/latest/latest_test.go +++ b/pkg/api/latest/latest_test.go @@ -21,6 +21,7 @@ import ( "testing" internal "github.com/GoogleCloudPlatform/kubernetes/pkg/api" + _ "github.com/GoogleCloudPlatform/kubernetes/pkg/api/v1" ) func TestResourceVersioner(t *testing.T) { diff --git a/pkg/api/v1beta3/defaults.go b/pkg/api/v1beta3/defaults.go index d542e5f3047..74f931dd136 100644 --- a/pkg/api/v1beta3/defaults.go +++ b/pkg/api/v1beta3/defaults.go @@ -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{} } diff --git a/pkg/api/validation/testdata/v1/invalidPod.yaml b/pkg/api/validation/testdata/v1/invalidPod.yaml new file mode 100644 index 00000000000..059b2dc7b2e --- /dev/null +++ b/pkg/api/validation/testdata/v1/invalidPod.yaml @@ -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 diff --git a/pkg/api/validation/testdata/v1/invalidPod1.json b/pkg/api/validation/testdata/v1/invalidPod1.json new file mode 100644 index 00000000000..df256426c45 --- /dev/null +++ b/pkg/api/validation/testdata/v1/invalidPod1.json @@ -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" + } + ] + } +} diff --git a/pkg/api/validation/testdata/v1/invalidPod2.json b/pkg/api/validation/testdata/v1/invalidPod2.json new file mode 100644 index 00000000000..97f02ac1336 --- /dev/null +++ b/pkg/api/validation/testdata/v1/invalidPod2.json @@ -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" + } + ] + } + ] + } +} diff --git a/pkg/api/validation/testdata/v1/invalidPod3.json b/pkg/api/validation/testdata/v1/invalidPod3.json new file mode 100644 index 00000000000..78bc87e8cea --- /dev/null +++ b/pkg/api/validation/testdata/v1/invalidPod3.json @@ -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" + } + ] + } + ] + } +} diff --git a/pkg/api/validation/testdata/v1/validPod.yaml b/pkg/api/validation/testdata/v1/validPod.yaml new file mode 100644 index 00000000000..b8bdbdf6983 --- /dev/null +++ b/pkg/api/validation/testdata/v1/validPod.yaml @@ -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 diff --git a/pkg/kubelet/config/http_test.go b/pkg/kubelet/config/http_test.go index 6843ac864b1..5a92ab75815 100644 --- a/pkg/kubelet/config/http_test.go +++ b/pkg/kubelet/config/http_test.go @@ -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,8 @@ func TestExtractPodsFromHTTP(t *testing.T) { Image: "foo", TerminationMessagePath: "/dev/termination-log", ImagePullPolicy: "Always", - SecurityContext: securitycontext.ValidSecurityContextWithContainerDefaults()}}, + //SecurityContext: securitycontext.ValidSecurityContextWithContainerDefaults() + }}, }, }), }, @@ -214,7 +214,7 @@ func TestExtractPodsFromHTTP(t *testing.T) { Image: "foo", TerminationMessagePath: "/dev/termination-log", ImagePullPolicy: "Always", - SecurityContext: securitycontext.ValidSecurityContextWithContainerDefaults()}}, + }}, }, }, &api.Pod{ @@ -234,7 +234,7 @@ func TestExtractPodsFromHTTP(t *testing.T) { Image: "bar", TerminationMessagePath: "/dev/termination-log", ImagePullPolicy: "IfNotPresent", - SecurityContext: securitycontext.ValidSecurityContextWithContainerDefaults()}}, + }}, }, }), },