Skip to content

Commit a8fdd3f

Browse files
committed
Fix crash during sync.
Do not use statefulset number of pods to figure out running ones for volume resizing, since the statefulset pointer could be nil. Instead, look at the actual running pods.
1 parent 52ddcd2 commit a8fdd3f

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

pkg/cluster/volumes.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,22 @@ func (c *Cluster) listPersistentVolumes() ([]*v1.PersistentVolume, error) {
5757
if err != nil {
5858
return nil, fmt.Errorf("could not list cluster's PersistentVolumeClaims: %v", err)
5959
}
60-
lastPodIndex := *c.Statefulset.Spec.Replicas - 1
60+
61+
pods, err := c.listPods()
62+
if err != nil {
63+
return nil, fmt.Errorf("could not get list of running pods for resizing persistent volumes: %v", err)
64+
}
65+
66+
lastPodIndex := len(pods) - 1
67+
6168
for _, pvc := range pvcs {
6269
lastDash := strings.LastIndex(pvc.Name, "-")
6370
if lastDash > 0 && lastDash < len(pvc.Name)-1 {
6471
pvcNumber, err := strconv.Atoi(pvc.Name[lastDash+1:])
6572
if err != nil {
6673
return nil, fmt.Errorf("could not convert last part of the persistent volume claim name %q to a number", pvc.Name)
6774
}
68-
if int32(pvcNumber) > lastPodIndex {
75+
if pvcNumber > lastPodIndex {
6976
c.logger.Debugf("skipping persistent volume %q corresponding to a non-running pods", pvc.Name)
7077
continue
7178
}
@@ -93,6 +100,7 @@ func (c *Cluster) resizeVolumes(newVolume spec.Volume, resizers []volumes.Volume
93100
if err != nil {
94101
return fmt.Errorf("could not list persistent volumes: %v", err)
95102
}
103+
96104
for _, pv := range pvs {
97105
volumeSize := quantityToGigabyte(pv.Spec.Capacity[v1.ResourceStorage])
98106
if volumeSize > newSize {

0 commit comments

Comments
 (0)