Merge pull request #294 from zalando-incubator/sync_volumes_before_statefulset
Fix crash during sync.
This commit is contained in:
		
						commit
						f5d61a5f46
					
				|  | @ -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 { | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue