diff --git a/pkg/apis/core/types.go b/pkg/apis/core/types.go index 03ffeb5b8d3..760d26309a3 100644 --- a/pkg/apis/core/types.go +++ b/pkg/apis/core/types.go @@ -1634,6 +1634,10 @@ type CSIPersistentVolumeSource struct { // Ex. "ext4", "xfs", "ntfs". Implicitly inferred to be "ext4" if unspecified. // +optional FSType string + + // Attributes of the volume to publish. + // +optional + VolumeAttributes map[string]string } // ContainerPort represents a network port in a single container diff --git a/pkg/volume/csi/csi_mounter.go b/pkg/volume/csi/csi_mounter.go index fcbe7e24ef2..52cda273d56 100644 --- a/pkg/volume/csi/csi_mounter.go +++ b/pkg/volume/csi/csi_mounter.go @@ -151,14 +151,7 @@ func (c *csiMountMgr) SetUpAt(dir string, fsGroup *int64) error { c.volumeInfo = attachment.Status.AttachmentMetadata } - // get volume attributes - // TODO: for alpha vol attributes are passed via PV.Annotations - // Beta will fix that - attribs, err := getVolAttribsFromSpec(c.spec) - if err != nil { - glog.Error(log("mounter.SetUpAt failed to extract volume attributes from PV annotations: %v", err)) - return err - } + attribs := csiSource.VolumeAttributes // create target_dir before call to NodePublish if err := os.MkdirAll(dir, 0750); err != nil { @@ -295,29 +288,6 @@ func (c *csiMountMgr) TearDownAt(dir string) error { return nil } -// getVolAttribsFromSpec extracts CSI VolumeAttributes information from PV.Annotations -// using key csi.kubernetes.io/volume-attributes. The annotation value is expected -// to be a JSON-encoded object of form {"key0":"val0",...,"keyN":"valN"} -func getVolAttribsFromSpec(spec *volume.Spec) (map[string]string, error) { - if spec == nil { - return nil, errors.New("missing volume spec") - } - annotations := spec.PersistentVolume.GetAnnotations() - if annotations == nil { - return nil, nil // no annotations found - } - jsonAttribs := annotations[csiVolAttribsAnnotationKey] - if jsonAttribs == "" { - return nil, nil // csi annotation not found - } - attribs := map[string]string{} - if err := json.Unmarshal([]byte(jsonAttribs), &attribs); err != nil { - glog.Error(log("error parsing csi PV.Annotation [%s]=%s: %v", csiVolAttribsAnnotationKey, jsonAttribs, err)) - return nil, err - } - return attribs, nil -} - // saveVolumeData persists parameter data as json file using the location // generated by /var/lib/kubelet/pods//volumes/kubernetes.io~csi//volume_data.json func saveVolumeData(p *csiPlugin, podUID types.UID, specVolID string, data map[string]string) error { diff --git a/pkg/volume/csi/csi_mounter_test.go b/pkg/volume/csi/csi_mounter_test.go index b95c1630a25..90555063dd6 100644 --- a/pkg/volume/csi/csi_mounter_test.go +++ b/pkg/volume/csi/csi_mounter_test.go @@ -202,53 +202,6 @@ func TestUnmounterTeardown(t *testing.T) { } -func TestGetVolAttribsFromSpec(t *testing.T) { - testCases := []struct { - name string - annotations map[string]string - attribs map[string]string - shouldFail bool - }{ - { - name: "attribs ok", - annotations: map[string]string{"key0": "val0", csiVolAttribsAnnotationKey: `{"k0":"attr0","k1":"attr1","k2":"attr2"}`, "keyN": "valN"}, - attribs: map[string]string{"k0": "attr0", "k1": "attr1", "k2": "attr2"}, - }, - - { - name: "missing attribs", - annotations: map[string]string{"key0": "val0", "keyN": "valN"}, - }, - { - name: "missing annotations", - }, - { - name: "bad json", - annotations: map[string]string{"key0": "val0", csiVolAttribsAnnotationKey: `{"k0""attr0","k1":"attr1,"k2":"attr2"`, "keyN": "valN"}, - attribs: map[string]string{"k0": "attr0", "k1": "attr1", "k2": "attr2"}, - shouldFail: true, - }, - } - spec := volume.NewSpecFromPersistentVolume(makeTestPV("test-pv", 10, testDriver, testVol), false) - for _, tc := range testCases { - t.Logf("test case: %s", tc.name) - spec.PersistentVolume.Annotations = tc.annotations - attribs, err := getVolAttribsFromSpec(spec) - if !tc.shouldFail && err != nil { - t.Errorf("test case should not fail, but err != nil: %v", err) - } - eq := true - for k, v := range attribs { - if tc.attribs[k] != v { - eq = false - } - } - if !eq { - t.Errorf("expecting attribs %#v, but got %#v", tc.attribs, attribs) - } - } -} - func TestSaveVolumeData(t *testing.T) { plug, tmpDir := newTestPlugin(t) defer os.RemoveAll(tmpDir) diff --git a/pkg/volume/csi/csi_plugin.go b/pkg/volume/csi/csi_plugin.go index b258d0b44e9..0b9b25241ee 100644 --- a/pkg/volume/csi/csi_plugin.go +++ b/pkg/volume/csi/csi_plugin.go @@ -31,8 +31,7 @@ import ( ) const ( - csiPluginName = "kubernetes.io/csi" - csiVolAttribsAnnotationKey = "csi.volume.kubernetes.io/volume-attributes" + csiPluginName = "kubernetes.io/csi" // TODO (vladimirvivien) implement a more dynamic way to discover // the unix domain socket path for each installed csi driver. diff --git a/staging/src/k8s.io/api/core/v1/types.go b/staging/src/k8s.io/api/core/v1/types.go index 43cc222a378..8d33f9c97e6 100644 --- a/staging/src/k8s.io/api/core/v1/types.go +++ b/staging/src/k8s.io/api/core/v1/types.go @@ -1748,6 +1748,10 @@ type CSIPersistentVolumeSource struct { // Ex. "ext4", "xfs", "ntfs". Implicitly inferred to be "ext4" if unspecified. // +optional FSType string `json:"fsType,omitempty" protobuf:"bytes,4,opt,name=fsType"` + + // Attributes of the volume to publish. + // +optional + VolumeAttributes map[string]string `json:"volumeAttributes,omitempty" protobuf:"bytes,5,rep,name=volumeAttributes"` } // ContainerPort represents a network port in a single container.