-
Notifications
You must be signed in to change notification settings - Fork 173
/
volume_provisioning_with_topology.go
255 lines (222 loc) · 12.2 KB
/
volume_provisioning_with_topology.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
/*
Copyright 2019 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package e2e
import (
"fmt"
"strings"
"time"
"github.com/onsi/ginkgo"
"github.com/onsi/gomega"
v1 "k8s.io/api/core/v1"
storagev1 "k8s.io/api/storage/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
clientset "k8s.io/client-go/kubernetes"
"k8s.io/kubernetes/test/e2e/framework"
e2elog "k8s.io/kubernetes/test/e2e/framework"
)
var _ = ginkgo.Describe("[csi-topology-block-e2e] Basic-Topology-Aware-Provisioning", func() {
f := framework.NewDefaultFramework("e2e-vsphere-topology-aware-provisioning")
var (
client clientset.Interface
namespace string
zoneValues []string
regionValues []string
allZones []string
allRegions []string
pvZone string
pvRegion string
allowedTopologies []v1.TopologySelectorLabelRequirement
nodeList *v1.NodeList
pod *v1.Pod
pvclaim *v1.PersistentVolumeClaim
storageclass *storagev1.StorageClass
err error
)
ginkgo.BeforeEach(func() {
client = f.ClientSet
namespace = f.Namespace.Name
bootstrap()
nodeList = framework.GetReadySchedulableNodesOrDie(f.ClientSet)
if !(len(nodeList.Items) > 0) {
framework.Failf("Unable to find ready and schedulable Node")
}
regionZoneValue := GetAndExpectStringEnvVar(envRegionZoneWithSharedDS)
regionValues, zoneValues, allowedTopologies = topologyParameterForStorageClass(regionZoneValue)
// Preparing all zones and regions with shared and non shared datastores
topologyWithSharedDS := GetAndExpectStringEnvVar(envRegionZoneWithSharedDS)
topologyWithNoSharedDS := GetAndExpectStringEnvVar(envRegionZoneWithNoSharedDS)
topologyWithOnlyOneNode := GetAndExpectStringEnvVar(envTopologyWithOnlyOneNode)
topologyValues := topologyWithSharedDS + "," + topologyWithNoSharedDS + "," + topologyWithOnlyOneNode
allRegions, allZones, _ = topologyParameterForStorageClass(topologyValues)
})
testCleanUpUtil := func() {
ginkgo.By("Performing cleanup")
ginkgo.By("Deleting the pod and wait for disk to detach")
err := framework.DeletePodWithWait(f, client, pod)
gomega.Expect(err).NotTo(gomega.HaveOccurred())
ginkgo.By("Deleting the PVC")
err = framework.DeletePersistentVolumeClaim(client, pvclaim.Name, namespace)
gomega.Expect(err).NotTo(gomega.HaveOccurred())
ginkgo.By("Deleting the Storage Class")
err = client.StorageV1().StorageClasses().Delete(storageclass.Name, nil)
gomega.Expect(err).NotTo(gomega.HaveOccurred())
}
verifyBasicTopologyBasedVolumeProvisioning := func(f *framework.Framework, client clientset.Interface, namespace string, scParameters map[string]string, allowedTopologies []v1.TopologySelectorLabelRequirement) {
storageclass, pvclaim, err = createPVCAndStorageClass(client, namespace, nil, scParameters, "", allowedTopologies, "")
gomega.Expect(err).NotTo(gomega.HaveOccurred())
ginkgo.By("Expect claim to pass provisioning volume")
err = framework.WaitForPersistentVolumeClaimPhase(v1.ClaimBound, client, pvclaim.Namespace, pvclaim.Name, framework.Poll, time.Minute)
gomega.Expect(err).NotTo(gomega.HaveOccurred(), fmt.Sprintf("Failed to provision volume with err: %v", err))
ginkgo.By("Verify if volume is provisioned in specified zone and region")
pv := getPvFromClaim(client, pvclaim.Namespace, pvclaim.Name)
if allowedTopologies == nil {
zoneValues = allZones
regionValues = allRegions
}
pvRegion, pvZone, err = verifyVolumeTopology(pv, zoneValues, regionValues)
gomega.Expect(err).NotTo(gomega.HaveOccurred())
ginkgo.By("Creating a pod")
pod, err := framework.CreatePod(client, namespace, nil, []*v1.PersistentVolumeClaim{pvclaim}, false, "")
gomega.Expect(err).NotTo(gomega.HaveOccurred())
ginkgo.By("Verify volume is attached to the node")
isDiskAttached, err := e2eVSphere.isVolumeAttachedToNode(client, pv.Spec.CSI.VolumeHandle, pod.Spec.NodeName)
gomega.Expect(err).NotTo(gomega.HaveOccurred())
gomega.Expect(isDiskAttached).To(gomega.BeTrue(), fmt.Sprintf("Volume is not attached to the node"))
ginkgo.By("Verify Pod is scheduled on a node belonging to same topology as the PV it is attached to")
err = verifyPodLocation(pod, nodeList, pvZone, pvRegion)
gomega.Expect(err).NotTo(gomega.HaveOccurred())
}
invokeTopologyBasedVolumeProvisioningWithInaccessibleParameters := func(f *framework.Framework, client clientset.Interface, namespace string, scParameters map[string]string, allowedTopologies []v1.TopologySelectorLabelRequirement, expectedErrMsg string) {
storageclass, pvclaim, err = createPVCAndStorageClass(client, namespace, nil, scParameters, "", allowedTopologies, "")
defer client.StorageV1().StorageClasses().Delete(storageclass.Name, nil)
ginkgo.By("Expect claim to fail provisioning volume on inaccessible non shared datastore")
err = framework.WaitForPersistentVolumeClaimPhase(v1.ClaimBound, client, pvclaim.Namespace, pvclaim.Name, framework.Poll, time.Minute/2)
gomega.Expect(err).To(gomega.HaveOccurred())
// Get the event list and verify if it contains expected error message
eventList, _ := client.CoreV1().Events(pvclaim.Namespace).List(metav1.ListOptions{})
gomega.Expect(eventList.Items).NotTo(gomega.BeEmpty())
actualErrMsg := eventList.Items[len(eventList.Items)-1].Message
e2elog.Logf(fmt.Sprintf("Actual failure message: %+q", actualErrMsg))
e2elog.Logf(fmt.Sprintf("Expected failure message: %+q", expectedErrMsg))
gomega.Expect(strings.Contains(actualErrMsg, expectedErrMsg)).To(gomega.BeTrue(), fmt.Sprintf("actualErrMsg: %q does not contain expectedErrMsg: %q", actualErrMsg, expectedErrMsg))
}
/*
Test to verify provisioning volume with valid zone and region specified in Storage Class succeeds.
Volume should be provisioned with Node Affinity rules for that zone/region.
Pod should be scheduled on Node located within that zone/region.
Steps
1. Create a Storage Class with valid region and zone specified in “AllowedTopologies”
2. Create a PVC using above SC
3. Wait for PVC to be in bound phase
4. Verify PV is created in specified zone and region
5. Create a Pod attached to the above PV
6. Verify Pod is scheduled on node located within the specified zone and region
7. Delete Pod and wait for disk to be detached
8. Delete PVC
9. Delete Storage Class
*/
ginkgo.It("Verify provisioning with valid topology specified in Storage Class passes", func() {
verifyBasicTopologyBasedVolumeProvisioning(f, client, namespace, nil, allowedTopologies)
testCleanUpUtil()
})
/*
Test to verify if provisioning with valid topology and a shared data store url specified in the Storage Class succeeds.
Volume should be provisioned with Node Affinity rules for that zone/region and on datastore matching datastoreURL.
Pod should be scheduled on Node located within that zone/region.
Steps
1. Create a Storage Class with spec containing valid region and zone in “AllowedTopologies” and datastoreURL accessible to this zone.
2. Create a PVC using above SC
3. Wait for PVC to be in bound phase
4. Verify volume is created in specified region and zone on datastore matching datastoreURL.
5. Create a Pod attached to the above PV
6. Verify Pod is scheduled on node located within the specified zone and region
7. Delete Pod and wait for disk to be detached
8. Delete PVC
9. Delete Storage Class
*/
ginkgo.It("Verify provisioning with valid topology and accessible shared datastore specified in Storage Class passes", func() {
sharedDatastoreURL := GetAndExpectStringEnvVar(envSharedDatastoreURL)
scParameters := make(map[string]string)
scParameters[scParamDatastoreURL] = sharedDatastoreURL
verifyBasicTopologyBasedVolumeProvisioning(f, client, namespace, scParameters, allowedTopologies)
testCleanUpUtil()
})
/*
Test to verify if provisioning with valid topology and storage policy specified in the Storage Class succeeds.
Volume should be provisioned with Node Affinity rules for that zone/region and on datastore compatible with Storage Policy specified.
Pod should be scheduled on Node located within that zone/region.
Steps
1. Create a Storage Class with with valid region and zone specified in “AllowedTopologies” and Storage Policy accessible to this zone.
2. Create a PVC using above SC
3. Wait for PVC to be in bound phase
4. Verify volume is created in specified region and zone on datastore compatible with Storage Policy specified.
5. Create a Pod attached to the above PV
6. Verify Pod is scheduled on node located within the specified zone and region
7. Delete Pod and wait for disk to be detached
8. Delete PVC
9. Delete Storage Class
*/
ginkgo.It("Verify dynamic volume provisioning works when allowed topology and storage policy is specified in the storageclass", func() {
storagePolicyNameForSharedDatastores := GetAndExpectStringEnvVar(envStoragePolicyNameForSharedDatastores)
scParameters := make(map[string]string)
scParameters[scParamStoragePolicyName] = storagePolicyNameForSharedDatastores
verifyBasicTopologyBasedVolumeProvisioning(f, client, namespace, scParameters, allowedTopologies)
testCleanUpUtil()
})
/*
Test to verify provisioning volume with valid zone and region fails, when an inaccessible non-shared datastore url is specified in Storage Class.
Steps
1. Create a Storage Class with spec containing valid region and zone in “AllowedTopologies” and datastoreURL inaccessible to this zone.
2. Create a PVC using above SC
3. Verify PVC creation fails with “Not Accessible” error
4. Delete PVC
*/
ginkgo.It("Verify provisioning volume with valid zone and region fails when an inaccessible non-shared datastore url is specified in Storage Class", func() {
nonSharedDatastoreURLInZone := GetAndExpectStringEnvVar(envInaccessibleZoneDatastoreURL)
scParameters := make(map[string]string)
scParameters[scParamDatastoreURL] = nonSharedDatastoreURLInZone
errStringToVerify := "DatastoreURL: " + scParameters[scParamDatastoreURL] + " specified in the storage class is not accessible in the topology"
invokeTopologyBasedVolumeProvisioningWithInaccessibleParameters(f, client, namespace, scParameters, allowedTopologies, errStringToVerify)
})
/*
Test to verify provisioning volume with valid zone and region fails, when storage policy from different zone is specified in Storage Class.
Steps
1. Create a Storage Class with spec containing valid region and zone in “AllowedTopologies” and storage policy from different zone.
2. Create a PVC using above SC
3. Verify PVC creation fails with “Not Accessible” error
4. Delete PVC
*/
ginkgo.It("Verify provisioning volume with valid zone and region fails when storage policy from different zone is specified in Storage Class", func() {
storagePolicyNameFromOtherZone := GetAndExpectStringEnvVar(envStoragePolicyNameFromInaccessibleZone)
scParameters := make(map[string]string)
scParameters[scParamStoragePolicyName] = storagePolicyNameFromOtherZone
errStringToVerify := "No compatible datastore found for storagePolicy"
invokeTopologyBasedVolumeProvisioningWithInaccessibleParameters(f, client, namespace, scParameters, allowedTopologies, errStringToVerify)
})
/*
Test to verify provisioning volume with no zone and region specified in Storage Class succeeds.
Volume should be provisioned with no Node Affinity rules for that zone/region.
Steps
1. Create a Storage Class with no region or zone specified in “AllowedTopologies”
2. Create a PVC using above SC
3. Wait for PVC to be in bound phase
4. Verify volume creation is successful
5. Verify PV does not contain any node affinity rules
6. Delete PVC
7. Delete Storage Class
*/
ginkgo.It("Verify provisioning with no topology specified in Storage Class passes", func() {
verifyBasicTopologyBasedVolumeProvisioning(f, client, namespace, nil, nil)
testCleanUpUtil()
})
})