Skip to content

Commit

Permalink
csi: use publish_info for storing and accessing the volume name
Browse files Browse the repository at this point in the history
This does away with the need for the nodes to call the API to fetch the
volume name, when it can be stored in the Status.AttachmentMetadata of
the VolumeAttachment object.
  • Loading branch information
Joonas Bergius committed Nov 9, 2018
1 parent 277a3fd commit dabbe9e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 12 deletions.
20 changes: 17 additions & 3 deletions driver/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ const (
)

const (
PublishInfoVolumeName = "com.digitalocean.csi/volume-name"

defaultVolumeSizeInGB = 16 * GB

createdByDO = "Created by DigitalOcean CSI driver"
Expand Down Expand Up @@ -253,7 +255,11 @@ func (d *Driver) ControllerPublishVolume(ctx context.Context, req *csi.Controlle
attachedID = id
if id == dropletID {
ll.Info("volume is already attached")
return &csi.ControllerPublishVolumeResponse{}, nil
return &csi.ControllerPublishVolumeResponse{
PublishInfo: map[string]string{
PublishInfoVolumeName: vol.Name,
},
}, nil
}
}

Expand All @@ -273,7 +279,11 @@ func (d *Driver) ControllerPublishVolume(ctx context.Context, req *csi.Controlle
"error": err,
"resp": resp,
}).Warn("assuming volume is attached already")
return &csi.ControllerPublishVolumeResponse{}, nil
return &csi.ControllerPublishVolumeResponse{
PublishInfo: map[string]string{
PublishInfoVolumeName: vol.Name,
},
}, nil
}

if strings.Contains(err.Error(), "Droplet already has a pending event") {
Expand All @@ -297,7 +307,11 @@ func (d *Driver) ControllerPublishVolume(ctx context.Context, req *csi.Controlle
}

ll.Info("volume is attached")
return &csi.ControllerPublishVolumeResponse{}, nil
return &csi.ControllerPublishVolumeResponse{
PublishInfo: map[string]string{
PublishInfoVolumeName: vol.Name,
},
}, nil
}

// ControllerUnpublishVolume deattaches the given volume from the node
Expand Down
16 changes: 7 additions & 9 deletions driver/node.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit dabbe9e

Please sign in to comment.