-
Notifications
You must be signed in to change notification settings - Fork 39.8k
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
statefulset persistent volume claim resize #110522
Conversation
@areller: Adding the "do-not-merge/release-note-label-needed" label because no release-note block was detected, please follow our release note process to remove it. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
@areller: This issue is currently awaiting triage. If a SIG or subproject determines this is a relevant issue, they will accept it by applying the The Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
Hi @areller. Thanks for your PR. I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: areller The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
@areller: PR needs rebase. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
resizing := false | ||
if pvcActual.Spec.Resources.Requests.Storage().Equal(*pvc.Spec.Resources.Requests.Storage()) { | ||
continue | ||
} else { | ||
resizing = true | ||
} |
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.
unless I'm mistaken, you can just shorten this to:
curSize := pvcActual.Spec.Resources.Requests.Storage()
newSize := pvc.Spec.Resources.Requests.Storage()
if curSize.Equal(*newSize) {
continue
}
if err != nil { | ||
err = fmt.Errorf("failed to resize PVC %s: %s", claimName, err) | ||
errs = append(errs, err) | ||
ssc.podControl.recordClaimEvent("resize", set, pod, pvcActual, err) | ||
continue | ||
} | ||
|
||
if resizing { | ||
ssc.podControl.recordClaimEvent("resize", set, pod, pvcActual, nil) | ||
} |
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.
You can shorten this whole block to just this:
if err != nil {
err = fmt.Errorf(("failed to resize PVC %s", claimName, err)
errs - append(errs, err)
}
ssc.podControl.recordClaimEvent("resize", set, pod, pvc, err)
}
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.
Agree, resizing
var looks like no necessary here, at this point(line 637), we can be sure that the pvc has been resized
resizing = true | ||
} | ||
|
||
patch := fmt.Sprintf(`{"spec": {"resources": {"requests": {"storage": "%s"}}}}`, pvc.Spec.Resources.Requests.Storage().String()) |
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.
If you take my suggested code above, you can do:
patch := fmt.Sprintf(`{"spec": {"resources": {"requests": {"storage": "%s"}}}}`, curSize)
Thank you @jaypipes. these are good suggestions |
@@ -592,6 +598,51 @@ func (ssc *defaultStatefulSetControl) updateStatefulSet( | |||
return &status, nil | |||
} | |||
|
|||
func (ssc *defaultStatefulSetControl) resizePVCs(set *apps.StatefulSet, updateRevision *apps.ControllerRevision, pods []*v1.Pod) error { |
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.
If updateRevision
is not used in this block, it's better not to pass in as a function argument
} | ||
|
||
patch := fmt.Sprintf(`{"spec": {"resources": {"requests": {"storage": "%s"}}}}`, pvc.Spec.Resources.Requests.Storage().String()) | ||
err = ssc.podControl.objectMgr.PatchClaim(set.Namespace, claimName, []byte(patch)) |
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 we need an extra PatchClaim
method while there is already exists UpdateClaim
if err != nil { | ||
err = fmt.Errorf("failed to resize PVC %s: %s", claimName, err) | ||
errs = append(errs, err) | ||
ssc.podControl.recordClaimEvent("resize", set, pod, pvcActual, err) | ||
continue | ||
} | ||
|
||
if resizing { | ||
ssc.podControl.recordClaimEvent("resize", set, pod, pvcActual, nil) | ||
} |
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.
Agree, resizing
var looks like no necessary here, at this point(line 637), we can be sure that the pvc has been resized
if err != nil { | ||
return nil, err | ||
} | ||
|
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.
if this err
var is not used in other place, restrict its scope by rewriting like
if err := xxx(); err != nil {
}
@@ -301,15 +308,22 @@ func (spc *StatefulPodControl) recordPodEvent(verb string, set *apps.StatefulSet | |||
// nil the generated event will have a reason of v1.EventTypeNormal. If err is not nil the generated event will have a | |||
// reason of v1.EventTypeWarning. | |||
func (spc *StatefulPodControl) recordClaimEvent(verb string, set *apps.StatefulSet, pod *v1.Pod, claim *v1.PersistentVolumeClaim, err error) { | |||
spc.recordUnavailableClaimEvent(verb, set, pod, claim.Name, err) |
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.
Emm.. it's just werid to have an err
var as a method argument, why we need wrap this func body as recordUnavailableClaimEvent
@@ -329,6 +330,11 @@ func (ssc *defaultStatefulSetControl) updateStatefulSet( | |||
// If the ordinal could not be parsed (ord < 0), ignore the Pod. | |||
} | |||
|
|||
err = ssc.resizePVCs(set, updateRevision, replicas) | |||
if err != nil { | |||
return nil, err |
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.
not sure if ok to return nil status
, does the return value been used by the caller ?
Shall we respect the .spec.updateStrategy when resizing |
If you still need this PR then please rebase, if not, please close the PR |
This PR has the label work-in-progress, please revisit to see if you still need this, please close if not |
What type of PR is this?
/kind feature
What this PR does / why we need it:
Today when resizing a persistent volume claim that's created by a stateful set template, by modifying the size in the template, the users gets back a generic error, saying that they're only allowed to modify number of replicas or statefulset spec template.
This PR allows users to also modify the request size in a PVC template of a statefulset, and it modifies the statefulset controller to be able to reconcile request size differences (i.e. patches the PVC if the size in the template changes)
In addition,
Which issue(s) this PR fixes:
Fixes #
Special notes for your reviewer:
Does this PR introduce a user-facing change?
Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.: