Add tests for not touching unchanged properties.
This commit is contained in:
parent
c671ee8d02
commit
0ceb554c07
|
|
@ -342,3 +342,123 @@ func TestMigrateGp3Support(t *testing.T) {
|
||||||
cluster.VolumeResizer = resizer
|
cluster.VolumeResizer = resizer
|
||||||
cluster.syncVolumes()
|
cluster.syncVolumes()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestManualGp2Gp3Support(t *testing.T) {
|
||||||
|
client, _ := newFakeK8sPVCclient()
|
||||||
|
clusterName := "acid-test-cluster"
|
||||||
|
namespace := "default"
|
||||||
|
|
||||||
|
// new cluster with pvc storage resize mode and configured labels
|
||||||
|
var cluster = New(
|
||||||
|
Config{
|
||||||
|
OpConfig: config.Config{
|
||||||
|
Resources: config.Resources{
|
||||||
|
ClusterLabels: map[string]string{"application": "spilo"},
|
||||||
|
ClusterNameLabel: "cluster-name",
|
||||||
|
},
|
||||||
|
StorageResizeMode: "mixed",
|
||||||
|
EnableEBSGp3Migration: false,
|
||||||
|
EnableEBSGp3MigrationMaxSize: 1000,
|
||||||
|
},
|
||||||
|
}, client, acidv1.Postgresql{}, logger, eventRecorder)
|
||||||
|
|
||||||
|
cluster.Spec.Volume.Size = "150Gi"
|
||||||
|
cluster.Spec.Volume.Iops = aws.Int64(6000)
|
||||||
|
cluster.Spec.Volume.Throughput = aws.Int64(275)
|
||||||
|
|
||||||
|
// set metadata, so that labels will get correct values
|
||||||
|
cluster.Name = clusterName
|
||||||
|
cluster.Namespace = namespace
|
||||||
|
filterLabels := cluster.labelsSet(false)
|
||||||
|
|
||||||
|
testVolumes := []testVolume{
|
||||||
|
{
|
||||||
|
size: 100,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
size: 100,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
initTestVolumesAndPods(cluster.KubeClient, namespace, clusterName, filterLabels, testVolumes)
|
||||||
|
|
||||||
|
ctrl := gomock.NewController(t)
|
||||||
|
defer ctrl.Finish()
|
||||||
|
|
||||||
|
resizer := mocks.NewMockVolumeResizer(ctrl)
|
||||||
|
|
||||||
|
resizer.EXPECT().ExtractVolumeID(gomock.Eq("aws://eu-central-1b/ebs-volume-1")).Return("ebs-volume-1", nil)
|
||||||
|
resizer.EXPECT().ExtractVolumeID(gomock.Eq("aws://eu-central-1b/ebs-volume-2")).Return("ebs-volume-2", nil)
|
||||||
|
|
||||||
|
resizer.EXPECT().DescribeVolumes(gomock.Eq([]string{"ebs-volume-1", "ebs-volume-2"})).Return(
|
||||||
|
[]volumes.VolumeProperties{
|
||||||
|
{VolumeID: "ebs-volume-1", VolumeType: "gp2", Size: 150, Iops: 3000},
|
||||||
|
{VolumeID: "ebs-volume-2", VolumeType: "gp2", Size: 150, Iops: 4000},
|
||||||
|
}, nil)
|
||||||
|
|
||||||
|
// expect only gp2 volume to be modified
|
||||||
|
resizer.EXPECT().ModifyVolume(gomock.Eq("ebs-volume-1"), gomock.Eq(aws.String("gp3")), gomock.Nil(), gomock.Eq(aws.Int64(6000)), gomock.Eq(aws.Int64(275))).Return(nil)
|
||||||
|
resizer.EXPECT().ModifyVolume(gomock.Eq("ebs-volume-2"), gomock.Eq(aws.String("gp3")), gomock.Nil(), gomock.Eq(aws.Int64(6000)), gomock.Eq(aws.Int64(275))).Return(nil)
|
||||||
|
|
||||||
|
cluster.VolumeResizer = resizer
|
||||||
|
cluster.syncVolumes()
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestDontTouchType(t *testing.T) {
|
||||||
|
client, _ := newFakeK8sPVCclient()
|
||||||
|
clusterName := "acid-test-cluster"
|
||||||
|
namespace := "default"
|
||||||
|
|
||||||
|
// new cluster with pvc storage resize mode and configured labels
|
||||||
|
var cluster = New(
|
||||||
|
Config{
|
||||||
|
OpConfig: config.Config{
|
||||||
|
Resources: config.Resources{
|
||||||
|
ClusterLabels: map[string]string{"application": "spilo"},
|
||||||
|
ClusterNameLabel: "cluster-name",
|
||||||
|
},
|
||||||
|
StorageResizeMode: "mixed",
|
||||||
|
EnableEBSGp3Migration: false,
|
||||||
|
EnableEBSGp3MigrationMaxSize: 1000,
|
||||||
|
},
|
||||||
|
}, client, acidv1.Postgresql{}, logger, eventRecorder)
|
||||||
|
|
||||||
|
cluster.Spec.Volume.Size = "177Gi"
|
||||||
|
|
||||||
|
// set metadata, so that labels will get correct values
|
||||||
|
cluster.Name = clusterName
|
||||||
|
cluster.Namespace = namespace
|
||||||
|
filterLabels := cluster.labelsSet(false)
|
||||||
|
|
||||||
|
testVolumes := []testVolume{
|
||||||
|
{
|
||||||
|
size: 150,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
size: 150,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
initTestVolumesAndPods(cluster.KubeClient, namespace, clusterName, filterLabels, testVolumes)
|
||||||
|
|
||||||
|
ctrl := gomock.NewController(t)
|
||||||
|
defer ctrl.Finish()
|
||||||
|
|
||||||
|
resizer := mocks.NewMockVolumeResizer(ctrl)
|
||||||
|
|
||||||
|
resizer.EXPECT().ExtractVolumeID(gomock.Eq("aws://eu-central-1b/ebs-volume-1")).Return("ebs-volume-1", nil)
|
||||||
|
resizer.EXPECT().ExtractVolumeID(gomock.Eq("aws://eu-central-1b/ebs-volume-2")).Return("ebs-volume-2", nil)
|
||||||
|
|
||||||
|
resizer.EXPECT().DescribeVolumes(gomock.Eq([]string{"ebs-volume-1", "ebs-volume-2"})).Return(
|
||||||
|
[]volumes.VolumeProperties{
|
||||||
|
{VolumeID: "ebs-volume-1", VolumeType: "gp2", Size: 150, Iops: 3000},
|
||||||
|
{VolumeID: "ebs-volume-2", VolumeType: "gp2", Size: 150, Iops: 4000},
|
||||||
|
}, nil)
|
||||||
|
|
||||||
|
// expect only gp2 volume to be modified
|
||||||
|
resizer.EXPECT().ModifyVolume(gomock.Eq("ebs-volume-1"), gomock.Nil(), gomock.Eq(aws.Int64(177)), gomock.Nil(), gomock.Nil()).Return(nil)
|
||||||
|
resizer.EXPECT().ModifyVolume(gomock.Eq("ebs-volume-2"), gomock.Nil(), gomock.Eq(aws.Int64(177)), gomock.Nil(), gomock.Nil()).Return(nil)
|
||||||
|
|
||||||
|
cluster.VolumeResizer = resizer
|
||||||
|
cluster.syncVolumes()
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue