change volume specs to int32 and define max iops and throughput values (#3139)

* change int64 volume specs to int32 like in used AWS lib
* upper iops and throughput limits
* minor refactoring in ebs.go
This commit is contained in:
Felix Kunde
2026-07-27 16:32:22 +02:00
committed by GitHub
parent 56a8f1d90b
commit d268c589c2
14 changed files with 67 additions and 73 deletions
+10 -10
View File
@@ -81,24 +81,24 @@ func (c *Cluster) syncUnderlyingEBSVolume() error {
errors := make([]string, 0)
for _, volume := range c.EBSVolumes {
var modifyIops *int64
var modifyThroughput *int64
var modifySize *int64
var modifyIops *int32
var modifyThroughput *int32
var modifySize *int32
var modifyType *string
if targetValue.Iops != nil && *targetValue.Iops >= int64(3000) {
if volume.Iops != int64(*targetValue.Iops) {
if targetValue.Iops != nil && *targetValue.Iops >= int32(3000) {
if volume.Iops != int32(*targetValue.Iops) {
modifyIops = targetValue.Iops
}
}
if targetValue.Throughput != nil && *targetValue.Throughput >= int64(125) {
if volume.Throughput != int64(*targetValue.Throughput) {
if targetValue.Throughput != nil && *targetValue.Throughput >= int32(125) {
if volume.Throughput != int32(*targetValue.Throughput) {
modifyThroughput = targetValue.Throughput
}
}
if targetSize > int64(volume.Size) {
if targetSize > volume.Size {
modifySize = &targetSize
}
@@ -437,6 +437,6 @@ func getPodNameFromPersistentVolume(pv *v1.PersistentVolume) *spec.NamespacedNam
return &spec.NamespacedName{Namespace: namespace, Name: name}
}
func quantityToGigabyte(q resource.Quantity) int64 {
return q.ScaledValue(0) / (1 * constants.Gigabyte)
func quantityToGigabyte(q resource.Quantity) int32 {
return int32(q.ScaledValue(0) / (1 * constants.Gigabyte))
}
+12 -13
View File
@@ -13,7 +13,6 @@ import (
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/golang/mock/gomock"
"github.com/stretchr/testify/assert"
"github.com/zalando/postgres-operator/mocks"
acidv1 "github.com/zalando/postgres-operator/pkg/apis/acid.zalan.do/v1"
@@ -25,9 +24,9 @@ import (
)
type testVolume struct {
size int64
iops int64
throughtput int64
size int32
iops int32
throughtput int32
volType string
}
@@ -121,7 +120,7 @@ func TestQuantityToGigabyte(t *testing.T) {
tests := []struct {
name string
quantityStr string
expected int64
expected int32
}{
{
"test with 1Gi",
@@ -131,12 +130,12 @@ func TestQuantityToGigabyte(t *testing.T) {
{
"test with float",
"1.5Gi",
int64(1),
int32(1),
},
{
"test with 1000Mi",
"1000Mi",
int64(0),
int32(0),
},
}
@@ -247,8 +246,8 @@ func TestGp2Gp3Migration(t *testing.T) {
}, client, acidv1.Postgresql{Spec: acidv1.PostgresSpec{Volume: acidv1.Volume{VolumeType: "gp3"}}}, logger, eventRecorder)
cluster.Spec.Volume.Size = "150Gi"
cluster.Spec.Volume.Iops = aws.Int64(6000)
cluster.Spec.Volume.Throughput = aws.Int64(275)
cluster.Spec.Volume.Iops = aws.Int32(6000)
cluster.Spec.Volume.Throughput = aws.Int32(275)
// set metadata, so that labels will get correct values
cluster.Name = clusterName
@@ -280,8 +279,8 @@ func TestGp2Gp3Migration(t *testing.T) {
}, 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)
resizer.EXPECT().ModifyVolume(gomock.Eq("ebs-volume-1"), gomock.Eq(aws.String("gp3")), gomock.Nil(), gomock.Eq(aws.Int32(6000)), gomock.Eq(aws.Int32(275))).Return(nil)
resizer.EXPECT().ModifyVolume(gomock.Eq("ebs-volume-2"), gomock.Eq(aws.String("gp3")), gomock.Nil(), gomock.Eq(aws.Int32(6000)), gomock.Eq(aws.Int32(275))).Return(nil)
cluster.VolumeResizer = resizer
cluster.syncVolumes()
@@ -343,8 +342,8 @@ func TestNoVolumeTypeChange(t *testing.T) {
}, 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)
resizer.EXPECT().ModifyVolume(gomock.Eq("ebs-volume-1"), gomock.Nil(), gomock.Eq(aws.Int32(177)), gomock.Nil(), gomock.Nil()).Return(nil)
resizer.EXPECT().ModifyVolume(gomock.Eq("ebs-volume-2"), gomock.Nil(), gomock.Eq(aws.Int32(177)), gomock.Nil(), gomock.Nil()).Return(nil)
cluster.VolumeResizer = resizer
cluster.syncVolumes()