Skip to content

Commit

Permalink
Return Capacity in Create Volume Request
Browse files Browse the repository at this point in the history
After PR [1], volume capacity needs to be returned by csi plugin
This commit returns volume capacity in create volume request

[1]kubernetes-csi/external-provisioner#76
  • Loading branch information
adisky committed Aug 17, 2018
1 parent 8765477 commit f42632e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
8 changes: 5 additions & 3 deletions pkg/csi/cinder/controllerserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ func (cs *controllerServer) CreateVolume(ctx context.Context, req *csi.CreateVol

resID := ""
resAvailability := ""
resSize := 0

if len(volumes) == 1 {
resID = volumes[0].ID
Expand All @@ -77,19 +78,20 @@ func (cs *controllerServer) CreateVolume(ctx context.Context, req *csi.CreateVol
return nil, errors.New("multiple volumes reported by Cinder with same name")
} else {
// Volume Create
resID, resAvailability, err = cloud.CreateVolume(volName, volSizeGB, volType, volAvailability, nil)
resID, resAvailability, resSize, err = cloud.CreateVolume(volName, volSizeGB, volType, volAvailability, nil)
if err != nil {
glog.V(3).Infof("Failed to CreateVolume: %v", err)
return nil, err
}

glog.V(4).Infof("Create volume %s in Availability Zone: %s", resID, resAvailability)
glog.V(4).Infof("Create volume %s in Availability Zone: %s of size %s GiB", resID, resAvailability, resSize)

}

return &csi.CreateVolumeResponse{
Volume: &csi.Volume{
Id: resID,
Id: resID,
CapacityBytes: int64(resSize * 1024 * 1024 * 1024),
Attributes: map[string]string{
"availability": resAvailability,
},
Expand Down
2 changes: 1 addition & 1 deletion pkg/csi/cinder/openstack/openstack.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
)

type IOpenStack interface {
CreateVolume(name string, size int, vtype, availability string, tags *map[string]string) (string, string, error)
CreateVolume(name string, size int, vtype, availability string, tags *map[string]string) (string, string, int, error)
DeleteVolume(volumeID string) error
AttachVolume(instanceID, volumeID string) (string, error)
WaitDiskAttached(instanceID string, volumeID string) error
Expand Down
6 changes: 3 additions & 3 deletions pkg/csi/cinder/openstack/openstack_volumes.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ type Volume struct {
}

// CreateVolume creates a volume of given size
func (os *OpenStack) CreateVolume(name string, size int, vtype, availability string, tags *map[string]string) (string, string, error) {
func (os *OpenStack) CreateVolume(name string, size int, vtype, availability string, tags *map[string]string) (string, string, int, error) {
opts := &volumes.CreateOpts{
Name: name,
Size: size,
Expand All @@ -74,10 +74,10 @@ func (os *OpenStack) CreateVolume(name string, size int, vtype, availability str

vol, err := volumes.Create(os.blockstorage, opts).Extract()
if err != nil {
return "", "", err
return "", "", 0, err
}

return vol.ID, vol.AvailabilityZone, nil
return vol.ID, vol.AvailabilityZone, vol.Size, nil
}

// GetVolumesByName is a wrapper around ListVolumes that creates a Name filter to act as a GetByName
Expand Down

0 comments on commit f42632e

Please sign in to comment.