generic_persistent_volume-disruptive.go 3.6 KB

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