generic_persistent_volume-disruptive.go 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /*
  2. Copyright 2018 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 storage
  14. import (
  15. "context"
  16. "github.com/onsi/ginkgo"
  17. v1 "k8s.io/api/core/v1"
  18. metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
  19. clientset "k8s.io/client-go/kubernetes"
  20. "k8s.io/kubernetes/test/e2e/framework"
  21. e2epod "k8s.io/kubernetes/test/e2e/framework/pod"
  22. e2epv "k8s.io/kubernetes/test/e2e/framework/pv"
  23. e2eskipper "k8s.io/kubernetes/test/e2e/framework/skipper"
  24. "k8s.io/kubernetes/test/e2e/storage/testsuites"
  25. "k8s.io/kubernetes/test/e2e/storage/utils"
  26. )
  27. var _ = utils.SIGDescribe("GenericPersistentVolume[Disruptive]", func() {
  28. f := framework.NewDefaultFramework("generic-disruptive-pv")
  29. var (
  30. c clientset.Interface
  31. ns string
  32. )
  33. ginkgo.BeforeEach(func() {
  34. // Skip tests unless number of nodes is 2
  35. e2eskipper.SkipUnlessNodeCountIsAtLeast(2)
  36. e2eskipper.SkipIfProviderIs("local")
  37. c = f.ClientSet
  38. ns = f.Namespace.Name
  39. })
  40. disruptiveTestTable := []disruptiveTest{
  41. {
  42. testItStmt: "Should test that a file written to the mount before kubelet restart is readable after restart.",
  43. runTest: utils.TestKubeletRestartsAndRestoresMount,
  44. },
  45. {
  46. testItStmt: "Should test that a volume mounted to a pod that is deleted while the kubelet is down unmounts when the kubelet returns.",
  47. runTest: utils.TestVolumeUnmountsFromDeletedPod,
  48. },
  49. {
  50. testItStmt: "Should test that a volume mounted to a pod that is force deleted while the kubelet is down unmounts when the kubelet returns.",
  51. runTest: utils.TestVolumeUnmountsFromForceDeletedPod,
  52. },
  53. }
  54. ginkgo.Context("When kubelet restarts", func() {
  55. // Test table housing the ginkgo.It() title string and test spec. runTest is type testBody, defined at
  56. // the start of this file. To add tests, define a function mirroring the testBody signature and assign
  57. // to runTest.
  58. var (
  59. clientPod *v1.Pod
  60. pvc *v1.PersistentVolumeClaim
  61. pv *v1.PersistentVolume
  62. )
  63. ginkgo.BeforeEach(func() {
  64. framework.Logf("Initializing pod and pvcs for test")
  65. clientPod, pvc, pv = createPodPVCFromSC(f, c, ns)
  66. })
  67. for _, test := range disruptiveTestTable {
  68. func(t disruptiveTest) {
  69. ginkgo.It(t.testItStmt, func() {
  70. ginkgo.By("Executing Spec")
  71. t.runTest(c, f, clientPod)
  72. })
  73. }(test)
  74. }
  75. ginkgo.AfterEach(func() {
  76. framework.Logf("Tearing down test spec")
  77. tearDownTestCase(c, f, ns, clientPod, pvc, pv, false)
  78. pvc, clientPod = nil, nil
  79. })
  80. })
  81. })
  82. func createPodPVCFromSC(f *framework.Framework, c clientset.Interface, ns string) (*v1.Pod, *v1.PersistentVolumeClaim, *v1.PersistentVolume) {
  83. var err error
  84. test := testsuites.StorageClassTest{
  85. Name: "default",
  86. ClaimSize: "2Gi",
  87. }
  88. pvc := e2epv.MakePersistentVolumeClaim(e2epv.PersistentVolumeClaimConfig{
  89. ClaimSize: test.ClaimSize,
  90. VolumeMode: &test.VolumeMode,
  91. }, ns)
  92. pvc, err = c.CoreV1().PersistentVolumeClaims(pvc.Namespace).Create(context.TODO(), pvc, metav1.CreateOptions{})
  93. framework.ExpectNoError(err, "Error creating pvc")
  94. pvcClaims := []*v1.PersistentVolumeClaim{pvc}
  95. pvs, err := e2epv.WaitForPVClaimBoundPhase(c, pvcClaims, framework.ClaimProvisionTimeout)
  96. framework.ExpectNoError(err, "Failed waiting for PVC to be bound %v", err)
  97. framework.ExpectEqual(len(pvs), 1)
  98. ginkgo.By("Creating a pod with dynamically provisioned volume")
  99. pod, err := e2epod.CreateSecPod(c, ns, pvcClaims, nil,
  100. false, "", false, false, e2epv.SELinuxLabel,
  101. nil, framework.PodStartTimeout)
  102. framework.ExpectNoError(err, "While creating pods for kubelet restart test")
  103. return pod, pvc, pvs[0]
  104. }