Making VolumeID != volName as per CSI spec

This commit is contained in:
Serguei Bezverkhi
2018-01-15 20:52:28 -05:00
parent 0215b385d3
commit 8614aee8ef
4 changed files with 50 additions and 30 deletions

View File

@ -48,12 +48,20 @@ func (cs *controllerServer) CreateVolume(ctx context.Context, req *csi.CreateVol
glog.V(3).Infof("invalid create volume req: %v", req)
return nil, err
}
// Volume Name
volName := req.GetName()
if len(volName) == 0 {
volName = uuid.NewUUID().String()
volOptions, err := getRBDVolumeOptions(req.Parameters, cs.clientSet)
if err != nil {
return nil, err
}
// Generating Volume Name and Volume ID, as accoeding to CSI spec they MUST be different
volName := req.GetName()
uniqueID := uuid.NewUUID().String()
if len(volName) == 0 {
volName = volOptions.Pool + "-dynamic-pvc-" + uniqueID
}
volOptions.VolName = volName
volumeID := "csi-rbd-" + uniqueID
// Volume Size - Default is 1 GiB
volSizeBytes := int64(oneGB)
if req.GetCapacityRange() != nil {
@ -61,14 +69,10 @@ func (cs *controllerServer) CreateVolume(ctx context.Context, req *csi.CreateVol
}
volSizeGB := int(volSizeBytes / 1024 / 1024 / 1024)
volOptions, err := getRBDVolumeOptions(req.Parameters, cs.clientSet)
if err != nil {
return nil, err
}
// Check if there is already RBD image with requested name
found, _, _ := rbdStatus(volName, volOptions)
found, _, _ := rbdStatus(volOptions)
if !found {
if err := createRBDImage(volName, volSizeGB, volOptions); err != nil {
if err := createRBDImage(volOptions, volSizeGB); err != nil {
if err != nil {
glog.Warningf("failed to create volume: %v", err)
return nil, err
@ -78,13 +82,13 @@ func (cs *controllerServer) CreateVolume(ctx context.Context, req *csi.CreateVol
}
// Storing volInfo into a persistent file, will need info to delete rbd image
// in ControllerUnpublishVolume
if err := persistVolInfo(volName, path.Join(PluginFolder, "controller"), volOptions); err != nil {
if err := persistVolInfo(volumeID, path.Join(PluginFolder, "controller"), volOptions); err != nil {
glog.Warningf("rbd: failed to store volInfo with error: %v", err)
}
return &csi.CreateVolumeResponse{
VolumeInfo: &csi.VolumeInfo{
Id: volName,
Id: volumeID,
CapacityBytes: uint64(volSizeBytes),
Attributes: req.GetParameters(),
},
@ -112,12 +116,13 @@ func (cs *controllerServer) ValidateVolumeCapabilities(ctx context.Context, req
func (cs *controllerServer) ControllerUnpublishVolume(ctx context.Context, req *csi.ControllerUnpublishVolumeRequest) (*csi.ControllerUnpublishVolumeResponse, error) {
// For now the image get unconditionally deleted, but here retention policy can be checked
volName := req.GetVolumeId()
volumeID := req.GetVolumeId()
volOptions := &rbdVolumeOptions{}
if err := loadVolInfo(volName, path.Join(PluginFolder, "controller"), volOptions); err != nil {
if err := loadVolInfo(volumeID, path.Join(PluginFolder, "controller"), volOptions); err != nil {
return nil, err
}
volName := volOptions.VolName
// Recover rbd secret key value, for now by k8s specific call
id := volOptions.AdminID
secretName := volOptions.AdminSecretName
@ -134,12 +139,12 @@ func (cs *controllerServer) ControllerUnpublishVolume(ctx context.Context, req *
// Deleting rbd image
glog.V(4).Infof("deleting volume %s", volName)
if err := deleteRBDImage(volName, volOptions); err != nil {
if err := deleteRBDImage(volOptions); err != nil {
glog.V(3).Infof("failed to delete rbd image: %s/%s with error: %v", volOptions.Pool, volName, err)
return nil, err
}
// Removing persistent storage file for the unmapped volume
if err := deleteVolInfo(volName, path.Join(PluginFolder, "controller")); err != nil {
if err := deleteVolInfo(volumeID, path.Join(PluginFolder, "controller")); err != nil {
return nil, err
}