pvc_label_selector.go 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. /*
  2. Copyright 2017 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 vsphere
  14. import (
  15. "time"
  16. "github.com/onsi/ginkgo"
  17. "k8s.io/api/core/v1"
  18. clientset "k8s.io/client-go/kubernetes"
  19. "k8s.io/kubernetes/test/e2e/framework"
  20. "k8s.io/kubernetes/test/e2e/storage/utils"
  21. )
  22. /*
  23. This is a function test for Selector-Label Volume Binding Feature
  24. Test verifies volume with the matching label is bounded with the PVC.
  25. Test Steps
  26. ----------
  27. 1. Create VMDK.
  28. 2. Create pv with label volume-type:ssd, volume path set to vmdk created in previous step, and PersistentVolumeReclaimPolicy is set to Delete.
  29. 3. Create PVC (pvc_vvol) with label selector to match with volume-type:vvol
  30. 4. Create PVC (pvc_ssd) with label selector to match with volume-type:ssd
  31. 5. Wait and verify pvc_ssd is bound with PV.
  32. 6. Verify Status of pvc_vvol is still pending.
  33. 7. Delete pvc_ssd.
  34. 8. verify associated pv is also deleted.
  35. 9. delete pvc_vvol
  36. */
  37. var _ = utils.SIGDescribe("PersistentVolumes [Feature:LabelSelector]", func() {
  38. f := framework.NewDefaultFramework("pvclabelselector")
  39. var (
  40. c clientset.Interface
  41. ns string
  42. pv_ssd *v1.PersistentVolume
  43. pvc_ssd *v1.PersistentVolumeClaim
  44. pvc_vvol *v1.PersistentVolumeClaim
  45. volumePath string
  46. ssdlabels map[string]string
  47. vvollabels map[string]string
  48. err error
  49. nodeInfo *NodeInfo
  50. )
  51. ginkgo.BeforeEach(func() {
  52. framework.SkipUnlessProviderIs("vsphere")
  53. c = f.ClientSet
  54. ns = f.Namespace.Name
  55. Bootstrap(f)
  56. nodeInfo = GetReadySchedulableRandomNodeInfo()
  57. framework.ExpectNoError(framework.WaitForAllNodesSchedulable(c, framework.TestContext.NodeSchedulableTimeout))
  58. ssdlabels = make(map[string]string)
  59. ssdlabels["volume-type"] = "ssd"
  60. vvollabels = make(map[string]string)
  61. vvollabels["volume-type"] = "vvol"
  62. })
  63. utils.SIGDescribe("Selector-Label Volume Binding:vsphere", func() {
  64. ginkgo.AfterEach(func() {
  65. ginkgo.By("Running clean up actions")
  66. if framework.ProviderIs("vsphere") {
  67. testCleanupVSpherePVClabelselector(c, ns, nodeInfo, volumePath, pv_ssd, pvc_ssd, pvc_vvol)
  68. }
  69. })
  70. ginkgo.It("should bind volume with claim for given label", func() {
  71. volumePath, pv_ssd, pvc_ssd, pvc_vvol, err = testSetupVSpherePVClabelselector(c, nodeInfo, ns, ssdlabels, vvollabels)
  72. framework.ExpectNoError(err)
  73. ginkgo.By("wait for the pvc_ssd to bind with pv_ssd")
  74. framework.ExpectNoError(framework.WaitOnPVandPVC(c, ns, pv_ssd, pvc_ssd))
  75. ginkgo.By("Verify status of pvc_vvol is pending")
  76. err = framework.WaitForPersistentVolumeClaimPhase(v1.ClaimPending, c, ns, pvc_vvol.Name, 3*time.Second, 300*time.Second)
  77. framework.ExpectNoError(err)
  78. ginkgo.By("delete pvc_ssd")
  79. framework.ExpectNoError(framework.DeletePersistentVolumeClaim(c, pvc_ssd.Name, ns), "Failed to delete PVC ", pvc_ssd.Name)
  80. ginkgo.By("verify pv_ssd is deleted")
  81. err = framework.WaitForPersistentVolumeDeleted(c, pv_ssd.Name, 3*time.Second, 300*time.Second)
  82. framework.ExpectNoError(err)
  83. volumePath = ""
  84. ginkgo.By("delete pvc_vvol")
  85. framework.ExpectNoError(framework.DeletePersistentVolumeClaim(c, pvc_vvol.Name, ns), "Failed to delete PVC ", pvc_vvol.Name)
  86. })
  87. })
  88. })
  89. func testSetupVSpherePVClabelselector(c clientset.Interface, nodeInfo *NodeInfo, ns string, ssdlabels map[string]string, vvollabels map[string]string) (volumePath string, pv_ssd *v1.PersistentVolume, pvc_ssd *v1.PersistentVolumeClaim, pvc_vvol *v1.PersistentVolumeClaim, err error) {
  90. ginkgo.By("creating vmdk")
  91. volumePath = ""
  92. volumePath, err = nodeInfo.VSphere.CreateVolume(&VolumeOptions{}, nodeInfo.DataCenterRef)
  93. if err != nil {
  94. return
  95. }
  96. ginkgo.By("creating the pv with label volume-type:ssd")
  97. pv_ssd = getVSpherePersistentVolumeSpec(volumePath, v1.PersistentVolumeReclaimDelete, ssdlabels)
  98. pv_ssd, err = c.CoreV1().PersistentVolumes().Create(pv_ssd)
  99. if err != nil {
  100. return
  101. }
  102. ginkgo.By("creating pvc with label selector to match with volume-type:vvol")
  103. pvc_vvol = getVSpherePersistentVolumeClaimSpec(ns, vvollabels)
  104. pvc_vvol, err = c.CoreV1().PersistentVolumeClaims(ns).Create(pvc_vvol)
  105. if err != nil {
  106. return
  107. }
  108. ginkgo.By("creating pvc with label selector to match with volume-type:ssd")
  109. pvc_ssd = getVSpherePersistentVolumeClaimSpec(ns, ssdlabels)
  110. pvc_ssd, err = c.CoreV1().PersistentVolumeClaims(ns).Create(pvc_ssd)
  111. return
  112. }
  113. func testCleanupVSpherePVClabelselector(c clientset.Interface, ns string, nodeInfo *NodeInfo, volumePath string, pv_ssd *v1.PersistentVolume, pvc_ssd *v1.PersistentVolumeClaim, pvc_vvol *v1.PersistentVolumeClaim) {
  114. ginkgo.By("running testCleanupVSpherePVClabelselector")
  115. if len(volumePath) > 0 {
  116. nodeInfo.VSphere.DeleteVolume(volumePath, nodeInfo.DataCenterRef)
  117. }
  118. if pvc_ssd != nil {
  119. framework.ExpectNoError(framework.DeletePersistentVolumeClaim(c, pvc_ssd.Name, ns), "Failed to delete PVC ", pvc_ssd.Name)
  120. }
  121. if pvc_vvol != nil {
  122. framework.ExpectNoError(framework.DeletePersistentVolumeClaim(c, pvc_vvol.Name, ns), "Failed to delete PVC ", pvc_vvol.Name)
  123. }
  124. if pv_ssd != nil {
  125. framework.ExpectNoError(framework.DeletePersistentVolume(c, pv_ssd.Name), "Failed to delete PV ", pv_ssd.Name)
  126. }
  127. }