Skip to content

Commit 0601b0b

Browse files
committed
add custom state ReplcaState
1 parent b53e944 commit 0601b0b

18 files changed

+248
-205
lines changed
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
ack_generate_info:
2-
build_date: "2025-03-14T22:49:47Z"
3-
build_hash: 0ab258c51775fd52af32e649da00d57373b20869
2+
build_date: "2025-03-21T01:11:17Z"
3+
build_hash: 3722729cebe6d3c03c7e442655ef0846f91566a2
44
go_version: go1.24.0
5-
version: v0.43.2-6-g0ab258c
6-
api_directory_checksum: 0d5b95bdbe63c6cfc495149b7a86440c4a5fb33a
5+
version: v0.43.2-7-g3722729
6+
api_directory_checksum: 8d795cf646566fd401b3d1642eaeb6524010c17c
77
api_version: v1alpha1
88
aws_sdk_go_version: v1.32.6
99
generator_config_info:
10-
file_checksum: 85db04e11e016a28a99058aab04767cf8345242e
10+
file_checksum: 51bcf58f02c2653ddaf3d98d6d60216c04c53dfe
1111
original_file_name: generator.yaml
1212
last_modification:
1313
reason: API generation

apis/v1alpha1/generator.yaml

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@ ignore:
1313
- TableDescription.TableClassSummary
1414
- CreateTableInput.ResourcePolicy
1515
- CreateTableInput.WarmThroughput
16+
custom_shapes:
17+
RepicaState:
18+
RegionName: string
19+
RegionStatus: string
20+
RegionStatusDescription: string
21+
RegionStatusPercentProgress: string
22+
RegionInaccessibleDateTime: string
1623
operations:
1724
UpdateGlobalTable:
1825
operation_type:
@@ -25,15 +32,11 @@ operations:
2532
resources:
2633
Table:
2734
fields:
28-
Replicas:
35+
ReplicationGroup:
2936
custom_field:
3037
list_of: CreateReplicationGroupMemberAction
3138
compare:
3239
is_ignored: true
33-
ReplicasDescriptions:
34-
custom_field:
35-
list_of: ReplicaDescription
36-
is_read_only: true
3740
GlobalSecondaryIndexesDescriptions:
3841
custom_field:
3942
list_of: GlobalSecondaryIndexDescription
@@ -73,7 +76,7 @@ resources:
7376
references:
7477
service_name: kms
7578
resource: Key
76-
path: Status.ACKResourceMetadata.ARN
79+
path: Status.ACKResourceMetadata.ARN
7780
exceptions:
7881
errors:
7982
404:

apis/v1alpha1/table.go

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apis/v1alpha1/types.go

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apis/v1alpha1/zz_generated.deepcopy.go

Lines changed: 24 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/bases/dynamodb.services.k8s.aws_tables.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ spec:
322322
format: int64
323323
type: integer
324324
type: object
325-
replicas:
325+
replicationGroup:
326326
items:
327327
description: Represents a replica to be created.
328328
properties:
@@ -644,7 +644,8 @@ spec:
644644
645645
* StreamLabel
646646
type: string
647-
replicasDescriptions:
647+
replicas:
648+
description: Represents replicas of the table.
648649
items:
649650
description: Contains the details of the replica.
650651
properties:

generator.yaml

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@ ignore:
1313
- TableDescription.TableClassSummary
1414
- CreateTableInput.ResourcePolicy
1515
- CreateTableInput.WarmThroughput
16+
custom_shapes:
17+
RepicaState:
18+
RegionName: string
19+
RegionStatus: string
20+
RegionStatusDescription: string
21+
RegionStatusPercentProgress: string
22+
RegionInaccessibleDateTime: string
1623
operations:
1724
UpdateGlobalTable:
1825
operation_type:
@@ -25,15 +32,11 @@ operations:
2532
resources:
2633
Table:
2734
fields:
28-
Replicas:
35+
ReplicationGroup:
2936
custom_field:
3037
list_of: CreateReplicationGroupMemberAction
3138
compare:
3239
is_ignored: true
33-
ReplicasDescriptions:
34-
custom_field:
35-
list_of: ReplicaDescription
36-
is_read_only: true
3740
GlobalSecondaryIndexesDescriptions:
3841
custom_field:
3942
list_of: GlobalSecondaryIndexDescription
@@ -73,7 +76,7 @@ resources:
7376
references:
7477
service_name: kms
7578
resource: Key
76-
path: Status.ACKResourceMetadata.ARN
79+
path: Status.ACKResourceMetadata.ARN
7780
exceptions:
7881
errors:
7982
404:

helm/crds/dynamodb.services.k8s.aws_tables.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ spec:
326326
format: int64
327327
type: integer
328328
type: object
329-
replicas:
329+
replicationGroup:
330330
items:
331331
description: Represents a replica to be created.
332332
properties:
@@ -648,7 +648,8 @@ spec:
648648
649649
* StreamLabel
650650
type: string
651-
replicasDescriptions:
651+
replicas:
652+
description: Represents replicas of the table.
652653
items:
653654
description: Contains the details of the replica.
654655
properties:

pkg/resource/table/hooks.go

Lines changed: 22 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ package table
1515

1616
import (
1717
"context"
18+
"errors"
1819
"fmt"
1920
"strings"
2021
"time"
@@ -51,7 +52,7 @@ var (
5152
svcsdktypes.IndexStatusCreating,
5253
)
5354
ErrReplicaNotActive = fmt.Errorf(
54-
"table replica in NOT '%v' state, cannot be modified or deleted",
55+
"table replica isn't in '%v' state, cannot be modified or deleted",
5556
svcsdktypes.ReplicaStatusActive,
5657
)
5758
)
@@ -106,34 +107,16 @@ func tableHasTerminalStatus(r *resource) bool {
106107
return false
107108
}
108109

109-
// isTableCreating returns true if the supplied DynamodbDB table is in the process
110-
// of being created
111-
func isTableCreating(r *resource) bool {
110+
// canUpdateTable returns true if the supplied DynamoDB table is in a state that can be updated
111+
// (not creating, updating, or deleting)
112+
func canUpdateTable(r *resource) bool {
112113
if r.ko.Status.TableStatus == nil {
113114
return false
114115
}
115116
dbis := *r.ko.Status.TableStatus
116-
return dbis == string(v1alpha1.TableStatus_SDK_CREATING)
117-
}
118-
119-
// isTableDeleting returns true if the supplied DynamodbDB table is in the process
120-
// of being deleted
121-
func isTableDeleting(r *resource) bool {
122-
if r.ko.Status.TableStatus == nil {
123-
return false
124-
}
125-
dbis := *r.ko.Status.TableStatus
126-
return dbis == string(v1alpha1.TableStatus_SDK_DELETING)
127-
}
128-
129-
// isTableUpdating returns true if the supplied DynamodbDB table is in the process
130-
// of being deleted
131-
func isTableUpdating(r *resource) bool {
132-
if r.ko.Status.TableStatus == nil {
133-
return false
134-
}
135-
dbis := *r.ko.Status.TableStatus
136-
return dbis == string(v1alpha1.TableStatus_SDK_UPDATING)
117+
return dbis != string(v1alpha1.TableStatus_SDK_CREATING) &&
118+
dbis != string(v1alpha1.TableStatus_SDK_UPDATING) &&
119+
dbis != string(v1alpha1.TableStatus_SDK_DELETING)
137120
}
138121

139122
func (rm *resourceManager) customUpdateTable(
@@ -146,21 +129,12 @@ func (rm *resourceManager) customUpdateTable(
146129
exit := rlog.Trace("rm.customUpdateTable")
147130
defer func(err error) { exit(err) }(err)
148131

149-
if isTableDeleting(latest) {
150-
msg := "table is currently being deleted"
151-
setSyncedCondition(desired, corev1.ConditionFalse, &msg, nil)
152-
return desired, requeueWaitWhileDeleting
153-
}
154-
if isTableCreating(latest) {
155-
msg := "table is currently being created"
156-
setSyncedCondition(desired, corev1.ConditionFalse, &msg, nil)
157-
return desired, requeueWaitWhileCreating
158-
}
159-
if isTableUpdating(latest) {
132+
if !canUpdateTable(latest) {
160133
msg := "table is currently being updated"
161134
setSyncedCondition(desired, corev1.ConditionFalse, &msg, nil)
162135
return desired, requeueWaitWhileUpdating
163136
}
137+
164138
if tableHasTerminalStatus(latest) {
165139
msg := "table is in '" + *latest.ko.Status.TableStatus + "' status"
166140
setTerminalCondition(desired, corev1.ConditionTrue, &msg, nil)
@@ -234,6 +208,13 @@ func (rm *resourceManager) customUpdateTable(
234208
return nil, err
235209
}
236210
case delta.DifferentAt("Spec.Replicas"):
211+
212+
if !hasStreamSpecificationWithNewAndOldImages(desired) {
213+
msg := "table must have DynamoDB Streams enabled with StreamViewType set to NEW_AND_OLD_IMAGES for replica updates"
214+
rlog.Debug(msg)
215+
return nil, ackerr.NewTerminalError(errors.New(msg))
216+
}
217+
237218
if err := rm.syncReplicaUpdates(ctx, latest, desired); err != nil {
238219
return nil, err
239220
}
@@ -572,11 +553,11 @@ func customPreCompare(
572553
}
573554

574555
// Handle ReplicaUpdates comparison
575-
if len(a.ko.Spec.Replicas) != len(b.ko.Spec.Replicas) {
576-
delta.Add("Spec.Replicas", a.ko.Spec.Replicas, b.ko.Spec.Replicas)
577-
} else if a.ko.Spec.Replicas != nil && b.ko.Spec.Replicas != nil {
578-
if !equalReplicaArrays(a.ko.Spec.Replicas, b.ko.Spec.Replicas) {
579-
delta.Add("Spec.Replicas", a.ko.Spec.Replicas, b.ko.Spec.Replicas)
556+
if len(a.ko.Spec.ReplicationGroup) != len(b.ko.Spec.ReplicationGroup) {
557+
delta.Add("Spec.ReplicationGroup", a.ko.Spec.ReplicationGroup, b.ko.Spec.ReplicationGroup)
558+
} else if a.ko.Spec.ReplicationGroup != nil && b.ko.Spec.ReplicationGroup != nil {
559+
if !equalReplicaArrays(a.ko.Spec.ReplicationGroup, b.ko.Spec.ReplicationGroup) {
560+
delta.Add("Spec.ReplicationGroup", a.ko.Spec.ReplicationGroup, b.ko.Spec.ReplicationGroup)
580561
}
581562
}
582563

0 commit comments

Comments
 (0)