volume_manager_test.go 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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 e2enode
  14. import (
  15. "context"
  16. "time"
  17. "k8s.io/api/core/v1"
  18. metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
  19. "k8s.io/apimachinery/pkg/util/uuid"
  20. "k8s.io/kubernetes/test/e2e/framework"
  21. e2epod "k8s.io/kubernetes/test/e2e/framework/pod"
  22. "fmt"
  23. "github.com/onsi/ginkgo"
  24. )
  25. var _ = framework.KubeDescribe("Kubelet Volume Manager", func() {
  26. f := framework.NewDefaultFramework("kubelet-volume-manager")
  27. ginkgo.Describe("Volume Manager", func() {
  28. ginkgo.Context("On terminatation of pod with memory backed volume", func() {
  29. ginkgo.It("should remove the volume from the node [NodeConformance]", func() {
  30. var (
  31. memoryBackedPod *v1.Pod
  32. volumeName string
  33. )
  34. ginkgo.By("Creating a pod with a memory backed volume that exits success without restart", func() {
  35. volumeName = "memory-volume"
  36. memoryBackedPod = f.PodClient().Create(&v1.Pod{
  37. ObjectMeta: metav1.ObjectMeta{
  38. Name: "pod" + string(uuid.NewUUID()),
  39. Namespace: f.Namespace.Name,
  40. },
  41. Spec: v1.PodSpec{
  42. RestartPolicy: v1.RestartPolicyNever,
  43. Containers: []v1.Container{
  44. {
  45. Image: busyboxImage,
  46. Name: "container" + string(uuid.NewUUID()),
  47. Command: []string{"sh", "-c", "echo"},
  48. VolumeMounts: []v1.VolumeMount{
  49. {
  50. Name: volumeName,
  51. MountPath: "/tmp",
  52. },
  53. },
  54. },
  55. },
  56. Volumes: []v1.Volume{
  57. {
  58. Name: volumeName,
  59. VolumeSource: v1.VolumeSource{
  60. EmptyDir: &v1.EmptyDirVolumeSource{Medium: v1.StorageMediumMemory},
  61. },
  62. },
  63. },
  64. },
  65. })
  66. err := e2epod.WaitForPodSuccessInNamespace(f.ClientSet, memoryBackedPod.Name, f.Namespace.Name)
  67. framework.ExpectNoError(err)
  68. })
  69. ginkgo.By("Verifying the memory backed volume was removed from node", func() {
  70. volumePath := fmt.Sprintf("/tmp/%s/volumes/kubernetes.io~empty-dir/%s", string(memoryBackedPod.UID), volumeName)
  71. var err error
  72. for i := 0; i < 10; i++ {
  73. // need to create a new verification pod on each pass since updates
  74. //to the HostPath volume aren't propogated to the pod
  75. pod := f.PodClient().Create(&v1.Pod{
  76. ObjectMeta: metav1.ObjectMeta{
  77. Name: "pod" + string(uuid.NewUUID()),
  78. Namespace: f.Namespace.Name,
  79. },
  80. Spec: v1.PodSpec{
  81. RestartPolicy: v1.RestartPolicyNever,
  82. Containers: []v1.Container{
  83. {
  84. Image: busyboxImage,
  85. Name: "container" + string(uuid.NewUUID()),
  86. Command: []string{"sh", "-c", "if [ -d " + volumePath + " ]; then exit 1; fi;"},
  87. VolumeMounts: []v1.VolumeMount{
  88. {
  89. Name: "kubelet-pods",
  90. MountPath: "/tmp",
  91. },
  92. },
  93. },
  94. },
  95. Volumes: []v1.Volume{
  96. {
  97. Name: "kubelet-pods",
  98. VolumeSource: v1.VolumeSource{
  99. // TODO: remove hardcoded kubelet volume directory path
  100. // framework.TestContext.KubeVolumeDir is currently not populated for node e2e
  101. HostPath: &v1.HostPathVolumeSource{Path: "/var/lib/kubelet/pods"},
  102. },
  103. },
  104. },
  105. },
  106. })
  107. err = e2epod.WaitForPodSuccessInNamespace(f.ClientSet, pod.Name, f.Namespace.Name)
  108. gp := int64(1)
  109. f.PodClient().Delete(context.TODO(), pod.Name, &metav1.DeleteOptions{GracePeriodSeconds: &gp})
  110. if err == nil {
  111. break
  112. }
  113. <-time.After(10 * time.Second)
  114. }
  115. framework.ExpectNoError(err)
  116. })
  117. })
  118. })
  119. })
  120. })