PageRenderTime 57ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/vendor/k8s.io/kubernetes/test/e2e_node/downward_api_test.go

https://gitlab.com/admin-github-cloud/bootkube
Go | 164 lines | 133 code | 15 blank | 16 comment | 0 complexity | e31ac59174838efea4cb69772aaf6485 MD5 | raw file
  1. /*
  2. Copyright 2016 The Kubernetes Authors All rights reserved.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package e2e_node
  14. import (
  15. "fmt"
  16. "k8s.io/kubernetes/pkg/api"
  17. "k8s.io/kubernetes/pkg/api/resource"
  18. "k8s.io/kubernetes/pkg/util"
  19. "k8s.io/kubernetes/test/e2e/framework"
  20. . "github.com/onsi/ginkgo"
  21. )
  22. // Ported from test/e2e/downard_api_test.go
  23. var _ = framework.KubeDescribe("Downward API", func() {
  24. f := NewDefaultFramework("downward-api")
  25. It("should provide pod name and namespace as env vars [Conformance]", func() {
  26. podName := "downward-api-" + string(util.NewUUID())
  27. env := []api.EnvVar{
  28. {
  29. Name: "POD_NAME",
  30. ValueFrom: &api.EnvVarSource{
  31. FieldRef: &api.ObjectFieldSelector{
  32. APIVersion: "v1",
  33. FieldPath: "metadata.name",
  34. },
  35. },
  36. },
  37. {
  38. Name: "POD_NAMESPACE",
  39. ValueFrom: &api.EnvVarSource{
  40. FieldRef: &api.ObjectFieldSelector{
  41. APIVersion: "v1",
  42. FieldPath: "metadata.namespace",
  43. },
  44. },
  45. },
  46. }
  47. expectations := []string{
  48. fmt.Sprintf("POD_NAME=%v", podName),
  49. fmt.Sprintf("POD_NAMESPACE=%v", f.Namespace.Name),
  50. }
  51. testDownwardAPI(f, podName, env, expectations)
  52. })
  53. It("should provide pod IP as an env var", func() {
  54. podName := "downward-api-" + string(util.NewUUID())
  55. env := []api.EnvVar{
  56. {
  57. Name: "POD_IP",
  58. ValueFrom: &api.EnvVarSource{
  59. FieldRef: &api.ObjectFieldSelector{
  60. APIVersion: "v1",
  61. FieldPath: "status.podIP",
  62. },
  63. },
  64. },
  65. }
  66. expectations := []string{
  67. "POD_IP=(?:\\d+)\\.(?:\\d+)\\.(?:\\d+)\\.(?:\\d+)",
  68. }
  69. testDownwardAPI(f, podName, env, expectations)
  70. })
  71. It("should provide container's limits.cpu/memory and requests.cpu/memory as env vars", func() {
  72. podName := "downward-api-" + string(util.NewUUID())
  73. env := []api.EnvVar{
  74. {
  75. Name: "CPU_LIMIT",
  76. ValueFrom: &api.EnvVarSource{
  77. ResourceFieldRef: &api.ResourceFieldSelector{
  78. Resource: "limits.cpu",
  79. },
  80. },
  81. },
  82. {
  83. Name: "MEMORY_LIMIT",
  84. ValueFrom: &api.EnvVarSource{
  85. ResourceFieldRef: &api.ResourceFieldSelector{
  86. Resource: "limits.memory",
  87. },
  88. },
  89. },
  90. {
  91. Name: "CPU_REQUEST",
  92. ValueFrom: &api.EnvVarSource{
  93. ResourceFieldRef: &api.ResourceFieldSelector{
  94. Resource: "requests.cpu",
  95. },
  96. },
  97. },
  98. {
  99. Name: "MEMORY_REQUEST",
  100. ValueFrom: &api.EnvVarSource{
  101. ResourceFieldRef: &api.ResourceFieldSelector{
  102. Resource: "requests.memory",
  103. },
  104. },
  105. },
  106. }
  107. expectations := []string{
  108. fmt.Sprintf("CPU_LIMIT=2"),
  109. fmt.Sprintf("MEMORY_LIMIT=67108864"),
  110. fmt.Sprintf("CPU_REQUEST=1"),
  111. fmt.Sprintf("MEMORY_REQUEST=33554432"),
  112. }
  113. testDownwardAPI(f, podName, env, expectations)
  114. })
  115. })
  116. func testDownwardAPI(f *framework.Framework, podName string, env []api.EnvVar, expectations []string) {
  117. pod := &api.Pod{
  118. ObjectMeta: api.ObjectMeta{
  119. Name: podName,
  120. Labels: map[string]string{"name": podName},
  121. },
  122. Spec: api.PodSpec{
  123. Containers: []api.Container{
  124. {
  125. Name: "dapi-container",
  126. Image: "gcr.io/google_containers/busybox:1.24",
  127. Command: []string{"sh", "-c", "env"},
  128. Resources: api.ResourceRequirements{
  129. Requests: api.ResourceList{
  130. api.ResourceCPU: resource.MustParse("250m"),
  131. api.ResourceMemory: resource.MustParse("32Mi"),
  132. },
  133. Limits: api.ResourceList{
  134. api.ResourceCPU: resource.MustParse("1250m"),
  135. api.ResourceMemory: resource.MustParse("64Mi"),
  136. },
  137. },
  138. Env: env,
  139. },
  140. },
  141. RestartPolicy: api.RestartPolicyNever,
  142. },
  143. }
  144. assignPodToNode(pod)
  145. f.TestContainerOutputRegexp("downward api env vars", pod, 0, expectations)
  146. }