let executeEBSMigration operator on cluster.EBSVolumes
This commit is contained in:
		
							parent
							
								
									a8bfeb7874
								
							
						
					
					
						commit
						de1ce17b36
					
				|  | @ -69,7 +69,7 @@ func (c *Cluster) Sync(newSpec *acidv1.Postgresql) error { | |||
| 		return err | ||||
| 	} | ||||
| 
 | ||||
| 	if c.OpConfig.EnableEBSGp3Migration { | ||||
| 	if c.OpConfig.EnableEBSGp3Migration && len(c.EBSVolumes) > 0 { | ||||
| 		err = c.executeEBSMigration() | ||||
| 		if nil != err { | ||||
| 			return err | ||||
|  |  | |||
|  | @ -458,20 +458,13 @@ func (c *Cluster) executeEBSMigration() error { | |||
| 	if err != nil { | ||||
| 		return fmt.Errorf("could not list persistent volumes: %v", err) | ||||
| 	} | ||||
| 	if len(pvs) == 0 { | ||||
| 		c.logger.Warningf("no persistent volumes found - skipping EBS migration") | ||||
| 		return nil | ||||
| 	} | ||||
| 	c.logger.Debugf("found %d volumes, size of known volumes %d", len(pvs), len(c.EBSVolumes)) | ||||
| 
 | ||||
| 	volumeIds := []string{} | ||||
| 	var volumeID string | ||||
| 	for _, pv := range pvs { | ||||
| 		volumeID, err = c.VolumeResizer.ExtractVolumeID(pv.Spec.AWSElasticBlockStore.VolumeID) | ||||
| 		if err != nil { | ||||
| 			continue | ||||
| 		} | ||||
| 
 | ||||
| 		volumeIds = append(volumeIds, volumeID) | ||||
| 	} | ||||
| 
 | ||||
| 	if len(volumeIds) == len(c.EBSVolumes) { | ||||
| 	if len(pvs) == len(c.EBSVolumes) { | ||||
| 		hasGp2 := false | ||||
| 		for _, v := range c.EBSVolumes { | ||||
| 			if v.VolumeType == "gp2" { | ||||
|  | @ -485,15 +478,10 @@ func (c *Cluster) executeEBSMigration() error { | |||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	awsVolumes, err := c.VolumeResizer.DescribeVolumes(volumeIds) | ||||
| 	if nil != err { | ||||
| 		return err | ||||
| 	} | ||||
| 
 | ||||
| 	var i3000 int64 = 3000 | ||||
| 	var i125 int64 = 125 | ||||
| 
 | ||||
| 	for _, volume := range awsVolumes { | ||||
| 	for _, volume := range c.EBSVolumes { | ||||
| 		if volume.VolumeType == "gp2" && volume.Size < c.OpConfig.EnableEBSGp3MigrationMaxSize { | ||||
| 			c.logger.Infof("modifying EBS volume %s to type gp3 migration (%d)", volume.VolumeID, volume.Size) | ||||
| 			err = c.VolumeResizer.ModifyVolume(volume.VolumeID, aws.String("gp3"), &volume.Size, &i3000, &i125) | ||||
|  |  | |||
|  | @ -224,7 +224,10 @@ func TestMigrateEBS(t *testing.T) { | |||
| 	resizer.EXPECT().ModifyVolume(gomock.Eq("ebs-volume-1"), gomock.Eq(aws.String("gp3")), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil) | ||||
| 
 | ||||
| 	cluster.VolumeResizer = resizer | ||||
| 	cluster.executeEBSMigration() | ||||
| 	err := cluster.populateVolumeMetaData() | ||||
| 	assert.NoError(t, err) | ||||
| 	err = cluster.executeEBSMigration() | ||||
| 	assert.NoError(t, err) | ||||
| } | ||||
| 
 | ||||
| func initTestVolumesAndPods(client k8sutil.KubernetesClient, namespace, clustername string, labels labels.Set, volumes []testVolume) { | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue