-
Notifications
You must be signed in to change notification settings - Fork 38.9k
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
Add support to resize Portworx volume #62308
Conversation
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.
LGTM
pkg/volume/portworx/portworx.go
Outdated
spec *volume.Spec, | ||
newSize resource.Quantity, | ||
oldSize resource.Quantity) (resource.Quantity, error) { | ||
glog.Infof("Expanding: %s from %v to %v", spec.Name(), oldSize, newSize) |
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.
using level 4 log?
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.
Switched to level 4 logging.
pkg/volume/portworx/portworx.go
Outdated
return oldSize, err | ||
} | ||
|
||
glog.Infof("Successfully resized %s to %v", spec.Name(), newSize) |
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.
Ditto.
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.
Fixed in latest incremental
pkg/volume/portworx/portworx_util.go
Outdated
@@ -38,6 +41,7 @@ const ( | |||
pvcNamespaceLabel = "namespace" | |||
pxServiceName = "portworx-service" | |||
pxDriverName = "pxd-sched" | |||
oneGig = 1024 * 1024 * 1024 |
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.
use oneGi
instead?
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.
Removed this and now using existing functions in https://github.com/kubernetes/kubernetes/blob/master/pkg/volume/util/util.go
return fmt.Errorf("failed to inspect Portworx volume: %s. Found: %d volumes", spec.Name(), len(vols)) | ||
} | ||
|
||
vol := vols[0] |
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.
only the first volume will be resized?
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.
Yes, because we inspected one volume above. So only one volume is expected is the response. Line 200 also explicitly makes that check. ResizeVolume
is a per-volume call.
pkg/volume/portworx/portworx_util.go
Outdated
|
||
func capacityToGB(capacity resource.Quantity) int { | ||
return int(volutil.RoundUpSize(capacity.Value(), oneGig)) | ||
} |
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.
there is already https://github.com/kubernetes/kubernetes/blob/master/pkg/volume/util/util.go#L372
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.
Thanks. Fixed.
/ok-to-test |
09925b3
to
5487761
Compare
@harsh-px Would you please rebase your commits. Thanks. I'll lgtm. |
cda50e9
to
5e57210
Compare
@dixudx done. |
pkg/volume/portworx/portworx_util.go
Outdated
@@ -56,7 +59,7 @@ func (util *PortworxVolumeUtil) CreateVolume(p *portworxVolumeProvisioner) (stri | |||
|
|||
capacity := p.options.PVC.Spec.Resources.Requests[v1.ResourceName(v1.ResourceStorage)] | |||
// Portworx Volumes are specified in GB |
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.
Why does this comment says Portworx volumes are specified in GB
and then code proceeds to use GiB
?
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.
Fixed in latest incremental.
newSize resource.Quantity, | ||
oldSize resource.Quantity) (resource.Quantity, error) { | ||
glog.V(4).Infof("Expanding: %s from %v to %v", spec.Name(), oldSize, newSize) | ||
err := plugin.util.ResizeVolume(spec, newSize, plugin.host) |
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.
This function should be idempotent. If portworx volume already has the user requested size, ExpandVolumeDevice
should be a no-op
followed by a successful response. Please see other volume plugins as an example.
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.
@gnufied the Portworx driver implementation on the server side is already idempotent. So invoking it multiple times will have the same effect as it internally checks if the volume has the size. So I don't need any logic here on the client side. Best to keep it simple.
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.
There is another reason for keeping this idempotent in Kubernetes rather than in Portworx server side. Lets say:
- User created a PVC of 5GB size and is matched with a PV which is of 7GiB size.
- Later on User edits the PVC to be 6GiB. Kuberenetes may still call
ExpandVolumeDevice
even though underlying PV already matches the requested size. - What happens in portworx server side now? Will it shrink existing 7GiB disk to 6GiB or will it return an error?
Obviously shrinking will be bad. We never shrink volumes in Kubernetes. Returning an error will be bad too. Even if theoretically Portworx in Server side does the "right thing" and returns successful response - there is no guarantee that the behaviour will remain the same always. That is why - it is important to not rely on Portworx behaviour in server side.
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.
@gnufied good point ! Updated the review with check to see if existing volume is already equal or greater than requested size.
pkg/volume/portworx/portworx_util.go
Outdated
|
||
vol := vols[0] | ||
vol.Spec.Size = uint64(volutil.RoundUpToGiB(newSize)) | ||
return driver.Set(spec.Name(), vol.Locator, vol.Spec) |
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.
Is there a way to get size after resizing? The reason most volume plugins returns "new size" from this function is because - after alignment to GB or GiB boundaries, actual volume size may be different than user requested size(but as long as it is more than user requested size we are fine)
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.
Done. Added check in the latest incremental if the size actually got updated.
Nearly there. Please make sure plugin uses one unit throughout the code (GB or GiB). Also - ideally |
fa522a9
to
7753d1a
Compare
pkg/volume/portworx/portworx_util.go
Outdated
} | ||
|
||
updatedVol := vols[0] | ||
if updatedVol.Spec.Size != vol.Spec.Size { |
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 don't think we need to check exact equality, may be just updatedVol.Size >= vol.Size
should be sufficient?
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.
Done. Now I'm allowing the updated volume to be greater than the requested size.
/retest |
@harsh-px please squash the commits. |
Closes kubernetes#62305 Signed-off-by: Harsh Desai <harsh@portworx.com> update comment and variable references to GiB Signed-off-by: Harsh Desai <harsh@portworx.com> explicitly check volume size after resize and fix size volume spec Signed-off-by: Harsh Desai <harsh@portworx.com> If Portworx volume is already greater than new size, skip resize Signed-off-by: Harsh Desai <harsh@portworx.com> Allow updated volume to be greater than requested size Signed-off-by: Harsh Desai <harsh@portworx.com>
b587a5c
to
adc7185
Compare
@gnufied Squashed the changes. It seems the tests for failing due to an automation issue.
I'm going to retry these. /retest |
/retest |
/approve approving the admission changes. |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: deads2k, dixudx, gnufied, harsh-px The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Automatic merge from submit-queue (batch tested with PRs 59592, 62308, 62523, 62635, 62243). If you want to cherry-pick this change to another branch, please follow the instructions here. |
Signed-off-by: Harsh Desai harsh@portworx.com
What this PR does / why we need it:
This PR adds support in the Portworx volume plugin to expand an existing PVC.
Which issue(s) this PR fixes:
Closes #62305
Release note: