@@ -32,23 +32,36 @@ import (
32
32
)
33
33
34
34
var (
35
- ErrTableDeleting = fmt .Errorf ("Table in '%v' state, cannot be modified or deleted" , svcsdk .TableStatusDeleting )
36
- ErrTableCreating = fmt .Errorf ("Table in '%v' state, cannot be modified or deleted" , svcsdk .TableStatusCreating )
37
- ErrTableUpdating = fmt .Errorf ("Table in '%v' state, cannot be modified or deleted" , svcsdk .TableStatusUpdating )
38
- ErrTableGSIsUpdating = fmt .Errorf ("Table GSIs in '%v' state, cannot be modified or deleted" , svcsdk .IndexStatusCreating )
35
+ ErrTableDeleting = fmt .Errorf (
36
+ "Table in '%v' state, cannot be modified or deleted" ,
37
+ svcsdk .TableStatusDeleting ,
38
+ )
39
+ ErrTableCreating = fmt .Errorf (
40
+ "Table in '%v' state, cannot be modified or deleted" ,
41
+ svcsdk .TableStatusCreating ,
42
+ )
43
+ ErrTableUpdating = fmt .Errorf (
44
+ "Table in '%v' state, cannot be modified or deleted" ,
45
+ svcsdk .TableStatusUpdating ,
46
+ )
47
+ ErrTableGSIsUpdating = fmt .Errorf (
48
+ "Table GSIs in '%v' state, cannot be modified or deleted" ,
49
+ svcsdk .IndexStatusCreating ,
50
+ )
39
51
)
40
52
53
+ // TerminalStatuses are the status strings that are terminal states for a
54
+ // DynamoDB table
55
+ var TerminalStatuses = []v1alpha1.TableStatus_SDK {
56
+ v1alpha1 .TableStatus_SDK_ARCHIVING ,
57
+ v1alpha1 .TableStatus_SDK_DELETING ,
58
+ }
59
+
41
60
var (
42
- // TerminalStatuses are the status strings that are terminal states for a
43
- // DynamoDB table
44
- TerminalStatuses = []v1alpha1.TableStatus_SDK {
45
- v1alpha1 .TableStatus_SDK_ARCHIVING ,
46
- v1alpha1 .TableStatus_SDK_DELETING ,
47
- }
61
+ DefaultTTLEnabledValue = false
62
+ DefaultPITREnabledValue = false
48
63
)
49
64
50
- var DefaultTTLEnabledValue = false
51
-
52
65
var (
53
66
requeueWaitWhileDeleting = ackrequeue .NeededAfter (
54
67
ErrTableDeleting ,
@@ -124,7 +137,10 @@ func (rm *resourceManager) customUpdateTable(
124
137
defer func (err error ) { exit (err ) }(err )
125
138
126
139
if immutableFieldChanges := rm .getImmutableFieldChanges (delta ); len (immutableFieldChanges ) > 0 {
127
- msg := fmt .Sprintf ("Immutable Spec fields have been modified: %s" , strings .Join (immutableFieldChanges , "," ))
140
+ msg := fmt .Sprintf (
141
+ "Immutable Spec fields have been modified: %s" ,
142
+ strings .Join (immutableFieldChanges , "," ),
143
+ )
128
144
return nil , ackerr .NewTerminalError (fmt .Errorf (msg ))
129
145
}
130
146
@@ -187,6 +203,13 @@ func (rm *resourceManager) customUpdateTable(
187
203
}
188
204
}
189
205
206
+ if delta .DifferentAt ("Spec.ContinuousBackups" ) {
207
+ err = rm .syncContinuousBackup (ctx , desired )
208
+ if err != nil {
209
+ return nil , fmt .Errorf ("cannot update table %v" , err )
210
+ }
211
+ }
212
+
190
213
// We want to update fast fields first
191
214
// Then attributes
192
215
// then GSI
@@ -202,7 +225,8 @@ func (rm *resourceManager) customUpdateTable(
202
225
}
203
226
case delta .DifferentAt ("Spec.GlobalSecondaryIndexes" ) && delta .DifferentAt ("Spec.AttributeDefinitions" ):
204
227
if err := rm .syncTableGlobalSecondaryIndexes (ctx , latest , desired ); err != nil {
205
- if awsErr , ok := ackerr .AWSError (err ); ok && awsErr .Code () == "LimitExceededException" {
228
+ if awsErr , ok := ackerr .AWSError (err ); ok &&
229
+ awsErr .Code () == "LimitExceededException" {
206
230
return nil , requeueWaitGSIReady
207
231
}
208
232
return nil , err
@@ -257,13 +281,17 @@ func (rm *resourceManager) newUpdateTablePayload(
257
281
input .ProvisionedThroughput = & svcsdk.ProvisionedThroughput {}
258
282
if r .ko .Spec .ProvisionedThroughput != nil {
259
283
if r .ko .Spec .ProvisionedThroughput .ReadCapacityUnits != nil {
260
- input .ProvisionedThroughput .ReadCapacityUnits = aws .Int64 (* r .ko .Spec .ProvisionedThroughput .ReadCapacityUnits )
284
+ input .ProvisionedThroughput .ReadCapacityUnits = aws .Int64 (
285
+ * r .ko .Spec .ProvisionedThroughput .ReadCapacityUnits ,
286
+ )
261
287
} else {
262
288
input .ProvisionedThroughput .ReadCapacityUnits = aws .Int64 (0 )
263
289
}
264
290
265
291
if r .ko .Spec .ProvisionedThroughput .WriteCapacityUnits != nil {
266
- input .ProvisionedThroughput .WriteCapacityUnits = aws .Int64 (* r .ko .Spec .ProvisionedThroughput .WriteCapacityUnits )
292
+ input .ProvisionedThroughput .WriteCapacityUnits = aws .Int64 (
293
+ * r .ko .Spec .ProvisionedThroughput .WriteCapacityUnits ,
294
+ )
267
295
} else {
268
296
input .ProvisionedThroughput .WriteCapacityUnits = aws .Int64 (0 )
269
297
}
@@ -277,8 +305,11 @@ func (rm *resourceManager) newUpdateTablePayload(
277
305
StreamEnabled : aws .Bool (* r .ko .Spec .StreamSpecification .StreamEnabled ),
278
306
}
279
307
// Only set streamViewType when streamSpefication is enabled and streamViewType is non-nil.
280
- if * r .ko .Spec .StreamSpecification .StreamEnabled && r .ko .Spec .StreamSpecification .StreamViewType != nil {
281
- input .StreamSpecification .StreamViewType = aws .String (* r .ko .Spec .StreamSpecification .StreamViewType )
308
+ if * r .ko .Spec .StreamSpecification .StreamEnabled &&
309
+ r .ko .Spec .StreamSpecification .StreamViewType != nil {
310
+ input .StreamSpecification .StreamViewType = aws .String (
311
+ * r .ko .Spec .StreamSpecification .StreamViewType ,
312
+ )
282
313
}
283
314
} else {
284
315
input .StreamSpecification = & svcsdk.StreamSpecification {
@@ -317,7 +348,9 @@ func (rm *resourceManager) syncTableSSESpecification(
317
348
input .SSESpecification .SSEType = aws .String (* r .ko .Spec .SSESpecification .SSEType )
318
349
}
319
350
if r .ko .Spec .SSESpecification .KMSMasterKeyID != nil {
320
- input .SSESpecification .KMSMasterKeyId = aws .String (* r .ko .Spec .SSESpecification .KMSMasterKeyID )
351
+ input .SSESpecification .KMSMasterKeyId = aws .String (
352
+ * r .ko .Spec .SSESpecification .KMSMasterKeyID ,
353
+ )
321
354
}
322
355
}
323
356
} else {
@@ -350,13 +383,17 @@ func (rm *resourceManager) syncTableProvisionedThroughput(
350
383
}
351
384
if r .ko .Spec .ProvisionedThroughput != nil {
352
385
if r .ko .Spec .ProvisionedThroughput .ReadCapacityUnits != nil {
353
- input .ProvisionedThroughput .ReadCapacityUnits = aws .Int64 (* r .ko .Spec .ProvisionedThroughput .ReadCapacityUnits )
386
+ input .ProvisionedThroughput .ReadCapacityUnits = aws .Int64 (
387
+ * r .ko .Spec .ProvisionedThroughput .ReadCapacityUnits ,
388
+ )
354
389
} else {
355
390
input .ProvisionedThroughput .ReadCapacityUnits = aws .Int64 (0 )
356
391
}
357
392
358
393
if r .ko .Spec .ProvisionedThroughput .WriteCapacityUnits != nil {
359
- input .ProvisionedThroughput .WriteCapacityUnits = aws .Int64 (* r .ko .Spec .ProvisionedThroughput .WriteCapacityUnits )
394
+ input .ProvisionedThroughput .WriteCapacityUnits = aws .Int64 (
395
+ * r .ko .Spec .ProvisionedThroughput .WriteCapacityUnits ,
396
+ )
360
397
} else {
361
398
input .ProvisionedThroughput .WriteCapacityUnits = aws .Int64 (0 )
362
399
}
@@ -395,6 +432,12 @@ func (rm *resourceManager) setResourceAdditionalFields(
395
432
ko .Spec .TimeToLive = ttlSpec
396
433
}
397
434
435
+ if pitrSpec , err := rm .getResourcePointInTimeRecoveryWithContext (ctx , ko .Spec .TableName ); err != nil {
436
+ return err
437
+ } else {
438
+ ko .Spec .ContinuousBackups = pitrSpec
439
+ }
440
+
398
441
return nil
399
442
}
400
443
@@ -403,11 +446,14 @@ func customPreCompare(
403
446
a * resource ,
404
447
b * resource ,
405
448
) {
406
-
407
449
if ackcompare .HasNilDifference (a .ko .Spec .SSESpecification , b .ko .Spec .SSESpecification ) {
408
450
if a .ko .Spec .SSESpecification != nil && b .ko .Spec .SSESpecification == nil {
409
451
if * a .ko .Spec .SSESpecification .Enabled {
410
- delta .Add ("Spec.SSESpecification" , a .ko .Spec .SSESpecification , b .ko .Spec .SSESpecification )
452
+ delta .Add (
453
+ "Spec.SSESpecification" ,
454
+ a .ko .Spec .SSESpecification ,
455
+ b .ko .Spec .SSESpecification ,
456
+ )
411
457
}
412
458
} else {
413
459
delta .Add ("Spec.SSESpecification" , a .ko .Spec .SSESpecification , b .ko .Spec .SSESpecification )
@@ -447,23 +493,35 @@ func customPreCompare(
447
493
}
448
494
449
495
if len (a .ko .Spec .AttributeDefinitions ) != len (b .ko .Spec .AttributeDefinitions ) {
450
- delta .Add ("Spec.AttributeDefinitions" , a .ko .Spec .AttributeDefinitions , b .ko .Spec .AttributeDefinitions )
496
+ delta .Add (
497
+ "Spec.AttributeDefinitions" ,
498
+ a .ko .Spec .AttributeDefinitions ,
499
+ b .ko .Spec .AttributeDefinitions ,
500
+ )
451
501
} else if a .ko .Spec .AttributeDefinitions != nil && b .ko .Spec .AttributeDefinitions != nil {
452
502
if ! equalAttributeDefinitions (a .ko .Spec .AttributeDefinitions , b .ko .Spec .AttributeDefinitions ) {
453
503
delta .Add ("Spec.AttributeDefinitions" , a .ko .Spec .AttributeDefinitions , b .ko .Spec .AttributeDefinitions )
454
504
}
455
505
}
456
506
457
507
if len (a .ko .Spec .GlobalSecondaryIndexes ) != len (b .ko .Spec .GlobalSecondaryIndexes ) {
458
- delta .Add ("Spec.GlobalSecondaryIndexes" , a .ko .Spec .GlobalSecondaryIndexes , b .ko .Spec .GlobalSecondaryIndexes )
508
+ delta .Add (
509
+ "Spec.GlobalSecondaryIndexes" ,
510
+ a .ko .Spec .GlobalSecondaryIndexes ,
511
+ b .ko .Spec .GlobalSecondaryIndexes ,
512
+ )
459
513
} else if a .ko .Spec .GlobalSecondaryIndexes != nil && b .ko .Spec .GlobalSecondaryIndexes != nil {
460
514
if ! equalGlobalSecondaryIndexesArrays (a .ko .Spec .GlobalSecondaryIndexes , b .ko .Spec .GlobalSecondaryIndexes ) {
461
515
delta .Add ("Spec.GlobalSecondaryIndexes" , a .ko .Spec .GlobalSecondaryIndexes , b .ko .Spec .GlobalSecondaryIndexes )
462
516
}
463
517
}
464
518
465
519
if len (a .ko .Spec .LocalSecondaryIndexes ) != len (b .ko .Spec .LocalSecondaryIndexes ) {
466
- delta .Add ("Spec.LocalSecondaryIndexes" , a .ko .Spec .LocalSecondaryIndexes , b .ko .Spec .LocalSecondaryIndexes )
520
+ delta .Add (
521
+ "Spec.LocalSecondaryIndexes" ,
522
+ a .ko .Spec .LocalSecondaryIndexes ,
523
+ b .ko .Spec .LocalSecondaryIndexes ,
524
+ )
467
525
} else if a .ko .Spec .LocalSecondaryIndexes != nil && b .ko .Spec .LocalSecondaryIndexes != nil {
468
526
if ! equalLocalSecondaryIndexesArrays (a .ko .Spec .LocalSecondaryIndexes , b .ko .Spec .LocalSecondaryIndexes ) {
469
527
delta .Add ("Spec.LocalSecondaryIndexes" , a .ko .Spec .LocalSecondaryIndexes , b .ko .Spec .LocalSecondaryIndexes )
@@ -496,6 +554,12 @@ func customPreCompare(
496
554
Enabled : & DefaultTTLEnabledValue ,
497
555
}
498
556
}
557
+ if a .ko .Spec .ContinuousBackups == nil && b .ko .Spec .ContinuousBackups != nil &&
558
+ b .ko .Spec .ContinuousBackups .PointInTimeRecoveryEnabled != nil {
559
+ a .ko .Spec .ContinuousBackups = & v1alpha1.PointInTimeRecoverySpecification {
560
+ PointInTimeRecoveryEnabled : & DefaultPITREnabledValue ,
561
+ }
562
+ }
499
563
}
500
564
501
565
// equalAttributeDefinitions return whether two AttributeDefinition arrays are equal or not.
@@ -614,7 +678,10 @@ func equalLocalSecondaryIndexes(
614
678
if ! equalStrings (a .Projection .ProjectionType , b .Projection .ProjectionType ) {
615
679
return false
616
680
}
617
- if ! ackcompare .SliceStringPEqual (a .Projection .NonKeyAttributes , b .Projection .NonKeyAttributes ) {
681
+ if ! ackcompare .SliceStringPEqual (
682
+ a .Projection .NonKeyAttributes ,
683
+ b .Projection .NonKeyAttributes ,
684
+ ) {
618
685
return false
619
686
}
620
687
}
0 commit comments