Merge pull request #55204 from vladimirvivien/k8s-csi-volume-source

Automatic merge from submit-queue. If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

Kubernetes CSI - Persistent Volume Source Type

**What this PR does / why we need it**:
This PR is to track the addition of new API type `CSIPersistentVolumeSource` that will be used as PersistentVolume for storage sources managed by CSI drivers. 

**Which issue(s) this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close the issue(s) when PR gets merged)*:
xref https://github.com/kubernetes/features/issues/178

**Special notes for your reviewer**:
- Implements API `PersistentVolume` type `CSIPersistentVolumeSource`
- Part of implementation for https://github.com/kubernetes/features/issues/178
- Designed at https://github.com/kubernetes/community/pull/1258

Other CSI Volume Plugin PRs:
- Plugin Mounter/Unmounter https://github.com/kubernetes/kubernetes/pull/54529
- Plugin Attacher/Detacher https://github.com/kubernetes/kubernetes/pull/55809

**Release note**:

```release-note
NONE
```
This commit is contained in:
Kubernetes Submit Queue
2017-11-17 22:18:30 -08:00
committed by GitHub
19 changed files with 1854 additions and 1212 deletions

View File

@@ -1353,6 +1353,64 @@ func TestValidateGlusterfs(t *testing.T) {
}
}
func TestValidateCSIVolumeSource(t *testing.T) {
testCases := []struct {
name string
csi *api.CSIPersistentVolumeSource
errtype field.ErrorType
errfield string
}{
{
name: "all required fields ok",
csi: &api.CSIPersistentVolumeSource{Driver: "test-driver", VolumeHandle: "test-123", ReadOnly: true},
},
{
name: "with default values ok",
csi: &api.CSIPersistentVolumeSource{Driver: "test-driver", VolumeHandle: "test-123"},
},
{
name: "missing driver name",
csi: &api.CSIPersistentVolumeSource{VolumeHandle: "test-123"},
errtype: field.ErrorTypeRequired,
errfield: "driver",
},
{
name: "missing volume handle",
csi: &api.CSIPersistentVolumeSource{Driver: "my-driver"},
errtype: field.ErrorTypeRequired,
errfield: "volumeHandle",
},
}
err := utilfeature.DefaultFeatureGate.Set("CSIPersistentVolume=true")
if err != nil {
t.Errorf("Failed to enable feature gate for CSIPersistentVolumes: %v", err)
return
}
for i, tc := range testCases {
errs := validateCSIPersistentVolumeSource(tc.csi, field.NewPath("field"))
if len(errs) > 0 && tc.errtype == "" {
t.Errorf("[%d: %q] unexpected error(s): %v", i, tc.name, errs)
} else if len(errs) == 0 && tc.errtype != "" {
t.Errorf("[%d: %q] expected error type %v", i, tc.name, tc.errtype)
} else if len(errs) >= 1 {
if errs[0].Type != tc.errtype {
t.Errorf("[%d: %q] expected error type %v, got %v", i, tc.name, tc.errtype, errs[0].Type)
} else if !strings.HasSuffix(errs[0].Field, "."+tc.errfield) {
t.Errorf("[%d: %q] expected error on field %q, got %q", i, tc.name, tc.errfield, errs[0].Field)
}
}
}
err = utilfeature.DefaultFeatureGate.Set("CSIPersistentVolume=false")
if err != nil {
t.Errorf("Failed to disable feature gate for CSIPersistentVolumes: %v", err)
return
}
}
// helper
func newInt32(val int) *int32 {
p := new(int32)