Skip to content

Commit

Permalink
Bugfix: PV should use capacity bytes returned by plugin, not PVC bytes
Browse files Browse the repository at this point in the history
  • Loading branch information
davidz627 committed Mar 27, 2018
1 parent 36cae78 commit fddc8b2
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions pkg/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ import (
"strings"
"time"

"k8s.io/apimachinery/pkg/api/resource"
_ "k8s.io/apimachinery/pkg/util/json"

"github.com/golang/glog"

"github.com/kubernetes-incubator/external-storage/lib/controller"
Expand Down Expand Up @@ -265,7 +268,6 @@ func (p *csiProvisioner) Provision(options controller.VolumeOptions) (*v1.Persis
},
CapacityRange: &csi.CapacityRange{
RequiredBytes: int64(volSizeBytes),
LimitBytes: int64(volSizeBytes),
},
}
secret := v1.SecretReference{}
Expand All @@ -291,6 +293,11 @@ func (p *csiProvisioner) Provision(options controller.VolumeOptions) (*v1.Persis
for k, v := range rep.Volume.Attributes {
volumeAttributes[k] = v
}
respCap := rep.GetVolume().GetCapacityBytes()
if respCap < volSizeBytes {
return nil, fmt.Errorf("created volume capacity %v less than requested capacity %v", respCap, volSizeBytes)
}
repBytesString := fmt.Sprintf("%v", respCap)
pv := &v1.PersistentVolume{
ObjectMeta: metav1.ObjectMeta{
Name: share,
Expand All @@ -299,7 +306,7 @@ func (p *csiProvisioner) Provision(options controller.VolumeOptions) (*v1.Persis
PersistentVolumeReclaimPolicy: options.PersistentVolumeReclaimPolicy,
AccessModes: options.PVC.Spec.AccessModes,
Capacity: v1.ResourceList{
v1.ResourceName(v1.ResourceStorage): options.PVC.Spec.Resources.Requests[v1.ResourceName(v1.ResourceStorage)],
v1.ResourceName(v1.ResourceStorage): resource.MustParse(repBytesString),
},
// TODO wait for CSI VolumeSource API
PersistentVolumeSource: v1.PersistentVolumeSource{
Expand Down

0 comments on commit fddc8b2

Please sign in to comment.