container_manager_test.go 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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 e2e_node
  14. import (
  15. "fmt"
  16. "time"
  17. "k8s.io/kubernetes/pkg/api"
  18. "k8s.io/kubernetes/pkg/util/uuid"
  19. "k8s.io/kubernetes/test/e2e/framework"
  20. . "github.com/onsi/ginkgo"
  21. . "github.com/onsi/gomega"
  22. )
  23. var _ = framework.KubeDescribe("Kubelet Container Manager", func() {
  24. f := framework.NewDefaultFramework("kubelet-container-manager")
  25. var podClient *framework.PodClient
  26. BeforeEach(func() {
  27. podClient = f.PodClient()
  28. })
  29. Describe("oom score adjusting", func() {
  30. Context("when scheduling a busybox command that always fails in a pod", func() {
  31. var podName string
  32. BeforeEach(func() {
  33. podName = "bin-false" + string(uuid.NewUUID())
  34. podClient.Create(&api.Pod{
  35. ObjectMeta: api.ObjectMeta{
  36. Name: podName,
  37. },
  38. Spec: api.PodSpec{
  39. // Don't restart the Pod since it is expected to exit
  40. RestartPolicy: api.RestartPolicyNever,
  41. Containers: []api.Container{
  42. {
  43. Image: ImageRegistry[busyBoxImage],
  44. Name: podName,
  45. Command: []string{"/bin/false"},
  46. },
  47. },
  48. },
  49. })
  50. })
  51. It("should have an error terminated reason", func() {
  52. Eventually(func() error {
  53. podData, err := podClient.Get(podName)
  54. if err != nil {
  55. return err
  56. }
  57. if len(podData.Status.ContainerStatuses) != 1 {
  58. return fmt.Errorf("expected only one container in the pod %q", podName)
  59. }
  60. contTerminatedState := podData.Status.ContainerStatuses[0].State.Terminated
  61. if contTerminatedState == nil {
  62. return fmt.Errorf("expected state to be terminated. Got pod status: %+v", podData.Status)
  63. }
  64. if contTerminatedState.Reason != "Error" {
  65. return fmt.Errorf("expected terminated state reason to be error. Got %+v", contTerminatedState)
  66. }
  67. return nil
  68. }, time.Minute, time.Second*4).Should(BeNil())
  69. })
  70. It("should be possible to delete", func() {
  71. err := podClient.Delete(podName, &api.DeleteOptions{})
  72. Expect(err).To(BeNil(), fmt.Sprintf("Error deleting Pod %v", err))
  73. })
  74. })
  75. })
  76. })