Skip to content

Commit ca89ad3

Browse files
committed
add tests
1 parent 3cc1a09 commit ca89ad3

15 files changed

+456
-50
lines changed

Diff for: apis/v1alpha1/ack-generate-metadata.yaml

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
ack_generate_info:
2-
build_date: "2025-03-12T23:25:20Z"
3-
build_hash: 5645e51ed3c413f616e1b929f1527a5139c44198
2+
build_date: "2025-03-14T22:49:47Z"
3+
build_hash: 0ab258c51775fd52af32e649da00d57373b20869
44
go_version: go1.24.0
5-
version: v0.43.2-3-g5645e51
5+
version: v0.43.2-6-g0ab258c
66
api_directory_checksum: 0d5b95bdbe63c6cfc495149b7a86440c4a5fb33a
77
api_version: v1alpha1
88
aws_sdk_go_version: v1.32.6
99
generator_config_info:
10-
file_checksum: 48323d41b9cb7ade08c8a87367846cccdd1f6409
10+
file_checksum: 85db04e11e016a28a99058aab04767cf8345242e
1111
original_file_name: generator.yaml
1212
last_modification:
1313
reason: API generation

Diff for: apis/v1alpha1/generator.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ resources:
8080
code: ResourceNotFoundException
8181
terminal_codes:
8282
- InvalidParameter
83+
- ValidationException
8384
update_operation:
8485
custom_method_name: customUpdateTable
8586
hooks:

Diff for: generator.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ resources:
8080
code: ResourceNotFoundException
8181
terminal_codes:
8282
- InvalidParameter
83+
- ValidationException
8384
update_operation:
8485
custom_method_name: customUpdateTable
8586
hooks:

Diff for: pkg/resource/table/hooks.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ var (
7878
)
7979
requeueWaitWhileUpdating = ackrequeue.NeededAfter(
8080
ErrTableUpdating,
81-
5*time.Second,
81+
10*time.Second,
8282
)
8383
requeueWaitGSIReady = ackrequeue.NeededAfter(
8484
ErrTableGSIsUpdating,

Diff for: pkg/resource/table/hooks_replica_updates.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import (
77
ackerr "github.com/aws-controllers-k8s/runtime/pkg/errors"
88
ackrtlog "github.com/aws-controllers-k8s/runtime/pkg/runtime/log"
99

10-
"github.com/aws/aws-sdk-go-v2/aws"
1110
"github.com/aws-controllers-k8s/dynamodb-controller/apis/v1alpha1"
11+
"github.com/aws/aws-sdk-go-v2/aws"
1212
svcsdk "github.com/aws/aws-sdk-go-v2/service/dynamodb"
1313
svcsdktypes "github.com/aws/aws-sdk-go-v2/service/dynamodb/types"
1414
)

Diff for: pkg/resource/table/manager.go

+7-7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: pkg/resource/table/sdk.go

+2-8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: pkg/resource/table/tags.go

+28-16
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: templates/hooks/table/sdk_create_post_set_output.go.tpl

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
}
66
// Check if replicas were specified during creation
77
if desired.ko.Spec.Replicas != nil && len(desired.ko.Spec.Replicas) > 0 {
8-
// Copy the replica configuration to the new resource
98
ko.Spec.Replicas = desired.ko.Spec.Replicas
109
1110
// Return with a requeue to process replica updates

Diff for: templates/hooks/table/sdk_delete_pre_build_request.go.tpl

-6
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,13 @@
77

88
// If there are replicas, we need to remove them before deleting the table
99
if r.ko.Spec.Replicas != nil && len(r.ko.Spec.Replicas) > 0 {
10-
// Create a desired state with no replicas
1110
desired := &resource{
1211
ko: r.ko.DeepCopy(),
1312
}
1413
desired.ko.Spec.Replicas = nil
1514

16-
// Call syncReplicaUpdates to remove all replicas
1715
err := rm.syncReplicaUpdates(ctx, r, desired)
1816
if err != nil {
19-
if err == requeueWaitWhileUpdating {
20-
// This is expected - we need to wait for the replica removal to complete
21-
return nil, err
22-
}
2317
return nil, err
2418
}
2519
}

Diff for: templates/hooks/table/sdk_read_one_post_set_output.go.tpl

-6
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,6 @@
8080
} else {
8181
f12elem.ReplicaInaccessibleDateTime = nil
8282
}
83-
if f12iter.ReplicaTableClassSummary != nil && f12iter.ReplicaTableClassSummary.TableClass != "" {
84-
f12elem.ReplicaTableClassSummary.TableClass = aws.String(string(f12iter.ReplicaTableClassSummary.TableClass))
85-
f12elem.ReplicaTableClassSummary.LastUpdateDateTime = &metav1.Time{Time: *f12iter.ReplicaTableClassSummary.LastUpdateDateTime}
86-
} else {
87-
f12elem.ReplicaTableClassSummary.TableClass = aws.String("STANDARD")
88-
}
8983
f12 = append(f12, f12elem)
9084
}
9185
ko.Status.ReplicasDescriptions = f12

Diff for: test/e2e/resources/table_with_replicas.yaml

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
apiVersion: dynamodb.services.k8s.aws/v1alpha1
2+
kind: Table
3+
metadata:
4+
name: $TABLE_NAME
5+
spec:
6+
tableName: $TABLE_NAME
7+
tableClass: STANDARD
8+
attributeDefinitions:
9+
- attributeName: PK
10+
attributeType: S
11+
- attributeName: SK
12+
attributeType: S
13+
keySchema:
14+
- attributeName: PK
15+
keyType: HASH
16+
- attributeName: SK
17+
keyType: RANGE
18+
billingMode: PAY_PER_REQUEST
19+
streamSpecification:
20+
streamEnabled: true
21+
streamViewType: "NEW_AND_OLD_IMAGES"
22+
replicas:
23+
- regionName: $REPLICA_REGION_1

Diff for: test/e2e/resources/table_with_replicas_invalid.yaml

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
apiVersion: dynamodb.services.k8s.aws/v1alpha1
2+
kind: Table
3+
metadata:
4+
name: $TABLE_NAME
5+
spec:
6+
tableName: $TABLE_NAME
7+
tableClass: STANDARD
8+
attributeDefinitions:
9+
- attributeName: PK
10+
attributeType: S
11+
- attributeName: SK
12+
attributeType: S
13+
keySchema:
14+
- attributeName: PK
15+
keyType: HASH
16+
- attributeName: SK
17+
keyType: RANGE
18+
billingMode: PAY_PER_REQUEST
19+
replicas:
20+
- regionName: $REPLICA_REGION_1

Diff for: test/e2e/table.py

+58
Original file line numberDiff line numberDiff line change
@@ -260,3 +260,61 @@ def get_point_in_time_recovery_enabled(table_name):
260260
return resp['ContinuousBackupsDescription']['PointInTimeRecoveryDescription']['PointInTimeRecoveryStatus'] == 'ENABLED'
261261
except c.exceptions.ResourceNotFoundException:
262262
return None
263+
264+
265+
class ReplicaMatcher:
266+
def __init__(self, expected_regions):
267+
self.expected_regions = expected_regions
268+
269+
def __call__(self, record: dict) -> bool:
270+
if 'Replicas' not in record:
271+
return False
272+
273+
actual_regions = set()
274+
for replica in record['Replicas']:
275+
if 'RegionName' in replica:
276+
actual_regions.add(replica['RegionName'])
277+
278+
return set(self.expected_regions) == actual_regions
279+
280+
281+
def replicas_match(expected_regions) -> TableMatchFunc:
282+
return ReplicaMatcher(expected_regions)
283+
284+
285+
class ReplicaStatusMatcher:
286+
def __init__(self, region, status):
287+
self.region = region
288+
self.status = status
289+
290+
def __call__(self, record: dict) -> bool:
291+
if 'Replicas' not in record:
292+
return False
293+
294+
for replica in record['Replicas']:
295+
if 'RegionName' in replica and replica['RegionName'] == self.region:
296+
return 'ReplicaStatus' in replica and replica['ReplicaStatus'] == self.status
297+
298+
return False
299+
300+
301+
def replica_status_matches(region, status) -> TableMatchFunc:
302+
return ReplicaStatusMatcher(region, status)
303+
304+
305+
def get_replicas(table_name):
306+
"""Returns the replicas for a DynamoDB table
307+
308+
Args:
309+
table_name: the name of the DynamoDB table to get replicas for
310+
Returns:
311+
A list of replicas or None if the table doesn't exist
312+
"""
313+
dynamodb = boto3.client('dynamodb')
314+
try:
315+
response = dynamodb.describe_table(TableName=table_name)
316+
if 'Table' in response and 'Replicas' in response['Table']:
317+
return response['Table']['Replicas']
318+
return []
319+
except dynamodb.exceptions.ResourceNotFoundException:
320+
return None

0 commit comments

Comments
 (0)