Skip to content

Commit f42632e

Browse files
author
adisky
committed
Return Capacity in Create Volume Request
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
1 parent 8765477 commit f42632e

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

pkg/csi/cinder/controllerserver.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ func (cs *controllerServer) CreateVolume(ctx context.Context, req *csi.CreateVol
6868

6969
resID := ""
7070
resAvailability := ""
71+
resSize := 0
7172

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

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

8889
}
8990

9091
return &csi.CreateVolumeResponse{
9192
Volume: &csi.Volume{
92-
Id: resID,
93+
Id: resID,
94+
CapacityBytes: int64(resSize * 1024 * 1024 * 1024),
9395
Attributes: map[string]string{
9496
"availability": resAvailability,
9597
},

pkg/csi/cinder/openstack/openstack.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import (
2727
)
2828

2929
type IOpenStack interface {
30-
CreateVolume(name string, size int, vtype, availability string, tags *map[string]string) (string, string, error)
30+
CreateVolume(name string, size int, vtype, availability string, tags *map[string]string) (string, string, int, error)
3131
DeleteVolume(volumeID string) error
3232
AttachVolume(instanceID, volumeID string) (string, error)
3333
WaitDiskAttached(instanceID string, volumeID string) error

pkg/csi/cinder/openstack/openstack_volumes.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ type Volume struct {
6161
}
6262

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

7575
vol, err := volumes.Create(os.blockstorage, opts).Extract()
7676
if err != nil {
77-
return "", "", err
77+
return "", "", 0, err
7878
}
7979

80-
return vol.ID, vol.AvailabilityZone, nil
80+
return vol.ID, vol.AvailabilityZone, vol.Size, nil
8181
}
8282

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

0 commit comments

Comments
 (0)