This is an automated email from the ASF dual-hosted git repository.

adheipsingh pushed a commit to branch 1.3.0-pvc-expansion-fix
in repository https://gitbox.apache.org/repos/asf/druid-operator.git

commit 4a11c07d1498165070ab0bf028aaec1eb1dc395a
Author: AdheipSingh <[email protected]>
AuthorDate: Fri Sep 26 19:48:39 2025 +0530

    fix pvc volume expansion issue
---
 controllers/druid/volume_expansion.go | 30 ++++++++++++++++++++++++------
 1 file changed, 24 insertions(+), 6 deletions(-)

diff --git a/controllers/druid/volume_expansion.go 
b/controllers/druid/volume_expansion.go
index 3ae6ee0..d2c888d 100644
--- a/controllers/druid/volume_expansion.go
+++ b/controllers/druid/volume_expansion.go
@@ -4,6 +4,7 @@ import (
        "context"
        "errors"
        "fmt"
+       "strings"
 
        "github.com/datainfrahq/druid-operator/apis/druid/v1alpha1"
        appsv1 "k8s.io/api/apps/v1"
@@ -162,17 +163,34 @@ func scalePVCForSts(ctx context.Context, sdk 
client.Client, nodeSpec *v1alpha1.D
 
                }
 
+               // Get the volume claim template name for this index
+               volumeClaimTemplateName := nodeSpec.VolumeClaimTemplates[i].Name
+
                // In case size dont match, patch the pvc with the desiredsize 
from druid CR
-               for p := range pvcSize {
-                       pSize, _ := pvcSize[p].AsInt64()
+               for p := range pvcList {
+                       pvcObj := pvcList[p].(*v1.PersistentVolumeClaim)
+
+                       // Extract the volume template name from PVC name
+                       // PVC name format: 
{volumeClaimTemplateName}-{statefulSetName}-{ordinal}
+                       stsName := sts.(*appsv1.StatefulSet).Name
+                       expectedPrefix := fmt.Sprintf("%s-%s-", 
volumeClaimTemplateName, stsName)
+
+                       // Skip if this PVC doesn't match the current volume 
claim template
+                       if !strings.HasPrefix(pvcObj.Name, expectedPrefix) {
+                               continue
+                       }
+
+                       pvcQuantity := 
pvcObj.Spec.Resources.Requests[v1.ResourceStorage]
+                       pSize, _ := pvcQuantity.AsInt64()
+
                        if desiredSize != pSize {
                                // use deepcopy
-                               patch := 
client.MergeFrom(pvcList[p].(*v1.PersistentVolumeClaim).DeepCopy())
-                               
pvcList[p].(*v1.PersistentVolumeClaim).Spec.Resources.Requests[v1.ResourceStorage]
 = desVolumeClaimTemplateSize[i]
-                               if err := writers.Patch(ctx, sdk, drd, 
pvcList[p].(*v1.PersistentVolumeClaim), false, patch, emitEvent); err != nil {
+                               patch := client.MergeFrom(pvcObj.DeepCopy())
+                               
pvcObj.Spec.Resources.Requests[v1.ResourceStorage] = 
desVolumeClaimTemplateSize[i]
+                               if err := writers.Patch(ctx, sdk, drd, pvcObj, 
false, patch, emitEvent); err != nil {
                                        return err
                                } else {
-                                       msg := fmt.Sprintf("[PVC:%s] 
successfully Patched with [Size:%s]", 
pvcList[p].(*v1.PersistentVolumeClaim).Name, 
desVolumeClaimTemplateSize[i].String())
+                                       msg := fmt.Sprintf("[PVC:%s] 
successfully Patched with [Size:%s]", pvcObj.Name, 
desVolumeClaimTemplateSize[i].String())
                                        logger.Info(msg, "name", drd.Name, 
"namespace", drd.Namespace)
                                }
                        }


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to