Skip to content

Commit 1955467

Browse files
authored
Merge pull request kubernetes#80117 from j-griffith/cloning_e2e_tests
Add e2e tests for CSI PVCDataSources
2 parents 7420bb2 + 47facf9 commit 1955467

File tree

4 files changed

+85
-17
lines changed

4 files changed

+85
-17
lines changed

test/e2e/storage/drivers/csi.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,9 @@ var _ testsuites.SnapshottableTestDriver = &hostpathCSIDriver{}
8787
// InitHostPathCSIDriver returns hostpathCSIDriver that implements TestDriver interface
8888
func InitHostPathCSIDriver() testsuites.TestDriver {
8989
return initHostPathCSIDriver("csi-hostpath",
90-
map[testsuites.Capability]bool{testsuites.CapPersistence: true, testsuites.CapDataSource: true,
91-
testsuites.CapMultiPODs: true, testsuites.CapBlock: true},
90+
map[testsuites.Capability]bool{testsuites.CapPersistence: true, testsuites.CapSnapshotDataSource: true,
91+
testsuites.CapMultiPODs: true, testsuites.CapBlock: true,
92+
testsuites.CapPVCDataSource: true},
9293
"test/e2e/testing-manifests/storage-csi/driver-registrar/rbac.yaml",
9394
"test/e2e/testing-manifests/storage-csi/external-attacher/rbac.yaml",
9495
"test/e2e/testing-manifests/storage-csi/external-provisioner/rbac.yaml",

test/e2e/storage/testsuites/provisioning.go

Lines changed: 75 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ import (
4444
type StorageClassTest struct {
4545
Client clientset.Interface
4646
Claim *v1.PersistentVolumeClaim
47+
SourceClaim *v1.PersistentVolumeClaim
4748
Class *storagev1.StorageClass
4849
Name string
4950
CloudProviders []string
@@ -86,10 +87,11 @@ func (p *provisioningTestSuite) defineTests(driver TestDriver, pattern testpatte
8687
config *PerTestConfig
8788
testCleanup func()
8889

89-
testCase *StorageClassTest
90-
cs clientset.Interface
91-
pvc *v1.PersistentVolumeClaim
92-
sc *storagev1.StorageClass
90+
testCase *StorageClassTest
91+
cs clientset.Interface
92+
pvc *v1.PersistentVolumeClaim
93+
sourcePVC *v1.PersistentVolumeClaim
94+
sc *storagev1.StorageClass
9395

9496
intreeOps opCounts
9597
migratedOps opCounts
@@ -134,10 +136,15 @@ func (p *provisioningTestSuite) defineTests(driver TestDriver, pattern testpatte
134136
ClaimSize: claimSize,
135137
StorageClassName: &(l.sc.Name),
136138
}, l.config.Framework.Namespace.Name)
137-
e2elog.Logf("In creating storage class object and pvc object for driver - sc: %v, pvc: %v", l.sc, l.pvc)
139+
l.sourcePVC = framework.MakePersistentVolumeClaim(framework.PersistentVolumeClaimConfig{
140+
ClaimSize: claimSize,
141+
StorageClassName: &(l.sc.Name),
142+
}, l.config.Framework.Namespace.Name)
143+
e2elog.Logf("In creating storage class object and pvc objects for driver - sc: %v, pvc: %v, src-pvc: %v", l.sc, l.pvc, l.sourcePVC)
138144
l.testCase = &StorageClassTest{
139145
Client: l.config.Framework.ClientSet,
140146
Claim: l.pvc,
147+
SourceClaim: l.sourcePVC,
141148
Class: l.sc,
142149
ClaimSize: claimSize,
143150
ExpectedSize: claimSize,
@@ -169,21 +176,21 @@ func (p *provisioningTestSuite) defineTests(driver TestDriver, pattern testpatte
169176
})
170177

171178
ginkgo.It("should provision storage with snapshot data source [Feature:VolumeSnapshotDataSource]", func() {
172-
if !dInfo.Capabilities[CapDataSource] {
179+
if !dInfo.Capabilities[CapSnapshotDataSource] {
173180
framework.Skipf("Driver %q does not support populate data from snapshot - skipping", dInfo.Name)
174181
}
175182

176183
sDriver, ok := driver.(SnapshottableTestDriver)
177184
if !ok {
178-
e2elog.Failf("Driver %q has CapDataSource but does not implement SnapshottableTestDriver", dInfo.Name)
185+
e2elog.Failf("Driver %q has CapSnapshotDataSource but does not implement SnapshottableTestDriver", dInfo.Name)
179186
}
180187

181188
init()
182189
defer cleanup()
183190

184191
dc := l.config.Framework.DynamicClient
185192
vsc := sDriver.GetSnapshotClass(l.config)
186-
dataSource, cleanupFunc := prepareDataSourceForProvisioning(framework.NodeSelection{Name: l.config.ClientNodeName}, l.cs, dc, l.pvc, l.sc, vsc)
193+
dataSource, cleanupFunc := prepareSnapshotDataSourceForProvisioning(framework.NodeSelection{Name: l.config.ClientNodeName}, l.cs, dc, l.pvc, l.sc, vsc)
187194
defer cleanupFunc()
188195

189196
l.pvc.Spec.DataSource = dataSource
@@ -194,6 +201,26 @@ func (p *provisioningTestSuite) defineTests(driver TestDriver, pattern testpatte
194201
}
195202
l.testCase.TestDynamicProvisioning()
196203
})
204+
ginkgo.It("should provision storage with pvc data source [Feature:VolumePVCDataSource]", func() {
205+
if !dInfo.Capabilities[CapPVCDataSource] {
206+
framework.Skipf("Driver %q does not support cloning - skipping", dInfo.Name)
207+
}
208+
209+
init()
210+
defer cleanup()
211+
212+
dc := l.config.Framework.DynamicClient
213+
dataSource, dataSourceCleanup := preparePVCDataSourceForProvisioning(framework.NodeSelection{Name: l.config.ClientNodeName}, l.cs, dc, l.sourcePVC, l.sc)
214+
defer dataSourceCleanup()
215+
216+
l.pvc.Spec.DataSource = dataSource
217+
l.testCase.PvCheck = func(claim *v1.PersistentVolumeClaim) {
218+
ginkgo.By("checking whether the created volume has the pre-populated data")
219+
command := fmt.Sprintf("grep '%s' /mnt/test/initialData", claim.Namespace)
220+
RunInPodWithVolume(l.cs, claim.Namespace, claim.Name, "pvc-datasource-tester", command, framework.NodeSelection{Name: l.config.ClientNodeName})
221+
}
222+
l.testCase.TestDynamicProvisioning()
223+
})
197224
}
198225

199226
// TestDynamicProvisioning tests dynamic provisioning with specified StorageClassTest
@@ -581,7 +608,7 @@ func verifyPVCsPending(client clientset.Interface, pvcs []*v1.PersistentVolumeCl
581608
}
582609
}
583610

584-
func prepareDataSourceForProvisioning(
611+
func prepareSnapshotDataSourceForProvisioning(
585612
node framework.NodeSelection,
586613
client clientset.Interface,
587614
dynamicClient dynamic.Interface,
@@ -653,3 +680,42 @@ func prepareDataSourceForProvisioning(
653680

654681
return dataSourceRef, cleanupFunc
655682
}
683+
684+
func preparePVCDataSourceForProvisioning(
685+
node framework.NodeSelection,
686+
client clientset.Interface,
687+
dynamicClient dynamic.Interface,
688+
source *v1.PersistentVolumeClaim,
689+
class *storagev1.StorageClass,
690+
) (*v1.TypedLocalObjectReference, func()) {
691+
var err error
692+
if class != nil {
693+
ginkgo.By("[Initialize dataSource]creating a StorageClass " + class.Name)
694+
_, err = client.StorageV1().StorageClasses().Create(class)
695+
framework.ExpectNoError(err)
696+
}
697+
698+
ginkgo.By("[Initialize dataSource]creating a source PVC")
699+
sourcePVC, err := client.CoreV1().PersistentVolumeClaims(source.Namespace).Create(source)
700+
framework.ExpectNoError(err)
701+
702+
// write namespace to the /mnt/test (= the volume).
703+
ginkgo.By("[Initialize dataSource]write data to volume")
704+
command := fmt.Sprintf("echo '%s' > /mnt/test/initialData", sourcePVC.GetNamespace())
705+
RunInPodWithVolume(client, sourcePVC.Namespace, sourcePVC.Name, "pvc-datasource-writer", command, node)
706+
707+
dataSourceRef := &v1.TypedLocalObjectReference{
708+
Kind: "PersistentVolumeClaim",
709+
Name: sourcePVC.GetName(),
710+
}
711+
712+
cleanupFunc := func() {
713+
e2elog.Logf("deleting source PVC %q/%q", sourcePVC.Namespace, sourcePVC.Name)
714+
err = client.CoreV1().PersistentVolumeClaims(sourcePVC.Namespace).Delete(sourcePVC.Name, nil)
715+
if err != nil && !apierrs.IsNotFound(err) {
716+
e2elog.Failf("Error deleting source PVC %q. Error: %v", sourcePVC.Name, err)
717+
}
718+
}
719+
720+
return dataSourceRef, cleanupFunc
721+
}

test/e2e/storage/testsuites/snapshottable.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ func (s *snapshottableTestSuite) defineTests(driver TestDriver, pattern testpatt
7878
dInfo := driver.GetDriverInfo()
7979
ok := false
8080
sDriver, ok = driver.(SnapshottableTestDriver)
81-
if !dInfo.Capabilities[CapDataSource] || !ok {
81+
if !dInfo.Capabilities[CapSnapshotDataSource] || !ok {
8282
framework.Skipf("Driver %q does not support snapshots - skipping", dInfo.Name)
8383
}
8484
dDriver, ok = driver.(DynamicPVTestDriver)

test/e2e/storage/testsuites/testdriver.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -131,11 +131,12 @@ type Capability string
131131

132132
// Constants related to capability
133133
const (
134-
CapPersistence Capability = "persistence" // data is persisted across pod restarts
135-
CapBlock Capability = "block" // raw block mode
136-
CapFsGroup Capability = "fsGroup" // volume ownership via fsGroup
137-
CapExec Capability = "exec" // exec a file in the volume
138-
CapDataSource Capability = "dataSource" // support populate data from snapshot
134+
CapPersistence Capability = "persistence" // data is persisted across pod restarts
135+
CapBlock Capability = "block" // raw block mode
136+
CapFsGroup Capability = "fsGroup" // volume ownership via fsGroup
137+
CapExec Capability = "exec" // exec a file in the volume
138+
CapSnapshotDataSource Capability = "snapshotDataSource" // support populate data from snapshot
139+
CapPVCDataSource Capability = "pvcDataSource" // support populate data from pvc
139140

140141
// multiple pods on a node can use the same volume concurrently;
141142
// for CSI, see:

0 commit comments

Comments
 (0)