vsphere_volume_cluster_ds.go 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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. "context"
  16. "github.com/onsi/ginkgo"
  17. "github.com/onsi/gomega"
  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. e2eskipper "k8s.io/kubernetes/test/e2e/framework/skipper"
  23. "k8s.io/kubernetes/test/e2e/storage/utils"
  24. )
  25. /*
  26. Tests to verify volume provisioning on a clustered datastore
  27. 1. Static provisioning
  28. 2. Dynamic provisioning
  29. 3. Dynamic provisioning with spbm policy
  30. This test reads env
  31. 1. CLUSTER_DATASTORE which should be set to clustered datastore
  32. 2. VSPHERE_SPBM_POLICY_DS_CLUSTER which should be set to a tag based spbm policy tagged to a clustered datastore
  33. */
  34. var _ = utils.SIGDescribe("Volume Provisioning On Clustered Datastore [Feature:vsphere]", func() {
  35. f := framework.NewDefaultFramework("volume-provision")
  36. var (
  37. client clientset.Interface
  38. namespace string
  39. scParameters map[string]string
  40. clusterDatastore string
  41. nodeInfo *NodeInfo
  42. )
  43. ginkgo.BeforeEach(func() {
  44. e2eskipper.SkipUnlessProviderIs("vsphere")
  45. Bootstrap(f)
  46. client = f.ClientSet
  47. namespace = f.Namespace.Name
  48. nodeInfo = GetReadySchedulableRandomNodeInfo()
  49. scParameters = make(map[string]string)
  50. clusterDatastore = GetAndExpectStringEnvVar(VCPClusterDatastore)
  51. })
  52. /*
  53. Steps:
  54. 1. Create volume options with datastore to be a clustered datastore
  55. 2. Create a vsphere volume
  56. 3. Create podspec with volume path. Create a corresponding pod
  57. 4. Verify disk is attached
  58. 5. Delete the pod and wait for the disk to be detached
  59. 6. Delete the volume
  60. */
  61. ginkgo.It("verify static provisioning on clustered datastore", func() {
  62. var volumePath string
  63. ginkgo.By("creating a test vsphere volume")
  64. volumeOptions := new(VolumeOptions)
  65. volumeOptions.CapacityKB = 2097152
  66. volumeOptions.Name = "e2e-vmdk-" + namespace
  67. volumeOptions.Datastore = clusterDatastore
  68. volumePath, err := nodeInfo.VSphere.CreateVolume(volumeOptions, nodeInfo.DataCenterRef)
  69. framework.ExpectNoError(err)
  70. defer func() {
  71. ginkgo.By("Deleting the vsphere volume")
  72. nodeInfo.VSphere.DeleteVolume(volumePath, nodeInfo.DataCenterRef)
  73. }()
  74. podspec := getVSpherePodSpecWithVolumePaths([]string{volumePath}, nil, nil)
  75. ginkgo.By("Creating pod")
  76. pod, err := client.CoreV1().Pods(namespace).Create(context.TODO(), podspec, metav1.CreateOptions{})
  77. framework.ExpectNoError(err)
  78. ginkgo.By("Waiting for pod to be ready")
  79. gomega.Expect(e2epod.WaitForPodNameRunningInNamespace(client, pod.Name, namespace)).To(gomega.Succeed())
  80. // get fresh pod info
  81. pod, err = client.CoreV1().Pods(namespace).Get(context.TODO(), pod.Name, metav1.GetOptions{})
  82. framework.ExpectNoError(err)
  83. nodeName := pod.Spec.NodeName
  84. ginkgo.By("Verifying volume is attached")
  85. expectVolumeToBeAttached(nodeName, volumePath)
  86. ginkgo.By("Deleting pod")
  87. err = e2epod.DeletePodWithWait(client, pod)
  88. framework.ExpectNoError(err)
  89. ginkgo.By("Waiting for volumes to be detached from the node")
  90. err = waitForVSphereDiskToDetach(volumePath, nodeName)
  91. framework.ExpectNoError(err)
  92. })
  93. /*
  94. Steps:
  95. 1. Create storage class parameter and specify datastore to be a clustered datastore name
  96. 2. invokeValidPolicyTest - util to do e2e dynamic provision test
  97. */
  98. ginkgo.It("verify dynamic provision with default parameter on clustered datastore", func() {
  99. scParameters[Datastore] = clusterDatastore
  100. invokeValidPolicyTest(f, client, namespace, scParameters)
  101. })
  102. /*
  103. Steps:
  104. 1. Create storage class parameter and specify storage policy to be a tag based spbm policy
  105. 2. invokeValidPolicyTest - util to do e2e dynamic provision test
  106. */
  107. ginkgo.It("verify dynamic provision with spbm policy on clustered datastore", func() {
  108. policyDatastoreCluster := GetAndExpectStringEnvVar(SPBMPolicyDataStoreCluster)
  109. scParameters[SpbmStoragePolicy] = policyDatastoreCluster
  110. invokeValidPolicyTest(f, client, namespace, scParameters)
  111. })
  112. })