Skip to content

Commit 0ea8584

Browse files
committed
feat: Add contributorInsights field to Table resource
1 parent bbd377c commit 0ea8584

15 files changed

+221
-11
lines changed

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
ack_generate_info:
2-
build_date: "2025-03-28T01:43:12Z"
2+
build_date: "2025-04-01T02:35:33Z"
33
build_hash: 980cb1e4734f673d16101cf55206b84ca639ec01
44
go_version: go1.24.1
55
version: v0.44.0
6-
api_directory_checksum: cb49386ebd7bb50e2521072a76262c72b9dbd285
6+
api_directory_checksum: 2f94829f12ad90f9c36c48823459c161c1670093
77
api_version: v1alpha1
88
aws_sdk_go_version: v1.32.6
99
generator_config_info:
10-
file_checksum: 4533fa8aca3b134b5895ad6ce9a093c3446d99da
10+
file_checksum: e7e79c3c7c21273967ca24947fda0f26b344c8f0
1111
original_file_name: generator.yaml
1212
last_modification:
1313
reason: API generation

Diff for: apis/v1alpha1/generator.yaml

+6
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ resources:
7070
service_name: kms
7171
resource: Key
7272
path: Status.ACKResourceMetadata.ARN
73+
ContributorInsights:
74+
from:
75+
operation: UpdateContributorInsights
76+
path: ContributorInsightsAction
7377
exceptions:
7478
errors:
7579
404:
@@ -86,6 +90,8 @@ resources:
8690
template_path: hooks/table/sdk_create_post_set_output.go.tpl
8791
sdk_read_one_post_set_output:
8892
template_path: hooks/table/sdk_read_one_post_set_output.go.tpl
93+
sdk_update_pre_build_request:
94+
template_path: hooks/table/sdk_update_pre_build_request.go.tpl
8995
sdk_delete_pre_build_request:
9096
template_path: hooks/table/sdk_delete_pre_build_request.go.tpl
9197
synced:

Diff for: apis/v1alpha1/table.go

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

Diff for: apis/v1alpha1/zz_generated.deepcopy.go

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

Diff for: config/crd/bases/dynamodb.services.k8s.aws_tables.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ spec:
8888
pointInTimeRecoveryEnabled:
8989
type: boolean
9090
type: object
91+
contributorInsights:
92+
description: Represents the contributor insights action.
93+
type: string
9194
deletionProtectionEnabled:
9295
description: |-
9396
Indicates whether deletion protection is to be enabled (true) or disabled

Diff for: generator.yaml

+6
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ resources:
7070
service_name: kms
7171
resource: Key
7272
path: Status.ACKResourceMetadata.ARN
73+
ContributorInsights:
74+
from:
75+
operation: UpdateContributorInsights
76+
path: ContributorInsightsAction
7377
exceptions:
7478
errors:
7579
404:
@@ -86,6 +90,8 @@ resources:
8690
template_path: hooks/table/sdk_create_post_set_output.go.tpl
8791
sdk_read_one_post_set_output:
8892
template_path: hooks/table/sdk_read_one_post_set_output.go.tpl
93+
sdk_update_pre_build_request:
94+
template_path: hooks/table/sdk_update_pre_build_request.go.tpl
8995
sdk_delete_pre_build_request:
9096
template_path: hooks/table/sdk_delete_pre_build_request.go.tpl
9197
synced:

Diff for: helm/crds/dynamodb.services.k8s.aws_tables.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ spec:
8888
pointInTimeRecoveryEnabled:
8989
type: boolean
9090
type: object
91+
contributorInsights:
92+
description: Represents the contributor insights action.
93+
type: string
9194
deletionProtectionEnabled:
9295
description: |-
9396
Indicates whether deletion protection is to be enabled (true) or disabled

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

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

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

+90
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import (
3131
corev1 "k8s.io/api/core/v1"
3232

3333
"github.com/aws-controllers-k8s/dynamodb-controller/apis/v1alpha1"
34+
svcapitypes "github.com/aws-controllers-k8s/dynamodb-controller/apis/v1alpha1"
3435
)
3536

3637
var (
@@ -136,6 +137,15 @@ func isTableUpdating(r *resource) bool {
136137
return dbis == string(v1alpha1.TableStatus_SDK_UPDATING)
137138
}
138139

140+
func isTableContributorInsightsUpdating(r *resource) bool {
141+
if r.ko.Spec.ContributorInsights == nil {
142+
return false
143+
}
144+
insightStatus := *r.ko.Spec.ContributorInsights
145+
return insightStatus == string(svcsdktypes.ContributorInsightsStatusEnabling) ||
146+
insightStatus == string(svcsdktypes.ContributorInsightsStatusDisabling)
147+
}
148+
139149
func (rm *resourceManager) customUpdateTable(
140150
ctx context.Context,
141151
desired *resource,
@@ -212,6 +222,13 @@ func (rm *resourceManager) customUpdateTable(
212222
}
213223
}
214224

225+
if delta.DifferentAt("Spec.ContributorInsights") {
226+
err = rm.updateContributorInsights(ctx, desired)
227+
if err != nil {
228+
return &resource{ko}, err
229+
}
230+
}
231+
215232
// We want to update fast fields first
216233
// Then attributes
217234
// then GSI
@@ -455,6 +472,9 @@ func (rm *resourceManager) setResourceAdditionalFields(
455472
ko.Spec.ContinuousBackups = pitrSpec
456473
}
457474

475+
if err = rm.setContributorInsights(ctx, ko); err != nil {
476+
return err
477+
}
458478
return nil
459479
}
460480

@@ -590,6 +610,11 @@ func customPreCompare(
590610
if a.ko.Spec.DeletionProtectionEnabled == nil {
591611
a.ko.Spec.DeletionProtectionEnabled = aws.Bool(false)
592612
}
613+
614+
if a.ko.Spec.ContributorInsights == nil &&
615+
*b.ko.Spec.ContributorInsights == string(svcsdktypes.ContributorInsightsActionDisable) {
616+
a.ko.Spec.ContributorInsights = b.ko.Spec.ContributorInsights
617+
}
593618
}
594619

595620
// equalAttributeDefinitions return whether two AttributeDefinition arrays are equal or not.
@@ -724,3 +749,68 @@ func equalLocalSecondaryIndexes(
724749
}
725750
return true
726751
}
752+
753+
// setContributorInsights retrieves the table's cloudformationInsights
754+
// configuration
755+
func (rm *resourceManager) setContributorInsights(
756+
ctx context.Context,
757+
ko *svcapitypes.Table,
758+
) (err error) {
759+
rlog := ackrtlog.FromContext(ctx)
760+
exit := rlog.Trace("rm.setCloudformationInsights")
761+
defer func() {
762+
exit(err)
763+
}()
764+
765+
resp, err := rm.sdkapi.DescribeContributorInsights(
766+
ctx,
767+
&svcsdk.DescribeContributorInsightsInput{
768+
TableName: ko.Spec.TableName,
769+
},
770+
)
771+
rm.metrics.RecordAPICall("READ_ONE", "DescribeContributorInsights", err)
772+
if err != nil {
773+
return err
774+
}
775+
776+
switch resp.ContributorInsightsStatus {
777+
case svcsdktypes.ContributorInsightsStatusEnabled:
778+
ko.Spec.ContributorInsights = aws.String(string(svcsdktypes.ContributorInsightsActionEnable))
779+
case svcsdktypes.ContributorInsightsStatusDisabled:
780+
ko.Spec.ContributorInsights = aws.String(string(svcsdktypes.ContributorInsightsActionDisable))
781+
default:
782+
ko.Spec.ContributorInsights = aws.String(string(resp.ContributorInsightsStatus))
783+
784+
}
785+
786+
return nil
787+
}
788+
789+
func (rm *resourceManager) updateContributorInsights(
790+
ctx context.Context,
791+
r *resource,
792+
) (err error) {
793+
rlog := ackrtlog.FromContext(ctx)
794+
exit := rlog.Trace("rm.updateCloudformationInsights")
795+
defer func() {
796+
exit(err)
797+
}()
798+
insight := svcsdktypes.ContributorInsightsActionDisable
799+
if r.ko.Spec.ContributorInsights != nil {
800+
insight = svcsdktypes.ContributorInsightsAction(*r.ko.Spec.ContributorInsights)
801+
}
802+
803+
_, err = rm.sdkapi.UpdateContributorInsights(
804+
ctx,
805+
&svcsdk.UpdateContributorInsightsInput{
806+
TableName: r.ko.Spec.TableName,
807+
ContributorInsightsAction: insight,
808+
},
809+
)
810+
rm.metrics.RecordAPICall("READ_ONE", "UpdateContributorInsights", err)
811+
if err != nil {
812+
return err
813+
}
814+
815+
return nil
816+
}

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

+11-3
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

+7-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,10 @@
22
if err := rm.syncTTL(ctx, desired, &resource{ko}); err != nil {
33
return nil, err
44
}
5-
}
5+
}
6+
7+
if desired.ko.Spec.ContributorInsights != nil {
8+
if err := rm.updateContributorInsights(ctx, desired); err != nil {
9+
return nil, err
10+
}
11+
}

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,12 @@
5757
if isTableCreating(&resource{ko}) {
5858
return &resource{ko}, requeueWaitWhileCreating
5959
}
60-
if isTableUpdating(&resource{ko}) {
61-
return &resource{ko}, requeueWaitWhileUpdating
62-
}
6360
if !canUpdateTableGSIs(&resource{ko}) {
6461
return &resource{ko}, requeueWaitGSIReady
6562
}
6663
if err := rm.setResourceAdditionalFields(ctx, ko); err != nil {
6764
return nil, err
68-
}
65+
}
66+
if isTableUpdating(&resource{ko}) || isTableContributorInsightsUpdating(&resource{ko}) {
67+
return &resource{ko}, requeueWaitWhileUpdating
68+
}

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

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Table used to test multiple interfering updates at once
2+
apiVersion: dynamodb.services.k8s.aws/v1alpha1
3+
kind: Table
4+
metadata:
5+
name: $TABLE_NAME
6+
spec:
7+
tableName: $TABLE_NAME
8+
billingMode: PAY_PER_REQUEST
9+
tableClass: STANDARD
10+
contributorInsights: ENABLE
11+
attributeDefinitions:
12+
- attributeName: Bill
13+
attributeType: S
14+
- attributeName: Total
15+
attributeType: S
16+
keySchema:
17+
- attributeName: Bill
18+
keyType: HASH
19+
- attributeName: Total
20+
keyType: RANGE

Diff for: test/e2e/table.py

+12
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,18 @@ def get(table_name):
236236
except c.exceptions.ResourceNotFoundException:
237237
return None
238238

239+
def get_insights(table_name):
240+
"""Returns a dict containing the Role record from the IAM API.
241+
242+
If no such Table exists, returns None.
243+
"""
244+
c = boto3.client('dynamodb', region_name=get_region())
245+
try:
246+
resp = c.describe_contributor_insights(TableName=table_name)
247+
return resp['ContributorInsightsStatus']
248+
except c.exceptions.ResourceNotFoundException:
249+
return None
250+
239251

240252
def get_time_to_live(table_name):
241253
"""Returns the TTL specification for the table with a supplied name.

0 commit comments

Comments
 (0)