-
Notifications
You must be signed in to change notification settings - Fork 32
HELP-85556 - fix PVC scaling ignoring namespaces #651
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
Open
MaciejKaras
wants to merge
8
commits into
master
Choose a base branch
from
maciejk/HELP-85556
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+91
−34
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
e24b400
HELP-85556 - fix PVC scaling ignoring namespaces
MaciejKaras e708a29
Update tests
MaciejKaras 883ef4b
Update tests
MaciejKaras 9a97a0e
Added changelog
MaciejKaras 57f8d69
Review fixes + updated `hasFinishedResizing` function
MaciejKaras 3a7e189
Review fixes
MaciejKaras fa666b1
Update changelog/20251217_fix_persistent_volume_claim_resize.md
MaciejKaras 4dbb932
Merge branch 'master' into maciejk/HELP-85556
MaciejKaras File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| --- | ||
| kind: fix | ||
| date: 2025-12-17 | ||
| --- | ||
|
|
||
| * **Persistent Volume Claim resize fix**: Fixed an issue where the Operator ignored namespaces when listing PVCs, causing conflicts with resizing PVCs of the same name. Now, PVCs are filtered by both name and namespace for accurate resizing. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -123,25 +123,26 @@ func HandlePVCResize(ctx context.Context, memberClient kubernetesClient.Client, | |
| // and we are not in the middle of a resize (that means pvcPhase is pvc.PhaseNoAction) for this statefulset. | ||
| // This means we want to start one | ||
| if increaseStorageOfAtLeastOnePVC { | ||
| err := enterprisests.AddPVCAnnotation(desiredSts) | ||
| if err != nil { | ||
| if err := enterprisests.AddPVCAnnotation(desiredSts); err != nil { | ||
| return workflow.Failed(xerrors.Errorf("can't add pvc annotation, err: %s", err)) | ||
| } | ||
|
|
||
| log.Infof("Detected PVC size expansion; patching all pvcs and increasing the size for sts: %s", desiredSts.Name) | ||
| if err := resizePVCsStorage(memberClient, desiredSts); err != nil { | ||
| if err := resizePVCsStorage(ctx, memberClient, desiredSts, log); err != nil { | ||
| return workflow.Failed(xerrors.Errorf("can't resize pvc, err: %s", err)) | ||
| } | ||
|
|
||
| finishedResizing, err := hasFinishedResizing(ctx, memberClient, desiredSts) | ||
| if err != nil { | ||
| return workflow.Failed(err) | ||
| } | ||
|
|
||
| if finishedResizing { | ||
| log.Info("PVCs finished resizing") | ||
| log.Info("Deleting StatefulSet and orphan pods") | ||
| // Cascade delete the StatefulSet | ||
| deletePolicy := metav1.DeletePropagationOrphan | ||
| if err := memberClient.Delete(context.TODO(), desiredSts, client.PropagationPolicy(deletePolicy)); err != nil && !apiErrors.IsNotFound(err) { | ||
| if err := memberClient.Delete(ctx, desiredSts, client.PropagationPolicy(deletePolicy)); err != nil && !apiErrors.IsNotFound(err) { | ||
|
Collaborator
Author
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 workflow.Failed(xerrors.Errorf("error deleting sts, err: %s", err)) | ||
| } | ||
|
|
||
|
|
@@ -182,7 +183,7 @@ func checkStatefulsetIsDeleted(ctx context.Context, memberClient kubernetesClien | |
|
|
||
| func hasFinishedResizing(ctx context.Context, memberClient kubernetesClient.Client, desiredSts *appsv1.StatefulSet) (bool, error) { | ||
| pvcList := corev1.PersistentVolumeClaimList{} | ||
| if err := memberClient.List(ctx, &pvcList); err != nil { | ||
| if err := memberClient.List(ctx, &pvcList, client.InNamespace(desiredSts.Namespace)); err != nil { | ||
| return false, err | ||
| } | ||
|
|
||
|
|
@@ -198,20 +199,23 @@ func hasFinishedResizing(ctx context.Context, memberClient kubernetesClient.Clie | |
| } | ||
|
|
||
| // resizePVCsStorage takes the sts we want to create and update all matching pvc with the new storage | ||
| func resizePVCsStorage(client kubernetesClient.Client, statefulSetToCreate *appsv1.StatefulSet) error { | ||
| pvcList := corev1.PersistentVolumeClaimList{} | ||
|
|
||
| func resizePVCsStorage(ctx context.Context, kubeClient kubernetesClient.Client, statefulSetToCreate *appsv1.StatefulSet, log *zap.SugaredLogger) error { | ||
| // this is to ensure that requests to a potentially not allowed resource is not blocking the operator until the end | ||
| ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute) | ||
| ctx, cancel := context.WithTimeout(ctx, 2*time.Minute) | ||
|
Collaborator
Author
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. now properly creating a context with timeout from parent context |
||
| defer cancel() | ||
|
|
||
| if err := client.List(ctx, &pvcList); err != nil { | ||
| pvcList := corev1.PersistentVolumeClaimList{} | ||
| if err := kubeClient.List(ctx, &pvcList, client.InNamespace(statefulSetToCreate.Namespace)); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| for _, existingPVC := range pvcList.Items { | ||
| if template, _ := getMatchingPVCTemplateFromSTS(statefulSetToCreate, &existingPVC); template != nil { | ||
| existingPVC.Spec.Resources.Requests[corev1.ResourceStorage] = *template.Spec.Resources.Requests.Storage() | ||
| if err := client.Update(ctx, &existingPVC); err != nil { | ||
| currentSize := existingPVC.Spec.Resources.Requests[corev1.ResourceStorage] | ||
| targetSize := *template.Spec.Resources.Requests.Storage() | ||
| log.Infof("Resizing PVC %s/%s from %s to %s", existingPVC.GetNamespace(), existingPVC.GetName(), currentSize.String(), targetSize.String()) | ||
| existingPVC.Spec.Resources.Requests[corev1.ResourceStorage] = targetSize | ||
| if err := kubeClient.Update(ctx, &existingPVC); err != nil { | ||
| return err | ||
| } | ||
| } | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
resizePVCsStorage()function did not receive parent context, this is fixed now