Skip to content

Commit d449624

Browse files
committed
Scale up/down and Scale in/out memory considerations
When spec is updated to perform Scale up and Scale in we would need to perform Scale up first followed by Scale in. Similarly when we perform Scale down and Scale out we would need to perform Scale out first.
1 parent 38ea80a commit d449624

File tree

2 files changed

+68
-0
lines changed

2 files changed

+68
-0
lines changed

pkg/resource/replication_group/custom_update_api.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,19 @@ func (rm *resourceManager) CustomModifyReplicationGroup(
101101
return rm.decreaseReplicaCount(ctx, desired, latest)
102102
}
103103

104+
// If there is a scale up modification, then we would prioritize it
105+
// over increase/decrease shards. This is important since performing
106+
// scale in without scale up might fail due to insufficient memory.
107+
if delta.DifferentAt("Spec.CacheNodeType") && desired.ko.Status.AllowedScaleUpModifications != nil {
108+
if desired.ko.Spec.CacheNodeType != nil {
109+
for _, scaleUpInstance := range desired.ko.Status.AllowedScaleUpModifications {
110+
if *scaleUpInstance == *desired.ko.Spec.CacheNodeType {
111+
return nil, nil
112+
}
113+
}
114+
}
115+
}
116+
104117
// increase/decrease shards
105118
if rm.shardConfigurationsDiffer(desired, latest) {
106119
return rm.updateShardConfiguration(ctx, desired, latest)

pkg/resource/replication_group/custom_update_api_test.go

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"github.com/aws-controllers-k8s/elasticache-controller/pkg/testutil"
2020
ackmetrics "github.com/aws-controllers-k8s/runtime/pkg/metrics"
2121
"github.com/aws-controllers-k8s/runtime/pkg/requeue"
22+
"github.com/aws/aws-sdk-go/aws/awserr"
2223
"github.com/pkg/errors"
2324
"github.com/stretchr/testify/mock"
2425
"go.uber.org/zap/zapcore"
@@ -391,6 +392,60 @@ func TestCustomModifyReplicationGroup_NodeGroup_available(t *testing.T) {
391392
})
392393
}
393394

395+
func TestCustomModifyReplicationGroup_ScaleUpAndDown_And_Resharding(t *testing.T) {
396+
assert := assert.New(t)
397+
398+
// Tests
399+
t.Run("ScaleInAndScaleUp=Diff", func(t *testing.T) {
400+
desired := provideResource()
401+
latest := provideResource()
402+
rgId := "RGID"
403+
desired.ko.Spec.ReplicationGroupID = &rgId
404+
latest.ko.Spec.ReplicationGroupID = &rgId
405+
406+
mocksdkapi := &mocksvcsdkapi.ElastiCacheAPI{}
407+
rm := provideResourceManagerWithMockSDKAPI(mocksdkapi)
408+
409+
var delta ackcompare.Delta
410+
delta.Add("Spec.CacheNodeType", "cache.t3.small", "cache.m5.large")
411+
delta.Add("Spec.NumNodeGroups", 3, 4)
412+
413+
var ctx context.Context
414+
res, err := rm.CustomModifyReplicationGroup(ctx, desired, latest, &delta)
415+
assert.Nil(res)
416+
assert.Nil(err)
417+
assert.Empty(mocksdkapi.Calls)
418+
})
419+
420+
t.Run("ScaleOutAndScaleDown=Diff", func(t *testing.T) {
421+
desired := provideResource()
422+
latest := provideResource()
423+
rgId := "RGID"
424+
desired.ko.Spec.ReplicationGroupID = &rgId
425+
latest.ko.Spec.ReplicationGroupID = &rgId
426+
427+
mocksdkapi := &mocksvcsdkapi.ElastiCacheAPI{}
428+
rm := provideResourceManagerWithMockSDKAPI(mocksdkapi)
429+
430+
var delta ackcompare.Delta
431+
delta.Add("Spec.CacheNodeType", "cache.t3.small", "cache.t3.micro")
432+
oldshardCount := int64(4)
433+
newShardCount := int64(10)
434+
delta.Add("Spec.NumNodeGroups", oldshardCount, newShardCount)
435+
desired.ko.Spec.NumNodeGroups = &newShardCount
436+
latest.ko.Spec.NumNodeGroups = &oldshardCount
437+
mocksdkapi.On("ModifyReplicationGroupShardConfigurationWithContext", mock.Anything, mock.Anything).Return(nil,
438+
awserr.New("Invalid", "Invalid error", nil))
439+
var ctx context.Context
440+
res, err := rm.CustomModifyReplicationGroup(ctx, desired, latest, &delta)
441+
assert.Nil(res)
442+
assert.NotNil(err)
443+
assert.NotEmpty(mocksdkapi.Calls)
444+
assert.Equal("ModifyReplicationGroupShardConfigurationWithContext", mocksdkapi.Calls[0].Method)
445+
})
446+
447+
}
448+
394449
// TestReplicaCountDifference tests scenarios to check if desired, latest replica count
395450
// configurations differ
396451
func TestReplicaCountDifference(t *testing.T) {

0 commit comments

Comments
 (0)