Enable PVC as DataSource for PVC creation

This enables the ability to specify and existing PVC as a DataSource in
a new PVC Spec (eg "clone" and existing volume).
This commit is contained in:
j-griffith
2019-04-11 13:45:03 -06:00
parent 8b7e777fe8
commit 123f1bac35
4 changed files with 70 additions and 7 deletions

View File

@@ -13288,3 +13288,48 @@ func TestValidateWindowsSecurityContextOptions(t *testing.T) {
})
}
}
func testDataSourceInSpec(name string, kind string, apiGroup string) *core.PersistentVolumeClaimSpec {
scName := "csi-plugin"
dataSourceInSpec := core.PersistentVolumeClaimSpec{
AccessModes: []core.PersistentVolumeAccessMode{
core.ReadOnlyMany,
},
Resources: core.ResourceRequirements{
Requests: core.ResourceList{
core.ResourceName(core.ResourceStorage): resource.MustParse("10G"),
},
},
StorageClassName: &scName,
DataSource: &core.TypedLocalObjectReference{
APIGroup: &apiGroup,
Kind: kind,
Name: name,
},
}
return &dataSourceInSpec
}
func TestAlphaVolumeDataSource(t *testing.T) {
successTestCases := []core.PersistentVolumeClaimSpec{
*testDataSourceInSpec("test_snapshot", "VolumeSnapshot", "snapshot.storage.k8s.io"),
*testDataSourceInSpec("test_pvc", "PersistentVolumeClaim", ""),
}
failedTestCases := []core.PersistentVolumeClaimSpec{
*testDataSourceInSpec("", "VolumeSnapshot", "snapshot.storage.k8s.io"),
*testDataSourceInSpec("test_snapshot", "PersistentVolumeClaim", "snapshot.storage.k8s.io"),
*testDataSourceInSpec("test_snapshot", "VolumeSnapshot", "storage.k8s.io"),
}
for _, tc := range successTestCases {
if errs := ValidatePersistentVolumeClaimSpec(&tc, field.NewPath("spec")); len(errs) != 0 {
t.Errorf("expected success: %v", errs)
}
}
for _, tc := range failedTestCases {
if errs := ValidatePersistentVolumeClaimSpec(&tc, field.NewPath("spec")); len(errs) == 0 {
t.Errorf("expected failure: %v", errs)
}
}
}