diff --git a/pkg/api/v1/resource/helpers.go b/pkg/api/v1/resource/helpers.go index af12f76341a..09d9ea04187 100644 --- a/pkg/api/v1/resource/helpers.go +++ b/pkg/api/v1/resource/helpers.go @@ -192,7 +192,7 @@ func MergeContainerResourceLimits(container *v1.Container, if container.Resources.Limits == nil { container.Resources.Limits = make(v1.ResourceList) } - for _, resource := range []v1.ResourceName{v1.ResourceCPU, v1.ResourceMemory} { + for _, resource := range []v1.ResourceName{v1.ResourceCPU, v1.ResourceMemory, v1.ResourceEphemeralStorage} { if quantity, exists := container.Resources.Limits[resource]; !exists || quantity.IsZero() { if cap, exists := allocatable[resource]; exists { container.Resources.Limits[resource] = *cap.Copy() diff --git a/test/e2e/common/downward_api.go b/test/e2e/common/downward_api.go index e6e3a979d45..a46ca1be63d 100644 --- a/test/e2e/common/downward_api.go +++ b/test/e2e/common/downward_api.go @@ -225,6 +225,81 @@ var _ = Describe("[sig-api-machinery] Downward API", func() { }) }) +var _ = framework.KubeDescribe("Downward API [Serial] [Disruptive]", func() { + f := framework.NewDefaultFramework("downward-api") + + Context("Downward API tests for local ephemeral storage", func() { + BeforeEach(func() { + framework.SkipUnlessLocalEphemeralStorageEnabled() + }) + + It("should provide container's limits.ephemeral-storage and requests.ephemeral-storage as env vars", func() { + podName := "downward-api-" + string(uuid.NewUUID()) + env := []v1.EnvVar{ + { + Name: "EPHEMERAL_STORAGE_LIMIT", + ValueFrom: &v1.EnvVarSource{ + ResourceFieldRef: &v1.ResourceFieldSelector{ + Resource: "limits.ephemeral-storage", + }, + }, + }, + { + Name: "EPHEMERAL_STORAGE_REQUEST", + ValueFrom: &v1.EnvVarSource{ + ResourceFieldRef: &v1.ResourceFieldSelector{ + Resource: "requests.ephemeral-storage", + }, + }, + }, + } + expectations := []string{ + fmt.Sprintf("EPHEMERAL_STORAGE_LIMIT=%d", 64*1024*1024), + fmt.Sprintf("EPHEMERAL_STORAGE_REQUEST=%d", 32*1024*1024), + } + + testDownwardAPIForEphemeralStorage(f, podName, env, expectations) + }) + + It("should provide default limits.ephemeral-storage from node allocatable", func() { + podName := "downward-api-" + string(uuid.NewUUID()) + env := []v1.EnvVar{ + { + Name: "EPHEMERAL_STORAGE_LIMIT", + ValueFrom: &v1.EnvVarSource{ + ResourceFieldRef: &v1.ResourceFieldSelector{ + Resource: "limits.ephemeral-storage", + }, + }, + }, + } + expectations := []string{ + "EPHEMERAL_STORAGE_LIMIT=[1-9]", + } + pod := &v1.Pod{ + ObjectMeta: metav1.ObjectMeta{ + Name: podName, + Labels: map[string]string{"name": podName}, + }, + Spec: v1.PodSpec{ + Containers: []v1.Container{ + { + Name: "dapi-container", + Image: busyboxImage, + Command: []string{"sh", "-c", "env"}, + Env: env, + }, + }, + RestartPolicy: v1.RestartPolicyNever, + }, + } + + testDownwardAPIUsingPod(f, pod, env, expectations) + }) + }) + +}) + func testDownwardAPI(f *framework.Framework, podName string, env []v1.EnvVar, expectations []string) { pod := &v1.Pod{ ObjectMeta: metav1.ObjectMeta{ @@ -257,6 +332,36 @@ func testDownwardAPI(f *framework.Framework, podName string, env []v1.EnvVar, ex testDownwardAPIUsingPod(f, pod, env, expectations) } +func testDownwardAPIForEphemeralStorage(f *framework.Framework, podName string, env []v1.EnvVar, expectations []string) { + pod := &v1.Pod{ + ObjectMeta: metav1.ObjectMeta{ + Name: podName, + Labels: map[string]string{"name": podName}, + }, + Spec: v1.PodSpec{ + Containers: []v1.Container{ + { + Name: "dapi-container", + Image: busyboxImage, + Command: []string{"sh", "-c", "env"}, + Resources: v1.ResourceRequirements{ + Requests: v1.ResourceList{ + v1.ResourceEphemeralStorage: resource.MustParse("32Mi"), + }, + Limits: v1.ResourceList{ + v1.ResourceEphemeralStorage: resource.MustParse("64Mi"), + }, + }, + Env: env, + }, + }, + RestartPolicy: v1.RestartPolicyNever, + }, + } + + testDownwardAPIUsingPod(f, pod, env, expectations) +} + func testDownwardAPIUsingPod(f *framework.Framework, pod *v1.Pod, env []v1.EnvVar, expectations []string) { f.TestContainerOutputRegexp("downward api env vars", pod, 0, expectations) }