Skip to content

Commit 97ca266

Browse files
authored
chore: Ensure controller understands both ENABLE & ENABLED contributorInsights (#129)
Description of changes: These changes allow users to define both ENABLE/DISABLE and ENABLED/DISABLED value for the ContributorInsights field. By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent d59d2f5 commit 97ca266

File tree

7 files changed

+46
-24
lines changed

7 files changed

+46
-24
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-04-01T02:35:33Z"
3-
build_hash: 980cb1e4734f673d16101cf55206b84ca639ec01
2+
build_date: "2025-04-08T22:25:51Z"
3+
build_hash: 0909e7f0adb8ffe4120a8c20d5d58b991f2539e9
44
go_version: go1.24.1
5-
version: v0.44.0
5+
version: v0.44.0-3-g0909e7f
66
api_directory_checksum: 2f94829f12ad90f9c36c48823459c161c1670093
77
api_version: v1alpha1
88
aws_sdk_go_version: v1.32.6
99
generator_config_info:
10-
file_checksum: e7e79c3c7c21273967ca24947fda0f26b344c8f0
10+
file_checksum: cc3489b53a45170d339a4de0d7d7ec0aa788955e
1111
original_file_name: generator.yaml
1212
last_modification:
1313
reason: API generation

Diff for: apis/v1alpha1/generator.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ resources:
7474
from:
7575
operation: UpdateContributorInsights
7676
path: ContributorInsightsAction
77+
compare:
78+
is_ignored: true
7779
exceptions:
7880
errors:
7981
404:

Diff for: generator.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ resources:
7474
from:
7575
operation: UpdateContributorInsights
7676
path: ContributorInsightsAction
77+
compare:
78+
is_ignored: true
7779
exceptions:
7880
errors:
7981
404:

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

+34-11
Original file line numberDiff line numberDiff line change
@@ -615,8 +615,16 @@ func customPreCompare(
615615
// This will ensure controller does not act on this field
616616
// if user is unaware of it.
617617
if a.ko.Spec.ContributorInsights == nil {
618-
a.ko.Spec.ContributorInsights = b.ko.Spec.ContributorInsights
618+
return
619619
}
620+
// latestInsight will always be either ENABLED or DISABLED, since we requeue at readOne if its not
621+
// either
622+
desiredInsight, _ := ensureContibutorInsight(a)
623+
latestInsight, _ := ensureContibutorInsight(b)
624+
if desiredInsight != latestInsight {
625+
delta.Add("Spec.ContributorInsights", a.ko.Spec.ContributorInsights, b.ko.Spec.ContributorInsights)
626+
}
627+
620628
}
621629

622630
// equalAttributeDefinitions return whether two AttributeDefinition arrays are equal or not.
@@ -775,19 +783,33 @@ func (rm *resourceManager) setContributorInsights(
775783
return err
776784
}
777785

778-
switch resp.ContributorInsightsStatus {
779-
case svcsdktypes.ContributorInsightsStatusEnabled:
780-
ko.Spec.ContributorInsights = aws.String(string(svcsdktypes.ContributorInsightsActionEnable))
781-
case svcsdktypes.ContributorInsightsStatusDisabled:
782-
ko.Spec.ContributorInsights = aws.String(string(svcsdktypes.ContributorInsightsActionDisable))
783-
default:
786+
// Only manage ContributorInsights if it is defined
787+
if ko.Spec.ContributorInsights != nil {
784788
ko.Spec.ContributorInsights = aws.String(string(resp.ContributorInsightsStatus))
785-
786789
}
787790

788791
return nil
789792
}
790793

794+
// ensureContibutorInsight ensures the controller understands ENABLE and ENABLED are the same.
795+
// We choose to return ContributorInsightsAction because that is the enum used to update.
796+
func ensureContibutorInsight(r *resource) (svcsdktypes.ContributorInsightsAction, error) {
797+
insight := svcsdktypes.ContributorInsightsActionDisable
798+
if r.ko.Spec.ContributorInsights != nil {
799+
// We will allow users to provide values ENABLE, ENABLED, DISABLE, DISABLED
800+
switch *r.ko.Spec.ContributorInsights {
801+
case string(svcsdktypes.ContributorInsightsActionEnable), string(svcsdktypes.ContributorInsightsStatusEnabled):
802+
insight = svcsdktypes.ContributorInsightsActionEnable
803+
case string(svcsdktypes.ContributorInsightsActionDisable), string(svcsdktypes.ContributorInsightsStatusDisabled):
804+
insight = svcsdktypes.ContributorInsightsActionDisable
805+
default:
806+
return "", fmt.Errorf("invalid ContributorInsights value: %s", *r.ko.Spec.ContributorInsights)
807+
}
808+
}
809+
810+
return insight, nil
811+
}
812+
791813
func (rm *resourceManager) updateContributorInsights(
792814
ctx context.Context,
793815
r *resource,
@@ -797,9 +819,10 @@ func (rm *resourceManager) updateContributorInsights(
797819
defer func() {
798820
exit(err)
799821
}()
800-
insight := svcsdktypes.ContributorInsightsActionDisable
801-
if r.ko.Spec.ContributorInsights != nil {
802-
insight = svcsdktypes.ContributorInsightsAction(*r.ko.Spec.ContributorInsights)
822+
823+
insight, err := ensureContibutorInsight(r)
824+
if err != nil {
825+
return fmt.Errorf("failed preparing contributorInsight: %v", err)
803826
}
804827

805828
_, err = rm.sdkapi.UpdateContributorInsights(

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ spec:
77
tableName: $TABLE_NAME
88
billingMode: PAY_PER_REQUEST
99
tableClass: STANDARD
10-
contributorInsights: ENABLE
10+
contributorInsights: ENABLED
1111
attributeDefinitions:
1212
- attributeName: Bill
1313
attributeType: S

Diff for: test/e2e/tests/test_table.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,8 @@ def test_enable_ttl(self, table_lsi):
279279
# Patch k8s resource
280280
k8s.patch_custom_resource(ref, updates)
281281

282+
time.sleep(MODIFY_WAIT_AFTER_SECONDS)
283+
282284
table.wait_until(
283285
table_name,
284286
table.ttl_on_attribute_matches("ForumName"),
@@ -480,7 +482,7 @@ def test_update_insights(self, table_insights):
480482

481483
# Check DynamoDB Table exists
482484
assert self.table_exists(table_name)
483-
assert cr['spec']['contributorInsights'] == "ENABLE"
485+
assert cr['spec']['contributorInsights'] == "ENABLED"
484486
assert self.table_insight_status(table_name, "ENABLED")
485487

486488
# Set provisionedThroughput

0 commit comments

Comments
 (0)