mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-25 20:53:33 +00:00
add v1 tests to hack/test-go; let default value of Container.SecurityContext to be nil
This commit is contained in:
parent
a6d68bd76d
commit
ff6947625d
@ -622,6 +622,23 @@ func runPatchTest(c *client.Client) {
|
|||||||
[]byte(`{"metadata":{"labels":{"$patch":"replace"}}}`),
|
[]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()]
|
pb := patchBodies[c.APIVersion()]
|
||||||
|
@ -140,6 +140,7 @@ func TestExampleObjectSchemas(t *testing.T) {
|
|||||||
cases := map[string]map[string]runtime.Object{
|
cases := map[string]map[string]runtime.Object{
|
||||||
"../cmd/integration": {
|
"../cmd/integration": {
|
||||||
"v1beta3-controller": &api.ReplicationController{},
|
"v1beta3-controller": &api.ReplicationController{},
|
||||||
|
"v1-controller": &api.ReplicationController{},
|
||||||
},
|
},
|
||||||
"../examples/guestbook": {
|
"../examples/guestbook": {
|
||||||
"frontend-controller": &api.ReplicationController{},
|
"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.
|
# Set to the goveralls binary path to report coverage results to Coveralls.io.
|
||||||
KUBE_GOVERALLS_BIN=${KUBE_GOVERALLS_BIN:-}
|
KUBE_GOVERALLS_BIN=${KUBE_GOVERALLS_BIN:-}
|
||||||
# Comma separated list of API Versions that should be tested.
|
# 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
|
# Run tests with the standard (registry) and a custom etcd prefix
|
||||||
# (kubernetes.io/registry).
|
# (kubernetes.io/registry).
|
||||||
KUBE_TEST_ETCD_PREFIXES=${KUBE_TEST_ETCD_PREFIXES:-"registry,kubernetes.io/registry"}
|
KUBE_TEST_ETCD_PREFIXES=${KUBE_TEST_ETCD_PREFIXES:-"registry,kubernetes.io/registry"}
|
||||||
|
@ -21,6 +21,7 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
internal "github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
internal "github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||||
|
_ "github.com/GoogleCloudPlatform/kubernetes/pkg/api/v1"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestResourceVersioner(t *testing.T) {
|
func TestResourceVersioner(t *testing.T) {
|
||||||
|
@ -171,6 +171,9 @@ func defaultHostNetworkPorts(containers *[]Container) {
|
|||||||
// defaultSecurityContext performs the downward and upward merges of a pod definition
|
// defaultSecurityContext performs the downward and upward merges of a pod definition
|
||||||
func defaultSecurityContext(container *Container) {
|
func defaultSecurityContext(container *Container) {
|
||||||
if container.SecurityContext == nil {
|
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)
|
glog.V(5).Infof("creating security context for container %s", container.Name)
|
||||||
container.SecurityContext = &SecurityContext{}
|
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/api/validation"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/securitycontext"
|
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/util/errors"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/util/errors"
|
||||||
)
|
)
|
||||||
@ -161,7 +160,8 @@ func TestExtractPodsFromHTTP(t *testing.T) {
|
|||||||
Image: "foo",
|
Image: "foo",
|
||||||
TerminationMessagePath: "/dev/termination-log",
|
TerminationMessagePath: "/dev/termination-log",
|
||||||
ImagePullPolicy: "Always",
|
ImagePullPolicy: "Always",
|
||||||
SecurityContext: securitycontext.ValidSecurityContextWithContainerDefaults()}},
|
//SecurityContext: securitycontext.ValidSecurityContextWithContainerDefaults()
|
||||||
|
}},
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
@ -214,7 +214,7 @@ func TestExtractPodsFromHTTP(t *testing.T) {
|
|||||||
Image: "foo",
|
Image: "foo",
|
||||||
TerminationMessagePath: "/dev/termination-log",
|
TerminationMessagePath: "/dev/termination-log",
|
||||||
ImagePullPolicy: "Always",
|
ImagePullPolicy: "Always",
|
||||||
SecurityContext: securitycontext.ValidSecurityContextWithContainerDefaults()}},
|
}},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
&api.Pod{
|
&api.Pod{
|
||||||
@ -234,7 +234,7 @@ func TestExtractPodsFromHTTP(t *testing.T) {
|
|||||||
Image: "bar",
|
Image: "bar",
|
||||||
TerminationMessagePath: "/dev/termination-log",
|
TerminationMessagePath: "/dev/termination-log",
|
||||||
ImagePullPolicy: "IfNotPresent",
|
ImagePullPolicy: "IfNotPresent",
|
||||||
SecurityContext: securitycontext.ValidSecurityContextWithContainerDefaults()}},
|
}},
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user