@@ -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,14 @@ func (rm *resourceManager) customUpdateTable(
187
203
}
188
204
}
189
205
206
+ if delta .DifferentAt ("Spec.ContinuousBackups" ) ||
207
+ delta .DifferentAt ("Spec.ContinuousBackups.PointInTimeRecoveryEnabled" ) {
208
+ err = rm .syncContinuousBackup (ctx , desired )
209
+ if err != nil {
210
+ return nil , fmt .Errorf ("cannot update table %v" , err )
211
+ }
212
+ }
213
+
190
214
// We want to update fast fields first
191
215
// Then attributes
192
216
// then GSI
@@ -202,7 +226,8 @@ func (rm *resourceManager) customUpdateTable(
202
226
}
203
227
case delta .DifferentAt ("Spec.GlobalSecondaryIndexes" ) && delta .DifferentAt ("Spec.AttributeDefinitions" ):
204
228
if err := rm .syncTableGlobalSecondaryIndexes (ctx , latest , desired ); err != nil {
205
- if awsErr , ok := ackerr .AWSError (err ); ok && awsErr .Code () == "LimitExceededException" {
229
+ if awsErr , ok := ackerr .AWSError (err ); ok &&
230
+ awsErr .Code () == "LimitExceededException" {
206
231
return nil , requeueWaitGSIReady
207
232
}
208
233
return nil , err
@@ -257,13 +282,17 @@ func (rm *resourceManager) newUpdateTablePayload(
257
282
input .ProvisionedThroughput = & svcsdk.ProvisionedThroughput {}
258
283
if r .ko .Spec .ProvisionedThroughput != nil {
259
284
if r .ko .Spec .ProvisionedThroughput .ReadCapacityUnits != nil {
260
- input .ProvisionedThroughput .ReadCapacityUnits = aws .Int64 (* r .ko .Spec .ProvisionedThroughput .ReadCapacityUnits )
285
+ input .ProvisionedThroughput .ReadCapacityUnits = aws .Int64 (
286
+ * r .ko .Spec .ProvisionedThroughput .ReadCapacityUnits ,
287
+ )
261
288
} else {
262
289
input .ProvisionedThroughput .ReadCapacityUnits = aws .Int64 (0 )
263
290
}
264
291
265
292
if r .ko .Spec .ProvisionedThroughput .WriteCapacityUnits != nil {
266
- input .ProvisionedThroughput .WriteCapacityUnits = aws .Int64 (* r .ko .Spec .ProvisionedThroughput .WriteCapacityUnits )
293
+ input .ProvisionedThroughput .WriteCapacityUnits = aws .Int64 (
294
+ * r .ko .Spec .ProvisionedThroughput .WriteCapacityUnits ,
295
+ )
267
296
} else {
268
297
input .ProvisionedThroughput .WriteCapacityUnits = aws .Int64 (0 )
269
298
}
@@ -277,8 +306,11 @@ func (rm *resourceManager) newUpdateTablePayload(
277
306
StreamEnabled : aws .Bool (* r .ko .Spec .StreamSpecification .StreamEnabled ),
278
307
}
279
308
// 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 )
309
+ if * r .ko .Spec .StreamSpecification .StreamEnabled &&
310
+ r .ko .Spec .StreamSpecification .StreamViewType != nil {
311
+ input .StreamSpecification .StreamViewType = aws .String (
312
+ * r .ko .Spec .StreamSpecification .StreamViewType ,
313
+ )
282
314
}
283
315
} else {
284
316
input .StreamSpecification = & svcsdk.StreamSpecification {
@@ -317,7 +349,9 @@ func (rm *resourceManager) syncTableSSESpecification(
317
349
input .SSESpecification .SSEType = aws .String (* r .ko .Spec .SSESpecification .SSEType )
318
350
}
319
351
if r .ko .Spec .SSESpecification .KMSMasterKeyID != nil {
320
- input .SSESpecification .KMSMasterKeyId = aws .String (* r .ko .Spec .SSESpecification .KMSMasterKeyID )
352
+ input .SSESpecification .KMSMasterKeyId = aws .String (
353
+ * r .ko .Spec .SSESpecification .KMSMasterKeyID ,
354
+ )
321
355
}
322
356
}
323
357
} else {
@@ -350,13 +384,17 @@ func (rm *resourceManager) syncTableProvisionedThroughput(
350
384
}
351
385
if r .ko .Spec .ProvisionedThroughput != nil {
352
386
if r .ko .Spec .ProvisionedThroughput .ReadCapacityUnits != nil {
353
- input .ProvisionedThroughput .ReadCapacityUnits = aws .Int64 (* r .ko .Spec .ProvisionedThroughput .ReadCapacityUnits )
387
+ input .ProvisionedThroughput .ReadCapacityUnits = aws .Int64 (
388
+ * r .ko .Spec .ProvisionedThroughput .ReadCapacityUnits ,
389
+ )
354
390
} else {
355
391
input .ProvisionedThroughput .ReadCapacityUnits = aws .Int64 (0 )
356
392
}
357
393
358
394
if r .ko .Spec .ProvisionedThroughput .WriteCapacityUnits != nil {
359
- input .ProvisionedThroughput .WriteCapacityUnits = aws .Int64 (* r .ko .Spec .ProvisionedThroughput .WriteCapacityUnits )
395
+ input .ProvisionedThroughput .WriteCapacityUnits = aws .Int64 (
396
+ * r .ko .Spec .ProvisionedThroughput .WriteCapacityUnits ,
397
+ )
360
398
} else {
361
399
input .ProvisionedThroughput .WriteCapacityUnits = aws .Int64 (0 )
362
400
}
@@ -395,6 +433,12 @@ func (rm *resourceManager) setResourceAdditionalFields(
395
433
ko .Spec .TimeToLive = ttlSpec
396
434
}
397
435
436
+ if pitrSpec , err := rm .getResourcePointInTimeRecoveryWithContext (ctx , ko .Spec .TableName ); err != nil {
437
+ return err
438
+ } else {
439
+ ko .Spec .ContinuousBackups = pitrSpec
440
+ }
441
+
398
442
return nil
399
443
}
400
444
@@ -403,11 +447,14 @@ func customPreCompare(
403
447
a * resource ,
404
448
b * resource ,
405
449
) {
406
-
407
450
if ackcompare .HasNilDifference (a .ko .Spec .SSESpecification , b .ko .Spec .SSESpecification ) {
408
451
if a .ko .Spec .SSESpecification != nil && b .ko .Spec .SSESpecification == nil {
409
452
if * a .ko .Spec .SSESpecification .Enabled {
410
- delta .Add ("Spec.SSESpecification" , a .ko .Spec .SSESpecification , b .ko .Spec .SSESpecification )
453
+ delta .Add (
454
+ "Spec.SSESpecification" ,
455
+ a .ko .Spec .SSESpecification ,
456
+ b .ko .Spec .SSESpecification ,
457
+ )
411
458
}
412
459
} else {
413
460
delta .Add ("Spec.SSESpecification" , a .ko .Spec .SSESpecification , b .ko .Spec .SSESpecification )
@@ -447,23 +494,35 @@ func customPreCompare(
447
494
}
448
495
449
496
if len (a .ko .Spec .AttributeDefinitions ) != len (b .ko .Spec .AttributeDefinitions ) {
450
- delta .Add ("Spec.AttributeDefinitions" , a .ko .Spec .AttributeDefinitions , b .ko .Spec .AttributeDefinitions )
497
+ delta .Add (
498
+ "Spec.AttributeDefinitions" ,
499
+ a .ko .Spec .AttributeDefinitions ,
500
+ b .ko .Spec .AttributeDefinitions ,
501
+ )
451
502
} else if a .ko .Spec .AttributeDefinitions != nil && b .ko .Spec .AttributeDefinitions != nil {
452
503
if ! equalAttributeDefinitions (a .ko .Spec .AttributeDefinitions , b .ko .Spec .AttributeDefinitions ) {
453
504
delta .Add ("Spec.AttributeDefinitions" , a .ko .Spec .AttributeDefinitions , b .ko .Spec .AttributeDefinitions )
454
505
}
455
506
}
456
507
457
508
if len (a .ko .Spec .GlobalSecondaryIndexes ) != len (b .ko .Spec .GlobalSecondaryIndexes ) {
458
- delta .Add ("Spec.GlobalSecondaryIndexes" , a .ko .Spec .GlobalSecondaryIndexes , b .ko .Spec .GlobalSecondaryIndexes )
509
+ delta .Add (
510
+ "Spec.GlobalSecondaryIndexes" ,
511
+ a .ko .Spec .GlobalSecondaryIndexes ,
512
+ b .ko .Spec .GlobalSecondaryIndexes ,
513
+ )
459
514
} else if a .ko .Spec .GlobalSecondaryIndexes != nil && b .ko .Spec .GlobalSecondaryIndexes != nil {
460
515
if ! equalGlobalSecondaryIndexesArrays (a .ko .Spec .GlobalSecondaryIndexes , b .ko .Spec .GlobalSecondaryIndexes ) {
461
516
delta .Add ("Spec.GlobalSecondaryIndexes" , a .ko .Spec .GlobalSecondaryIndexes , b .ko .Spec .GlobalSecondaryIndexes )
462
517
}
463
518
}
464
519
465
520
if len (a .ko .Spec .LocalSecondaryIndexes ) != len (b .ko .Spec .LocalSecondaryIndexes ) {
466
- delta .Add ("Spec.LocalSecondaryIndexes" , a .ko .Spec .LocalSecondaryIndexes , b .ko .Spec .LocalSecondaryIndexes )
521
+ delta .Add (
522
+ "Spec.LocalSecondaryIndexes" ,
523
+ a .ko .Spec .LocalSecondaryIndexes ,
524
+ b .ko .Spec .LocalSecondaryIndexes ,
525
+ )
467
526
} else if a .ko .Spec .LocalSecondaryIndexes != nil && b .ko .Spec .LocalSecondaryIndexes != nil {
468
527
if ! equalLocalSecondaryIndexesArrays (a .ko .Spec .LocalSecondaryIndexes , b .ko .Spec .LocalSecondaryIndexes ) {
469
528
delta .Add ("Spec.LocalSecondaryIndexes" , a .ko .Spec .LocalSecondaryIndexes , b .ko .Spec .LocalSecondaryIndexes )
@@ -496,6 +555,12 @@ func customPreCompare(
496
555
Enabled : & DefaultTTLEnabledValue ,
497
556
}
498
557
}
558
+ if a .ko .Spec .ContinuousBackups == nil && b .ko .Spec .ContinuousBackups != nil &&
559
+ b .ko .Spec .ContinuousBackups .PointInTimeRecoveryEnabled != nil {
560
+ a .ko .Spec .ContinuousBackups = & v1alpha1.PointInTimeRecoverySpecification {
561
+ PointInTimeRecoveryEnabled : & DefaultPITREnabledValue ,
562
+ }
563
+ }
499
564
}
500
565
501
566
// equalAttributeDefinitions return whether two AttributeDefinition arrays are equal or not.
@@ -614,7 +679,10 @@ func equalLocalSecondaryIndexes(
614
679
if ! equalStrings (a .Projection .ProjectionType , b .Projection .ProjectionType ) {
615
680
return false
616
681
}
617
- if ! ackcompare .SliceStringPEqual (a .Projection .NonKeyAttributes , b .Projection .NonKeyAttributes ) {
682
+ if ! ackcompare .SliceStringPEqual (
683
+ a .Projection .NonKeyAttributes ,
684
+ b .Projection .NonKeyAttributes ,
685
+ ) {
618
686
return false
619
687
}
620
688
}
0 commit comments