Skip to content
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

Closed
wants to merge 4 commits into from

Conversation

areller
Copy link

@areller areller commented Jun 12, 2022

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,

  1. Those kind of changes aren't affected by rollback (i.e. if you rollback a PVC resize, it won't actually resize back)
  2. If the PVC patch fails during statefulset reconciliation (e.g. the user tries to decrease the PVC size and the storage driver doesn't support that), all other changes to the statefulset are blocked from being reconciled, until the user addresses the other (e.g. increase the PVC size back up in the statefulset template)

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.:


@k8s-ci-robot
Copy link
Contributor

@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.

@k8s-ci-robot k8s-ci-robot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/needs-kind Indicates a PR lacks a `kind/foo` label and requires one. do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Jun 12, 2022
@k8s-ci-robot
Copy link
Contributor

@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 triage/accepted label and provide further guidance.

The triage/accepted label can be added by org members by writing /triage accepted in a comment.

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.

@k8s-ci-robot
Copy link
Contributor

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 /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

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.

@k8s-ci-robot k8s-ci-robot added needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. do-not-merge/contains-merge-commits Indicates a PR which contains merge commits. labels Jun 12, 2022
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: areller
To complete the pull request process, please assign liggitt after the PR has been reviewed.
You can assign the PR to them by writing /assign @liggitt in a comment when ready.

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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the sig/apps Categorizes an issue or PR as relevant to SIG Apps. label Jun 12, 2022
@k8s-ci-robot k8s-ci-robot added sig/auth Categorizes an issue or PR as relevant to SIG Auth. and removed do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Jun 12, 2022
@k8s-ci-robot
Copy link
Contributor

@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.

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jul 15, 2022
Comment on lines +621 to +626
resizing := false
if pvcActual.Spec.Resources.Requests.Storage().Equal(*pvc.Spec.Resources.Requests.Storage()) {
continue
} else {
resizing = true
}
Copy link
Contributor

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
}

Comment on lines +630 to +639
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)
}
Copy link
Contributor

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)

}

Copy link
Contributor

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())
Copy link
Contributor

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)

@areller
Copy link
Author

areller commented Sep 13, 2022

Thank you @jaypipes. these are good suggestions
I'm waiting for kubernetes/enhancements#3412 to be reviewed/approved
this PR is a draft, I'm not sure yet if I'll use it or open a new one for the full implementation, but I'll keep your suggestions in mind

@@ -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 {
Copy link
Contributor

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))
Copy link
Contributor

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

Comment on lines +630 to +639
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)
}
Copy link
Contributor

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
}

Copy link
Contributor

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)
Copy link
Contributor

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
Copy link
Contributor

@yuchengwu yuchengwu Oct 10, 2022

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 ?

@yuchengwu
Copy link
Contributor

Shall we respect the .spec.updateStrategy when resizing

@dims
Copy link
Member

dims commented Dec 12, 2022

If you still need this PR then please rebase, if not, please close the PR

@dims
Copy link
Member

dims commented Dec 12, 2022

This PR has the label work-in-progress, please revisit to see if you still need this, please close if not

@areller areller closed this Dec 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/needs-kind Indicates a PR lacks a `kind/foo` label and requires one. do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. sig/apps Categorizes an issue or PR as relevant to SIG Apps. sig/auth Categorizes an issue or PR as relevant to SIG Auth. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

5 participants