-
Notifications
You must be signed in to change notification settings - Fork 336
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bugfix: PV should use capacity bytes returned by plugin, not PVC bytes #49
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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" | ||
|
@@ -289,7 +292,6 @@ func (p *csiProvisioner) Provision(options controller.VolumeOptions) (*v1.Persis | |
}, | ||
CapacityRange: &csi.CapacityRange{ | ||
RequiredBytes: int64(volSizeBytes), | ||
LimitBytes: int64(volSizeBytes), | ||
}, | ||
} | ||
rep := &csi.CreateVolumeResponse{} | ||
|
@@ -336,6 +338,28 @@ 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 { | ||
capErr := fmt.Errorf("created volume capacity %v less than requested capacity %v", respCap, volSizeBytes) | ||
delReq := &csi.DeleteVolumeRequest{ | ||
VolumeId: rep.GetVolume().GetId(), | ||
} | ||
if options.Parameters != nil { | ||
credentials, err := getCredentialsFromParameters(p.client, options.Parameters) | ||
if err != nil { | ||
return nil, err | ||
} | ||
delReq.ControllerDeleteSecrets = credentials | ||
} | ||
ctx, cancel := context.WithTimeout(context.Background(), p.timeout) | ||
defer cancel() | ||
_, err := p.csiClient.DeleteVolume(ctx, delReq) | ||
if err != nil { | ||
capErr = fmt.Errorf("%v. Cleanup of volume %s failed, volume is orphaned: %v", capErr, share, err) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
} | ||
return nil, capErr | ||
} | ||
repBytesString := fmt.Sprintf("%v", respCap) | ||
pv := &v1.PersistentVolume{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: share, | ||
|
@@ -344,7 +368,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), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should not provide this value in bytes. I checked already existing PV and it displays the value rounded up to Gigabytes. [root@kube-3 ~]# kubectl get pv -o yaml kubernetes-dynamic-pv-8ecdbbbd1e2311e8 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, sounds good. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. at least we need to validate the bytes are no less than what is claimed in the PVC. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @rootfs If number of bytes returned by the driver is less than in PVC's request, we fail, right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe we should throw an error, I will add that in |
||
}, | ||
// TODO wait for CSI VolumeSource API | ||
PersistentVolumeSource: v1.PersistentVolumeSource{ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've also removed
LimitBytes
. Rationale is that some storage plugins may have a min volume size that is larger thanRequiredBytes
and current Kubernetes behavior is to allow the greater sized volume to be created and bound to the requested PVC. This will align the behavior with existing Kubernetes behavior. Additionally, very few storage systems are able to give back a volume with the exact amount of bytes requested, it might have to round up a little (or a lot), and we should not fail in those use cases.