docker_containers.go 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /*
  2. Copyright 2016 The Kubernetes Authors.
  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 common
  14. import (
  15. "github.com/onsi/gomega"
  16. "k8s.io/api/core/v1"
  17. metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
  18. "k8s.io/apimachinery/pkg/util/uuid"
  19. "k8s.io/kubernetes/test/e2e/framework"
  20. e2epod "k8s.io/kubernetes/test/e2e/framework/pod"
  21. imageutils "k8s.io/kubernetes/test/utils/image"
  22. )
  23. var _ = framework.KubeDescribe("Docker Containers", func() {
  24. f := framework.NewDefaultFramework("containers")
  25. /*
  26. Release : v1.9
  27. Testname: Docker containers, without command and arguments
  28. Description: Default command and arguments from the docker image entrypoint MUST be used when Pod does not specify the container command
  29. */
  30. framework.ConformanceIt("should use the image defaults if command and args are blank [NodeConformance]", func() {
  31. pod := f.PodClient().Create(entrypointTestPod())
  32. err := e2epod.WaitForPodNameRunningInNamespace(f.ClientSet, pod.Name, f.Namespace.Name)
  33. framework.ExpectNoError(err, "Expected pod %q to be running, got error: %v", pod.Name, err)
  34. pollLogs := func() (string, error) {
  35. return e2epod.GetPodLogs(f.ClientSet, f.Namespace.Name, pod.Name, containerName)
  36. }
  37. // The agnhost's image default entrypoint / args are: "/agnhost pause"
  38. // which will print out "Paused".
  39. gomega.Eventually(pollLogs, 3, framework.Poll).Should(gomega.ContainSubstring("Paused"))
  40. })
  41. /*
  42. Release : v1.9
  43. Testname: Docker containers, with arguments
  44. Description: Default command and from the docker image entrypoint MUST be used when Pod does not specify the container command but the arguments from Pod spec MUST override when specified.
  45. */
  46. framework.ConformanceIt("should be able to override the image's default arguments (docker cmd) [NodeConformance]", func() {
  47. pod := entrypointTestPod()
  48. pod.Spec.Containers[0].Args = []string{"entrypoint-tester", "override", "arguments"}
  49. f.TestContainerOutput("override arguments", pod, 0, []string{
  50. "[/agnhost entrypoint-tester override arguments]",
  51. })
  52. })
  53. // Note: when you override the entrypoint, the image's arguments (docker cmd)
  54. // are ignored.
  55. /*
  56. Release : v1.9
  57. Testname: Docker containers, with command
  58. Description: Default command from the docker image entrypoint MUST NOT be used when Pod specifies the container command. Command from Pod spec MUST override the command in the image.
  59. */
  60. framework.ConformanceIt("should be able to override the image's default command (docker entrypoint) [NodeConformance]", func() {
  61. pod := entrypointTestPod()
  62. pod.Spec.Containers[0].Command = []string{"/agnhost-2", "entrypoint-tester"}
  63. f.TestContainerOutput("override command", pod, 0, []string{
  64. "[/agnhost-2 entrypoint-tester]",
  65. })
  66. })
  67. /*
  68. Release : v1.9
  69. Testname: Docker containers, with command and arguments
  70. Description: Default command and arguments from the docker image entrypoint MUST NOT be used when Pod specifies the container command and arguments. Command and arguments from Pod spec MUST override the command and arguments in the image.
  71. */
  72. framework.ConformanceIt("should be able to override the image's default command and arguments [NodeConformance]", func() {
  73. pod := entrypointTestPod()
  74. pod.Spec.Containers[0].Command = []string{"/agnhost-2"}
  75. pod.Spec.Containers[0].Args = []string{"entrypoint-tester", "override", "arguments"}
  76. f.TestContainerOutput("override all", pod, 0, []string{
  77. "[/agnhost-2 entrypoint-tester override arguments]",
  78. })
  79. })
  80. })
  81. const testContainerName = "test-container"
  82. // Return a prototypical entrypoint test pod
  83. func entrypointTestPod() *v1.Pod {
  84. podName := "client-containers-" + string(uuid.NewUUID())
  85. one := int64(1)
  86. return &v1.Pod{
  87. ObjectMeta: metav1.ObjectMeta{
  88. Name: podName,
  89. },
  90. Spec: v1.PodSpec{
  91. Containers: []v1.Container{
  92. {
  93. Name: testContainerName,
  94. Image: imageutils.GetE2EImage(imageutils.Agnhost),
  95. },
  96. },
  97. RestartPolicy: v1.RestartPolicyNever,
  98. TerminationGracePeriodSeconds: &one,
  99. },
  100. }
  101. }