1+ // Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
2+ //
3+ // Licensed under the Apache License, Version 2.0 (the "License"). You may
4+ // not use this file except in compliance with the License. A copy of the
5+ // License is located at
6+ //
7+ // http://aws.amazon.com/apache2.0/
8+ //
9+ // or in the "license" file accompanying this file. This file is distributed
10+ // on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
11+ // express or implied. See the License for the specific language governing
12+ // permissions and limitations under the License.
13+
114package table
215
316import (
417 "context"
5- "errors"
618
7- ackerr "github.com/aws-controllers-k8s/runtime/pkg/errors"
819 ackrtlog "github.com/aws-controllers-k8s/runtime/pkg/runtime/log"
9-
1020 "github.com/aws/aws-sdk-go-v2/aws"
11- "github.com/aws-controllers-k8s/dynamodb-controller/apis/v1alpha1"
1221 svcsdk "github.com/aws/aws-sdk-go-v2/service/dynamodb"
1322 svcsdktypes "github.com/aws/aws-sdk-go-v2/service/dynamodb/types"
23+
24+ "github.com/aws-controllers-k8s/dynamodb-controller/apis/v1alpha1"
1425)
1526
1627// equalCreateReplicationGroupMemberActions compares two CreateReplicationGroupMemberAction objects
@@ -238,17 +249,11 @@ func deleteReplicaUpdate(regionName string) svcsdktypes.ReplicationGroupUpdate {
238249// canUpdateTableReplicas returns true if it's possible to update table replicas.
239250// We can only modify replicas when they are in ACTIVE state.
240251func canUpdateTableReplicas (r * resource ) bool {
241- if isTableCreating (r ) || isTableDeleting (r ) || isTableUpdating (r ) {
242- return false
243- }
244-
245252 // Check if any replica is not in ACTIVE state
246- if r .ko .Status .ReplicasDescriptions != nil {
247- for _ , replicaDesc := range r .ko .Status .ReplicasDescriptions {
248- if replicaDesc .RegionName != nil && replicaDesc .ReplicaStatus != nil {
249- if * replicaDesc .ReplicaStatus != string (svcsdktypes .ReplicaStatusActive ) {
250- return false
251- }
253+ for _ , replicaDesc := range r .ko .Status .Replicas {
254+ if replicaDesc .RegionName != nil && replicaDesc .ReplicaStatus != nil {
255+ if * replicaDesc .ReplicaStatus != string (svcsdktypes .ReplicaStatusActive ) {
256+ return false
252257 }
253258 }
254259 }
@@ -275,32 +280,15 @@ func (rm *resourceManager) syncReplicaUpdates(
275280) (err error ) {
276281 rlog := ackrtlog .FromContext (ctx )
277282 exit := rlog .Trace ("rm.syncReplicaUpdates" )
278- defer exit (err )
279-
280- if ! hasStreamSpecificationWithNewAndOldImages (desired ) {
281- msg := "table must have DynamoDB Streams enabled with StreamViewType set to NEW_AND_OLD_IMAGES for replica updates"
282- rlog .Debug (msg )
283- return ackerr .NewTerminalError (errors .New (msg ))
284- }
285-
286- if ! canUpdateTableReplicas (latest ) {
287- return requeueWaitForReplicasActive
288- }
289-
290- if isTableUpdating (latest ) {
291- return requeueWaitWhileUpdating
292- }
283+ defer func () {
284+ exit (err )
285+ }()
293286
294287 input , replicasInQueue , err := rm .newUpdateTableReplicaUpdatesOneAtATimePayload (ctx , latest , desired )
295288 if err != nil {
296289 return err
297290 }
298291
299- // If there are no updates to make, we don't need to requeue
300- if len (input .ReplicaUpdates ) == 0 {
301- return nil
302- }
303-
304292 // Call the UpdateTable API
305293 _ , err = rm .sdkapi .UpdateTable (ctx , input )
306294 rm .metrics .RecordAPICall ("UPDATE" , "UpdateTable" , err )
@@ -328,7 +316,9 @@ func (rm *resourceManager) newUpdateTableReplicaUpdatesOneAtATimePayload(
328316) (input * svcsdk.UpdateTableInput , replicasInQueue int , err error ) {
329317 rlog := ackrtlog .FromContext (ctx )
330318 exit := rlog .Trace ("rm.newUpdateTableReplicaUpdatesOneAtATimePayload" )
331- defer exit (err )
319+ defer func () {
320+ exit (err )
321+ }()
332322
333323 createReplicas , updateReplicas , deleteRegions := calculateReplicaUpdates (latest , desired )
334324
@@ -378,17 +368,17 @@ func calculateReplicaUpdates(
378368 deleteRegions []string ,
379369) {
380370 existingRegions := make (map [string ]* v1alpha1.CreateReplicationGroupMemberAction )
381- if latest != nil && latest .ko .Spec .Replicas != nil {
382- for _ , replica := range latest .ko .Spec .Replicas {
371+ if latest != nil && latest .ko .Spec .ReplicationGroup != nil {
372+ for _ , replica := range latest .ko .Spec .ReplicationGroup {
383373 if replica .RegionName != nil {
384374 existingRegions [* replica .RegionName ] = replica
385375 }
386376 }
387377 }
388378
389379 desiredRegions := make (map [string ]* v1alpha1.CreateReplicationGroupMemberAction )
390- if desired != nil && desired .ko .Spec .Replicas != nil {
391- for _ , replica := range desired .ko .Spec .Replicas {
380+ if desired != nil && desired .ko .Spec .ReplicationGroup != nil {
381+ for _ , replica := range desired .ko .Spec .ReplicationGroup {
392382 if replica .RegionName != nil {
393383 desiredRegions [* replica .RegionName ] = replica
394384 }
0 commit comments