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.
This commit is contained in:
Oleksii Kliukin 2018-05-18 14:42:20 +02:00
parent 52ddcd25cc
commit a8fdd3f2db
1 changed files with 10 additions and 2 deletions

View File

@ -57,7 +57,14 @@ func (c *Cluster) listPersistentVolumes() ([]*v1.PersistentVolume, error) {
if err != nil { if err != nil {
return nil, fmt.Errorf("could not list cluster's PersistentVolumeClaims: %v", err) return nil, fmt.Errorf("could not list cluster's PersistentVolumeClaims: %v", err)
} }
lastPodIndex := *c.Statefulset.Spec.Replicas - 1
pods, err := c.listPods()
if err != nil {
return nil, fmt.Errorf("could not get list of running pods for resizing persistent volumes: %v", err)
}
lastPodIndex := len(pods) - 1
for _, pvc := range pvcs { for _, pvc := range pvcs {
lastDash := strings.LastIndex(pvc.Name, "-") lastDash := strings.LastIndex(pvc.Name, "-")
if lastDash > 0 && lastDash < len(pvc.Name)-1 { if lastDash > 0 && lastDash < len(pvc.Name)-1 {
@ -65,7 +72,7 @@ func (c *Cluster) listPersistentVolumes() ([]*v1.PersistentVolume, error) {
if err != nil { if err != nil {
return nil, fmt.Errorf("could not convert last part of the persistent volume claim name %q to a number", pvc.Name) return nil, fmt.Errorf("could not convert last part of the persistent volume claim name %q to a number", pvc.Name)
} }
if int32(pvcNumber) > lastPodIndex { if pvcNumber > lastPodIndex {
c.logger.Debugf("skipping persistent volume %q corresponding to a non-running pods", pvc.Name) c.logger.Debugf("skipping persistent volume %q corresponding to a non-running pods", pvc.Name)
continue continue
} }
@ -93,6 +100,7 @@ func (c *Cluster) resizeVolumes(newVolume spec.Volume, resizers []volumes.Volume
if err != nil { if err != nil {
return fmt.Errorf("could not list persistent volumes: %v", err) return fmt.Errorf("could not list persistent volumes: %v", err)
} }
for _, pv := range pvs { for _, pv := range pvs {
volumeSize := quantityToGigabyte(pv.Spec.Capacity[v1.ResourceStorage]) volumeSize := quantityToGigabyte(pv.Spec.Capacity[v1.ResourceStorage])
if volumeSize > newSize { if volumeSize > newSize {