Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use attributes field instead of annotations. #36

Merged
merged 1 commit into from
Mar 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 3 additions & 9 deletions pkg/connection/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
18 changes: 3 additions & 15 deletions pkg/controller/csi_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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
Expand All @@ -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()},
Expand Down