From 6837ad99071e3ea6bb4aa314ddb25972dc1bbfd2 Mon Sep 17 00:00:00 2001 From: Jan Safranek Date: Wed, 14 Mar 2018 14:53:07 +0100 Subject: [PATCH] Use attributes field instead of annotations. --- pkg/connection/util.go | 12 +++--------- pkg/controller/csi_handler_test.go | 18 +++--------------- 2 files changed, 6 insertions(+), 24 deletions(-) diff --git a/pkg/connection/util.go b/pkg/connection/util.go index 37fa45914..a0d89be4b 100644 --- a/pkg/connection/util.go +++ b/pkg/connection/util.go @@ -105,14 +105,8 @@ func GetVolumeHandle(pv *v1.PersistentVolume) (string, bool, error) { } func GetVolumeAttributes(pv *v1.PersistentVolume) (map[string]string, error) { - ann, ok := pv.Annotations[csiVolAttribsAnnotationKey] - if !ok { - return nil, nil - } - attribs := map[string]string{} - if err := json.Unmarshal([]byte(ann), &attribs); err != nil { - return nil, fmt.Errorf("error parsing annotation %s on PV %q: %s", csiVolAttribsAnnotationKey, pv.Name, err) + if pv.Spec.PersistentVolumeSource.CSI == nil { + return nil, fmt.Errorf("persistent volume does not contain CSI volume source") } - - return attribs, nil + return pv.Spec.PersistentVolumeSource.CSI.VolumeAttributes, nil } diff --git a/pkg/controller/csi_handler_test.go b/pkg/controller/csi_handler_test.go index 3645f5fef..d5b86f22d 100644 --- a/pkg/controller/csi_handler_test.go +++ b/pkg/controller/csi_handler_test.go @@ -85,11 +85,8 @@ func pvDeleted(pv *v1.PersistentVolume) *v1.PersistentVolume { return pv } -func pvWithAttributes(pv *v1.PersistentVolume, json string) *v1.PersistentVolume { - if pv.Annotations == nil { - pv.Annotations = map[string]string{} - } - pv.Annotations["csi.volume.kubernetes.io/volume-attributes"] = json +func pvWithAttributes(pv *v1.PersistentVolume, attributes map[string]string) *v1.PersistentVolume { + pv.Spec.PersistentVolumeSource.CSI.VolumeAttributes = attributes return pv } @@ -154,7 +151,7 @@ func TestCSIHandler(t *testing.T) { }, { name: "VolumeAttachment with attributes -> successful attachment", - initialObjects: []runtime.Object{pvWithAttributes(pvWithFinalizer(), "{\"foo\":\"bar\"}"), node()}, + initialObjects: []runtime.Object{pvWithAttributes(pvWithFinalizer(), map[string]string{"foo": "bar"}), node()}, updatedVA: va(false, ""), expectedActions: []core.Action{ // Finalizer is saved first @@ -165,15 +162,6 @@ func TestCSIHandler(t *testing.T) { {"attach", testVolumeHandle, testNodeID, map[string]string{"foo": "bar"}, success, notDetached, noMetadata}, }, }, - { - name: "Error parsing attributes -> error", - initialObjects: []runtime.Object{pvWithAttributes(pvWithFinalizer(), "{\"foo\":\"bar\""), node()}, - updatedVA: va(false, ""), - expectedActions: []core.Action{ - // Error is saved - core.NewUpdateAction(vaGroupResourceVersion, metav1.NamespaceNone, vaWithAttachError(va(false, ""), "error parsing annotation csi.volume.kubernetes.io/volume-attributes on PV \"pv1\": unexpected end of JSON input")), - }, - }, { name: "VolumeAttachment updated -> PV finalizer is added", initialObjects: []runtime.Object{pv(), node()},