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 c336699
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion 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 @@ -291,6 +294,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 +307,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 c336699

Please sign in to comment.