Skip to content

Commit

Permalink
Enable Scale-In without NodeGroupConfiguration
Browse files Browse the repository at this point in the history
Scale-In requires the node group to remove or
node group to retain.

Including logic to remove last node group if
NodeGroupConfiguration isnt specified.
  • Loading branch information
nmvk committed Sep 25, 2021
1 parent f9de752 commit 4f95892
Showing 1 changed file with 18 additions and 14 deletions.
32 changes: 18 additions & 14 deletions pkg/resource/replication_group/custom_update_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,20 @@ func (rm *resourceManager) newUpdateShardConfigurationRequestPayload(
res.SetNodeGroupCount(*desiredShardsCount)
}

// If desired nodegroup count (number of shards):
// - increases, then (optional) provide ReshardingConfiguration
// - decreases, then (mandatory) provide
// either NodeGroupsToRemove
// or NodeGroupsToRetain
var latestShardsCount *int64 = nil
if latestStatus.NodeGroups != nil {
numShards := int64(len(latestStatus.NodeGroups))
latestShardsCount = &numShards
}

increase := (desiredShardsCount != nil && latestShardsCount != nil && *desiredShardsCount > *latestShardsCount) ||
(desiredShardsCount != nil && latestShardsCount == nil)
decrease := desiredShardsCount != nil && latestShardsCount != nil && *desiredShardsCount < *latestShardsCount
// Additional arguments
shardsConfig := []*svcsdk.ReshardingConfiguration{}
shardsToRetain := []*string{}
Expand All @@ -494,21 +508,11 @@ func (rm *resourceManager) newUpdateShardConfigurationRequestPayload(
}
shardsConfig = append(shardsConfig, shardConfig)
}
} else if decrease {
for i := 0; i < int(*desiredShardsCount); i++ {
shardsToRetain = append(shardsToRetain, desired.ko.Status.NodeGroups[i].NodeGroupID)
}
}
// If desired nodegroup count (number of shards):
// - increases, then (optional) provide ReshardingConfiguration
// - decreases, then (mandatory) provide
// either NodeGroupsToRemove
// or NodeGroupsToRetain
var latestShardsCount *int64 = nil
if latestStatus.NodeGroups != nil {
numShards := int64(len(latestStatus.NodeGroups))
latestShardsCount = &numShards
}

increase := (desiredShardsCount != nil && latestShardsCount != nil && *desiredShardsCount > *latestShardsCount) ||
(desiredShardsCount != nil && latestShardsCount == nil)
decrease := desiredShardsCount != nil && latestShardsCount != nil && *desiredShardsCount < *latestShardsCount

if increase {
if len(shardsConfig) > 0 {
Expand Down

0 comments on commit 4f95892

Please sign in to comment.