mirror of
				https://github.com/optim-enterprises-bv/kubernetes.git
				synced 2025-11-03 19:58:17 +00:00 
			
		
		
		
	Move configmap, docker_containers, downward_api, expansion and secrets
test into common directory.
This commit is contained in:
		@@ -94,7 +94,7 @@ pkg/util/oom/oom_linux.go:		return fmt.Errorf("invalid PID %d specified for oom_
 | 
			
		||||
pkg/util/oom/oom_linux.go:	oomScoreAdjPath := path.Join("/proc", pidStr, "oom_score_adj")
 | 
			
		||||
pkg/util/oom/oom_linux.go:// Writes 'value' to /proc/<pid>/oom_score_adj for all processes in cgroup cgroupName.
 | 
			
		||||
pkg/util/oom/oom_linux.go:// Writes 'value' to /proc/<pid>/oom_score_adj. PID = 0 means self
 | 
			
		||||
test/e2e/configmap.go:						Command: []string{"/mt", "--break_on_expected_content=false", "--retry_time=120", "--file_content_in_loop=/etc/configmap-volume/data-1"},
 | 
			
		||||
test/e2e/common/configmap.go:						Command: []string{"/mt", "--break_on_expected_content=false", "--retry_time=120", "--file_content_in_loop=/etc/configmap-volume/data-1"},
 | 
			
		||||
test/e2e/common/downwardapi_volume.go:			Command: []string{"/mt", "--break_on_expected_content=false", "--retry_time=120", "--file_content_in_loop=" + filePath},
 | 
			
		||||
test/e2e/es_cluster_logging.go:		framework.Failf("No cluster_name field in Elasticsearch response: %v", esResponse)
 | 
			
		||||
test/e2e/es_cluster_logging.go:	// Check to see if have a cluster_name field.
 | 
			
		||||
 
 | 
			
		||||
@@ -1,5 +1,5 @@
 | 
			
		||||
/*
 | 
			
		||||
Copyright 2014 The Kubernetes Authors.
 | 
			
		||||
Copyright 2016 The Kubernetes Authors.
 | 
			
		||||
 | 
			
		||||
Licensed under the Apache License, Version 2.0 (the "License");
 | 
			
		||||
you may not use this file except in compliance with the License.
 | 
			
		||||
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
 | 
			
		||||
limitations under the License.
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
package e2e
 | 
			
		||||
package common
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"fmt"
 | 
			
		||||
@@ -127,13 +127,10 @@ var _ = framework.KubeDescribe("ConfigMap", func() {
 | 
			
		||||
 | 
			
		||||
		defer func() {
 | 
			
		||||
			By("Deleting the pod")
 | 
			
		||||
			f.Client.Pods(f.Namespace.Name).Delete(pod.Name, api.NewDeleteOptions(0))
 | 
			
		||||
			f.PodClient().Delete(pod.Name, api.NewDeleteOptions(0))
 | 
			
		||||
		}()
 | 
			
		||||
		By("Creating the pod")
 | 
			
		||||
		pod, err = f.Client.Pods(f.Namespace.Name).Create(pod)
 | 
			
		||||
		Expect(err).NotTo(HaveOccurred())
 | 
			
		||||
 | 
			
		||||
		framework.ExpectNoError(framework.WaitForPodRunningInNamespace(f.Client, pod))
 | 
			
		||||
		f.PodClient().CreateSync(pod)
 | 
			
		||||
 | 
			
		||||
		pollLogs := func() (string, error) {
 | 
			
		||||
			return framework.GetPodLogs(f.Client, f.Namespace.Name, pod.Name, containerName)
 | 
			
		||||
@@ -1,5 +1,5 @@
 | 
			
		||||
/*
 | 
			
		||||
Copyright 2015 The Kubernetes Authors.
 | 
			
		||||
Copyright 2016 The Kubernetes Authors.
 | 
			
		||||
 | 
			
		||||
Licensed under the Apache License, Version 2.0 (the "License");
 | 
			
		||||
you may not use this file except in compliance with the License.
 | 
			
		||||
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
 | 
			
		||||
limitations under the License.
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
package e2e
 | 
			
		||||
package common
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"k8s.io/kubernetes/pkg/api"
 | 
			
		||||
@@ -1,5 +1,5 @@
 | 
			
		||||
/*
 | 
			
		||||
Copyright 2015 The Kubernetes Authors.
 | 
			
		||||
Copyright 2016 The Kubernetes Authors.
 | 
			
		||||
 | 
			
		||||
Licensed under the Apache License, Version 2.0 (the "License");
 | 
			
		||||
you may not use this file except in compliance with the License.
 | 
			
		||||
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
 | 
			
		||||
limitations under the License.
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
package e2e
 | 
			
		||||
package common
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"fmt"
 | 
			
		||||
@@ -1,5 +1,5 @@
 | 
			
		||||
/*
 | 
			
		||||
Copyright 2015 The Kubernetes Authors.
 | 
			
		||||
Copyright 2016 The Kubernetes Authors.
 | 
			
		||||
 | 
			
		||||
Licensed under the Apache License, Version 2.0 (the "License");
 | 
			
		||||
you may not use this file except in compliance with the License.
 | 
			
		||||
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
 | 
			
		||||
limitations under the License.
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
package e2e
 | 
			
		||||
package common
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"k8s.io/kubernetes/pkg/api"
 | 
			
		||||
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
 | 
			
		||||
limitations under the License.
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
package e2e
 | 
			
		||||
package common
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"fmt"
 | 
			
		||||
@@ -4319,6 +4319,7 @@ func ScaleRCByLabels(client *client.Client, ns string, l map[string]string, repl
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// TODO(random-liu): Change this to be a member function of the framework.
 | 
			
		||||
func GetPodLogs(c *client.Client, namespace, podName, containerName string) (string, error) {
 | 
			
		||||
	return getPodLogsInternal(c, namespace, podName, containerName, false)
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,335 +0,0 @@
 | 
			
		||||
/*
 | 
			
		||||
Copyright 2016 The Kubernetes Authors.
 | 
			
		||||
 | 
			
		||||
Licensed under the Apache License, Version 2.0 (the "License");
 | 
			
		||||
you may not use this file except in compliance with the License.
 | 
			
		||||
You may obtain a copy of the License at
 | 
			
		||||
 | 
			
		||||
    http://www.apache.org/licenses/LICENSE-2.0
 | 
			
		||||
 | 
			
		||||
Unless required by applicable law or agreed to in writing, software
 | 
			
		||||
distributed under the License is distributed on an "AS IS" BASIS,
 | 
			
		||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 | 
			
		||||
See the License for the specific language governing permissions and
 | 
			
		||||
limitations under the License.
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
package e2e_node
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"fmt"
 | 
			
		||||
	"time"
 | 
			
		||||
 | 
			
		||||
	"k8s.io/kubernetes/pkg/api"
 | 
			
		||||
	"k8s.io/kubernetes/pkg/util/uuid"
 | 
			
		||||
	"k8s.io/kubernetes/test/e2e/framework"
 | 
			
		||||
 | 
			
		||||
	. "github.com/onsi/ginkgo"
 | 
			
		||||
	. "github.com/onsi/gomega"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
var _ = framework.KubeDescribe("ConfigMap", func() {
 | 
			
		||||
 | 
			
		||||
	f := framework.NewDefaultFramework("configmap")
 | 
			
		||||
 | 
			
		||||
	It("should be consumable from pods in volume [Conformance]", func() {
 | 
			
		||||
		doConfigMapE2EWithoutMappings(f, 0, 0)
 | 
			
		||||
	})
 | 
			
		||||
 | 
			
		||||
	It("should be consumable from pods in volume as non-root [Conformance]", func() {
 | 
			
		||||
		doConfigMapE2EWithoutMappings(f, 1000, 0)
 | 
			
		||||
	})
 | 
			
		||||
 | 
			
		||||
	It("should be consumable from pods in volume as non-root with FSGroup [Feature:FSGroup]", func() {
 | 
			
		||||
		doConfigMapE2EWithoutMappings(f, 1000, 1001)
 | 
			
		||||
	})
 | 
			
		||||
 | 
			
		||||
	It("should be consumable from pods in volume with mappings [Conformance]", func() {
 | 
			
		||||
		doConfigMapE2EWithMappings(f, 0, 0)
 | 
			
		||||
	})
 | 
			
		||||
 | 
			
		||||
	It("should be consumable from pods in volume with mappings as non-root [Conformance]", func() {
 | 
			
		||||
		doConfigMapE2EWithMappings(f, 1000, 0)
 | 
			
		||||
	})
 | 
			
		||||
 | 
			
		||||
	It("should be consumable from pods in volume with mappings as non-root with FSGroup [Feature:FSGroup]", func() {
 | 
			
		||||
		doConfigMapE2EWithMappings(f, 1000, 1001)
 | 
			
		||||
	})
 | 
			
		||||
 | 
			
		||||
	It("updates should be reflected in volume [Conformance]", func() {
 | 
			
		||||
 | 
			
		||||
		// We may have to wait or a full sync period to elapse before the
 | 
			
		||||
		// Kubelet projects the update into the volume and the container picks
 | 
			
		||||
		// it up. This timeout is based on the default Kubelet sync period (1
 | 
			
		||||
		// minute) plus additional time for fudge factor.
 | 
			
		||||
		const podLogTimeout = 300 * time.Second
 | 
			
		||||
 | 
			
		||||
		name := "configmap-test-upd-" + string(uuid.NewUUID())
 | 
			
		||||
		volumeName := "configmap-volume"
 | 
			
		||||
		volumeMountPath := "/etc/configmap-volume"
 | 
			
		||||
		containerName := "configmap-volume-test"
 | 
			
		||||
 | 
			
		||||
		configMap := &api.ConfigMap{
 | 
			
		||||
			ObjectMeta: api.ObjectMeta{
 | 
			
		||||
				Namespace: f.Namespace.Name,
 | 
			
		||||
				Name:      name,
 | 
			
		||||
			},
 | 
			
		||||
			Data: map[string]string{
 | 
			
		||||
				"data-1": "value-1",
 | 
			
		||||
			},
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		By(fmt.Sprintf("Creating configMap with name %s", configMap.Name))
 | 
			
		||||
 | 
			
		||||
		var err error
 | 
			
		||||
		if configMap, err = f.Client.ConfigMaps(f.Namespace.Name).Create(configMap); err != nil {
 | 
			
		||||
			framework.Failf("unable to create test configMap %s: %v", configMap.Name, err)
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		pod := &api.Pod{
 | 
			
		||||
			ObjectMeta: api.ObjectMeta{
 | 
			
		||||
				Name: "pod-configmaps-" + string(uuid.NewUUID()),
 | 
			
		||||
			},
 | 
			
		||||
			Spec: api.PodSpec{
 | 
			
		||||
				Volumes: []api.Volume{
 | 
			
		||||
					{
 | 
			
		||||
						Name: volumeName,
 | 
			
		||||
						VolumeSource: api.VolumeSource{
 | 
			
		||||
							ConfigMap: &api.ConfigMapVolumeSource{
 | 
			
		||||
								LocalObjectReference: api.LocalObjectReference{
 | 
			
		||||
									Name: name,
 | 
			
		||||
								},
 | 
			
		||||
							},
 | 
			
		||||
						},
 | 
			
		||||
					},
 | 
			
		||||
				},
 | 
			
		||||
				Containers: []api.Container{
 | 
			
		||||
					{
 | 
			
		||||
						Name:    containerName,
 | 
			
		||||
						Image:   ImageRegistry[mountTestImage],
 | 
			
		||||
						Command: []string{"/mt", "--break_on_expected_content=false", "--retry_time=120", "--file_content_in_loop=/etc/configmap-volume/data-1"},
 | 
			
		||||
						VolumeMounts: []api.VolumeMount{
 | 
			
		||||
							{
 | 
			
		||||
								Name:      volumeName,
 | 
			
		||||
								MountPath: volumeMountPath,
 | 
			
		||||
								ReadOnly:  true,
 | 
			
		||||
							},
 | 
			
		||||
						},
 | 
			
		||||
					},
 | 
			
		||||
				},
 | 
			
		||||
				RestartPolicy: api.RestartPolicyNever,
 | 
			
		||||
			},
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		By("Creating the pod")
 | 
			
		||||
		f.PodClient().CreateSync(pod)
 | 
			
		||||
 | 
			
		||||
		pollLogs := func() (string, error) {
 | 
			
		||||
			return framework.GetPodLogs(f.Client, f.Namespace.Name, pod.Name, containerName)
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		Eventually(pollLogs, podLogTimeout, framework.Poll).Should(ContainSubstring("value-1"))
 | 
			
		||||
 | 
			
		||||
		By(fmt.Sprintf("Updating configmap %v", configMap.Name))
 | 
			
		||||
		configMap.ResourceVersion = "" // to force update
 | 
			
		||||
		configMap.Data["data-1"] = "value-2"
 | 
			
		||||
		_, err = f.Client.ConfigMaps(f.Namespace.Name).Update(configMap)
 | 
			
		||||
		Expect(err).NotTo(HaveOccurred())
 | 
			
		||||
 | 
			
		||||
		By("waiting to observe update in volume")
 | 
			
		||||
		Eventually(pollLogs, podLogTimeout, framework.Poll).Should(ContainSubstring("value-2"))
 | 
			
		||||
	})
 | 
			
		||||
 | 
			
		||||
	It("should be consumable via environment variable [Conformance]", func() {
 | 
			
		||||
		name := "configmap-test-" + string(uuid.NewUUID())
 | 
			
		||||
		configMap := newConfigMap(f, name)
 | 
			
		||||
		By(fmt.Sprintf("Creating configMap %v/%v", f.Namespace.Name, configMap.Name))
 | 
			
		||||
 | 
			
		||||
		var err error
 | 
			
		||||
		if configMap, err = f.Client.ConfigMaps(f.Namespace.Name).Create(configMap); err != nil {
 | 
			
		||||
			framework.Failf("unable to create test configMap %s: %v", configMap.Name, err)
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		pod := &api.Pod{
 | 
			
		||||
			ObjectMeta: api.ObjectMeta{
 | 
			
		||||
				Name: "pod-configmaps-" + string(uuid.NewUUID()),
 | 
			
		||||
			},
 | 
			
		||||
			Spec: api.PodSpec{
 | 
			
		||||
				Containers: []api.Container{
 | 
			
		||||
					{
 | 
			
		||||
						Name:    "env-test",
 | 
			
		||||
						Image:   ImageRegistry[busyBoxImage],
 | 
			
		||||
						Command: []string{"sh", "-c", "env"},
 | 
			
		||||
						Env: []api.EnvVar{
 | 
			
		||||
							{
 | 
			
		||||
								Name: "CONFIG_DATA_1",
 | 
			
		||||
								ValueFrom: &api.EnvVarSource{
 | 
			
		||||
									ConfigMapKeyRef: &api.ConfigMapKeySelector{
 | 
			
		||||
										LocalObjectReference: api.LocalObjectReference{
 | 
			
		||||
											Name: name,
 | 
			
		||||
										},
 | 
			
		||||
										Key: "data-1",
 | 
			
		||||
									},
 | 
			
		||||
								},
 | 
			
		||||
							},
 | 
			
		||||
						},
 | 
			
		||||
					},
 | 
			
		||||
				},
 | 
			
		||||
				RestartPolicy: api.RestartPolicyNever,
 | 
			
		||||
			},
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		f.TestContainerOutput("consume configMaps", pod, 0, []string{
 | 
			
		||||
			"CONFIG_DATA_1=value-1",
 | 
			
		||||
		})
 | 
			
		||||
	})
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
func newConfigMap(f *framework.Framework, name string) *api.ConfigMap {
 | 
			
		||||
	return &api.ConfigMap{
 | 
			
		||||
		ObjectMeta: api.ObjectMeta{
 | 
			
		||||
			Namespace: f.Namespace.Name,
 | 
			
		||||
			Name:      name,
 | 
			
		||||
		},
 | 
			
		||||
		Data: map[string]string{
 | 
			
		||||
			"data-1": "value-1",
 | 
			
		||||
			"data-2": "value-2",
 | 
			
		||||
			"data-3": "value-3",
 | 
			
		||||
		},
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func doConfigMapE2EWithoutMappings(f *framework.Framework, uid, fsGroup int64) {
 | 
			
		||||
	var (
 | 
			
		||||
		name            = "configmap-test-volume-" + string(uuid.NewUUID())
 | 
			
		||||
		volumeName      = "configmap-volume"
 | 
			
		||||
		volumeMountPath = "/etc/configmap-volume"
 | 
			
		||||
		configMap       = newConfigMap(f, name)
 | 
			
		||||
	)
 | 
			
		||||
 | 
			
		||||
	By(fmt.Sprintf("Creating configMap with name %s", configMap.Name))
 | 
			
		||||
 | 
			
		||||
	var err error
 | 
			
		||||
	if configMap, err = f.Client.ConfigMaps(f.Namespace.Name).Create(configMap); err != nil {
 | 
			
		||||
		framework.Failf("unable to create test configMap %s: %v", configMap.Name, err)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	pod := &api.Pod{
 | 
			
		||||
		ObjectMeta: api.ObjectMeta{
 | 
			
		||||
			Name: "pod-configmaps-" + string(uuid.NewUUID()),
 | 
			
		||||
		},
 | 
			
		||||
		Spec: api.PodSpec{
 | 
			
		||||
			SecurityContext: &api.PodSecurityContext{},
 | 
			
		||||
			Volumes: []api.Volume{
 | 
			
		||||
				{
 | 
			
		||||
					Name: volumeName,
 | 
			
		||||
					VolumeSource: api.VolumeSource{
 | 
			
		||||
						ConfigMap: &api.ConfigMapVolumeSource{
 | 
			
		||||
							LocalObjectReference: api.LocalObjectReference{
 | 
			
		||||
								Name: name,
 | 
			
		||||
							},
 | 
			
		||||
						},
 | 
			
		||||
					},
 | 
			
		||||
				},
 | 
			
		||||
			},
 | 
			
		||||
			Containers: []api.Container{
 | 
			
		||||
				{
 | 
			
		||||
					Name:  "configmap-volume-test",
 | 
			
		||||
					Image: ImageRegistry[mountTestImage],
 | 
			
		||||
					Args:  []string{"--file_content=/etc/configmap-volume/data-1"},
 | 
			
		||||
					VolumeMounts: []api.VolumeMount{
 | 
			
		||||
						{
 | 
			
		||||
							Name:      volumeName,
 | 
			
		||||
							MountPath: volumeMountPath,
 | 
			
		||||
							ReadOnly:  true,
 | 
			
		||||
						},
 | 
			
		||||
					},
 | 
			
		||||
				},
 | 
			
		||||
			},
 | 
			
		||||
			RestartPolicy: api.RestartPolicyNever,
 | 
			
		||||
		},
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if uid != 0 {
 | 
			
		||||
		pod.Spec.SecurityContext.RunAsUser = &uid
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if fsGroup != 0 {
 | 
			
		||||
		pod.Spec.SecurityContext.FSGroup = &fsGroup
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	f.TestContainerOutput("consume configMaps", pod, 0, []string{
 | 
			
		||||
		"content of file \"/etc/configmap-volume/data-1\": value-1",
 | 
			
		||||
	})
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func doConfigMapE2EWithMappings(f *framework.Framework, uid, fsGroup int64) {
 | 
			
		||||
	var (
 | 
			
		||||
		name            = "configmap-test-volume-map-" + string(uuid.NewUUID())
 | 
			
		||||
		volumeName      = "configmap-volume"
 | 
			
		||||
		volumeMountPath = "/etc/configmap-volume"
 | 
			
		||||
		configMap       = newConfigMap(f, name)
 | 
			
		||||
	)
 | 
			
		||||
 | 
			
		||||
	By(fmt.Sprintf("Creating configMap with name %s", configMap.Name))
 | 
			
		||||
 | 
			
		||||
	var err error
 | 
			
		||||
	if configMap, err = f.Client.ConfigMaps(f.Namespace.Name).Create(configMap); err != nil {
 | 
			
		||||
		framework.Failf("unable to create test configMap %s: %v", configMap.Name, err)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	pod := &api.Pod{
 | 
			
		||||
		ObjectMeta: api.ObjectMeta{
 | 
			
		||||
			Name: "pod-configmaps-" + string(uuid.NewUUID()),
 | 
			
		||||
		},
 | 
			
		||||
		Spec: api.PodSpec{
 | 
			
		||||
			SecurityContext: &api.PodSecurityContext{},
 | 
			
		||||
			Volumes: []api.Volume{
 | 
			
		||||
				{
 | 
			
		||||
					Name: volumeName,
 | 
			
		||||
					VolumeSource: api.VolumeSource{
 | 
			
		||||
						ConfigMap: &api.ConfigMapVolumeSource{
 | 
			
		||||
							LocalObjectReference: api.LocalObjectReference{
 | 
			
		||||
								Name: name,
 | 
			
		||||
							},
 | 
			
		||||
							Items: []api.KeyToPath{
 | 
			
		||||
								{
 | 
			
		||||
									Key:  "data-2",
 | 
			
		||||
									Path: "path/to/data-2",
 | 
			
		||||
								},
 | 
			
		||||
							},
 | 
			
		||||
						},
 | 
			
		||||
					},
 | 
			
		||||
				},
 | 
			
		||||
			},
 | 
			
		||||
			Containers: []api.Container{
 | 
			
		||||
				{
 | 
			
		||||
					Name:  "configmap-volume-test",
 | 
			
		||||
					Image: ImageRegistry[mountTestImage],
 | 
			
		||||
					Args:  []string{"--file_content=/etc/configmap-volume/path/to/data-2"},
 | 
			
		||||
					VolumeMounts: []api.VolumeMount{
 | 
			
		||||
						{
 | 
			
		||||
							Name:      volumeName,
 | 
			
		||||
							MountPath: volumeMountPath,
 | 
			
		||||
							ReadOnly:  true,
 | 
			
		||||
						},
 | 
			
		||||
					},
 | 
			
		||||
				},
 | 
			
		||||
			},
 | 
			
		||||
			RestartPolicy: api.RestartPolicyNever,
 | 
			
		||||
		},
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if uid != 0 {
 | 
			
		||||
		pod.Spec.SecurityContext.RunAsUser = &uid
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if fsGroup != 0 {
 | 
			
		||||
		pod.Spec.SecurityContext.FSGroup = &fsGroup
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	f.TestContainerOutput("consume configMaps", pod, 0, []string{
 | 
			
		||||
		"content of file \"/etc/configmap-volume/path/to/data-2\": value-2",
 | 
			
		||||
	})
 | 
			
		||||
}
 | 
			
		||||
@@ -1,162 +0,0 @@
 | 
			
		||||
/*
 | 
			
		||||
Copyright 2016 The Kubernetes Authors.
 | 
			
		||||
 | 
			
		||||
Licensed under the Apache License, Version 2.0 (the "License");
 | 
			
		||||
you may not use this file except in compliance with the License.
 | 
			
		||||
You may obtain a copy of the License at
 | 
			
		||||
 | 
			
		||||
    http://www.apache.org/licenses/LICENSE-2.0
 | 
			
		||||
 | 
			
		||||
Unless required by applicable law or agreed to in writing, software
 | 
			
		||||
distributed under the License is distributed on an "AS IS" BASIS,
 | 
			
		||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 | 
			
		||||
See the License for the specific language governing permissions and
 | 
			
		||||
limitations under the License.
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
package e2e_node
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"fmt"
 | 
			
		||||
 | 
			
		||||
	"k8s.io/kubernetes/pkg/api"
 | 
			
		||||
	"k8s.io/kubernetes/pkg/api/resource"
 | 
			
		||||
	"k8s.io/kubernetes/pkg/util/uuid"
 | 
			
		||||
	"k8s.io/kubernetes/test/e2e/framework"
 | 
			
		||||
 | 
			
		||||
	. "github.com/onsi/ginkgo"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
// Ported from test/e2e/downard_api_test.go
 | 
			
		||||
 | 
			
		||||
var _ = framework.KubeDescribe("Downward API", func() {
 | 
			
		||||
	f := framework.NewDefaultFramework("downward-api")
 | 
			
		||||
	It("should provide pod name and namespace as env vars [Conformance]", func() {
 | 
			
		||||
		podName := "downward-api-" + string(uuid.NewUUID())
 | 
			
		||||
		env := []api.EnvVar{
 | 
			
		||||
			{
 | 
			
		||||
				Name: "POD_NAME",
 | 
			
		||||
				ValueFrom: &api.EnvVarSource{
 | 
			
		||||
					FieldRef: &api.ObjectFieldSelector{
 | 
			
		||||
						APIVersion: "v1",
 | 
			
		||||
						FieldPath:  "metadata.name",
 | 
			
		||||
					},
 | 
			
		||||
				},
 | 
			
		||||
			},
 | 
			
		||||
			{
 | 
			
		||||
				Name: "POD_NAMESPACE",
 | 
			
		||||
				ValueFrom: &api.EnvVarSource{
 | 
			
		||||
					FieldRef: &api.ObjectFieldSelector{
 | 
			
		||||
						APIVersion: "v1",
 | 
			
		||||
						FieldPath:  "metadata.namespace",
 | 
			
		||||
					},
 | 
			
		||||
				},
 | 
			
		||||
			},
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		expectations := []string{
 | 
			
		||||
			fmt.Sprintf("POD_NAME=%v", podName),
 | 
			
		||||
			fmt.Sprintf("POD_NAMESPACE=%v", f.Namespace.Name),
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		testDownwardAPI(f, podName, env, expectations)
 | 
			
		||||
	})
 | 
			
		||||
 | 
			
		||||
	It("should provide pod IP as an env var", func() {
 | 
			
		||||
		podName := "downward-api-" + string(uuid.NewUUID())
 | 
			
		||||
		env := []api.EnvVar{
 | 
			
		||||
			{
 | 
			
		||||
				Name: "POD_IP",
 | 
			
		||||
				ValueFrom: &api.EnvVarSource{
 | 
			
		||||
					FieldRef: &api.ObjectFieldSelector{
 | 
			
		||||
						APIVersion: "v1",
 | 
			
		||||
						FieldPath:  "status.podIP",
 | 
			
		||||
					},
 | 
			
		||||
				},
 | 
			
		||||
			},
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		expectations := []string{
 | 
			
		||||
			"POD_IP=(?:\\d+)\\.(?:\\d+)\\.(?:\\d+)\\.(?:\\d+)",
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		testDownwardAPI(f, podName, env, expectations)
 | 
			
		||||
	})
 | 
			
		||||
 | 
			
		||||
	It("should provide container's limits.cpu/memory and requests.cpu/memory as env vars", func() {
 | 
			
		||||
		podName := "downward-api-" + string(uuid.NewUUID())
 | 
			
		||||
		env := []api.EnvVar{
 | 
			
		||||
			{
 | 
			
		||||
				Name: "CPU_LIMIT",
 | 
			
		||||
				ValueFrom: &api.EnvVarSource{
 | 
			
		||||
					ResourceFieldRef: &api.ResourceFieldSelector{
 | 
			
		||||
						Resource: "limits.cpu",
 | 
			
		||||
					},
 | 
			
		||||
				},
 | 
			
		||||
			},
 | 
			
		||||
			{
 | 
			
		||||
				Name: "MEMORY_LIMIT",
 | 
			
		||||
				ValueFrom: &api.EnvVarSource{
 | 
			
		||||
					ResourceFieldRef: &api.ResourceFieldSelector{
 | 
			
		||||
						Resource: "limits.memory",
 | 
			
		||||
					},
 | 
			
		||||
				},
 | 
			
		||||
			},
 | 
			
		||||
			{
 | 
			
		||||
				Name: "CPU_REQUEST",
 | 
			
		||||
				ValueFrom: &api.EnvVarSource{
 | 
			
		||||
					ResourceFieldRef: &api.ResourceFieldSelector{
 | 
			
		||||
						Resource: "requests.cpu",
 | 
			
		||||
					},
 | 
			
		||||
				},
 | 
			
		||||
			},
 | 
			
		||||
			{
 | 
			
		||||
				Name: "MEMORY_REQUEST",
 | 
			
		||||
				ValueFrom: &api.EnvVarSource{
 | 
			
		||||
					ResourceFieldRef: &api.ResourceFieldSelector{
 | 
			
		||||
						Resource: "requests.memory",
 | 
			
		||||
					},
 | 
			
		||||
				},
 | 
			
		||||
			},
 | 
			
		||||
		}
 | 
			
		||||
		expectations := []string{
 | 
			
		||||
			fmt.Sprintf("CPU_LIMIT=2"),
 | 
			
		||||
			fmt.Sprintf("MEMORY_LIMIT=67108864"),
 | 
			
		||||
			fmt.Sprintf("CPU_REQUEST=1"),
 | 
			
		||||
			fmt.Sprintf("MEMORY_REQUEST=33554432"),
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		testDownwardAPI(f, podName, env, expectations)
 | 
			
		||||
	})
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
func testDownwardAPI(f *framework.Framework, podName string, env []api.EnvVar, expectations []string) {
 | 
			
		||||
	pod := &api.Pod{
 | 
			
		||||
		ObjectMeta: api.ObjectMeta{
 | 
			
		||||
			Name:   podName,
 | 
			
		||||
			Labels: map[string]string{"name": podName},
 | 
			
		||||
		},
 | 
			
		||||
		Spec: api.PodSpec{
 | 
			
		||||
			Containers: []api.Container{
 | 
			
		||||
				{
 | 
			
		||||
					Name:    "dapi-container",
 | 
			
		||||
					Image:   ImageRegistry[busyBoxImage],
 | 
			
		||||
					Command: []string{"sh", "-c", "env"},
 | 
			
		||||
					Resources: api.ResourceRequirements{
 | 
			
		||||
						Requests: api.ResourceList{
 | 
			
		||||
							api.ResourceCPU:    resource.MustParse("250m"),
 | 
			
		||||
							api.ResourceMemory: resource.MustParse("32Mi"),
 | 
			
		||||
						},
 | 
			
		||||
						Limits: api.ResourceList{
 | 
			
		||||
							api.ResourceCPU:    resource.MustParse("1250m"),
 | 
			
		||||
							api.ResourceMemory: resource.MustParse("64Mi"),
 | 
			
		||||
						},
 | 
			
		||||
					},
 | 
			
		||||
					Env: env,
 | 
			
		||||
				},
 | 
			
		||||
			},
 | 
			
		||||
			RestartPolicy: api.RestartPolicyNever,
 | 
			
		||||
		},
 | 
			
		||||
	}
 | 
			
		||||
	f.TestContainerOutputRegexp("downward api env vars", pod, 0, expectations)
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user