Skip to content

Commit 1dfe7bd

Browse files
authored
handle asynchronous updates for DBInstance by requeueing (#65)
Issue [#1156](aws-controllers-k8s/community#1156) Description of changes: * During DBInstance update, when `ModifyDBInstance` call returns success then the ACK reconciler marks the resource as Synced and the reconciliation stops. However asynchronous update of DBInstance happens on server side and the ACK reconciler does not sync them. * Add two new hooks, one to requeue after successful update and another to handle delta for non-late-initialized fields. * I did not use the `requeueOnSuccessSeconds` construct because it will cause the reconciliation to go forever and for some amount of time, the resource condition will be synced, even when the DBInstance is in modifying state. * Do not set Synced condition true inside post_read_many hook, but depend on `ensureConditions` method **Test Updates** * Update test manifest to use smaller storage to improve the test time and use engine version 14.1 because engine version 13.2 was throwing unsupported errors * Added e2e test for 'MultiAZ' field update as mentioned in the issue [#1156](aws-controllers-k8s/community#1156) * Updated the test to wait for Synced condition and then assert DBInstance fields using AWS API calls By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent 9634b96 commit 1dfe7bd

File tree

11 files changed

+93
-21
lines changed

11 files changed

+93
-21
lines changed
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
ack_generate_info:
2-
build_date: "2022-03-02T19:31:05Z"
2+
build_date: "2022-03-05T00:11:28Z"
33
build_hash: ade2429bb444ab635916395ea5773d141ba135e1
44
go_version: go1.17.5
55
version: v0.17.2
66
api_directory_checksum: c5762d0b5707ca20866f2f0e85bc23863733ca11
77
api_version: v1alpha1
88
aws_sdk_go_version: v1.42.0
99
generator_config_info:
10-
file_checksum: a0cccebb7e683a3b9b6082b5cde6630fd5ad4237
10+
file_checksum: 3afea95265e7836112e0b1e37166290f18511d09
1111
original_file_name: generator.yaml
1212
last_modification:
1313
reason: API generation

apis/v1alpha1/generator.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,12 @@ resources:
122122
template_path: hooks/db_instance/sdk_update_pre_build_request.go.tpl
123123
sdk_update_post_build_request:
124124
template_path: hooks/db_instance/sdk_update_post_build_request.go.tpl
125+
sdk_update_post_set_output:
126+
template_path: hooks/db_instance/sdk_update_post_set_output.go.tpl
125127
sdk_delete_pre_build_request:
126128
template_path: hooks/db_instance/sdk_delete_pre_build_request.go.tpl
129+
delta_pre_compare:
130+
template_path: hooks/db_instance/delta_pre_compare.go.tpl
127131
exceptions:
128132
terminal_codes:
129133
- InvalidParameter

generator.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,12 @@ resources:
122122
template_path: hooks/db_instance/sdk_update_pre_build_request.go.tpl
123123
sdk_update_post_build_request:
124124
template_path: hooks/db_instance/sdk_update_post_build_request.go.tpl
125+
sdk_update_post_set_output:
126+
template_path: hooks/db_instance/sdk_update_post_set_output.go.tpl
125127
sdk_delete_pre_build_request:
126128
template_path: hooks/db_instance/sdk_delete_pre_build_request.go.tpl
129+
delta_pre_compare:
130+
template_path: hooks/db_instance/delta_pre_compare.go.tpl
127131
exceptions:
128132
terminal_codes:
129133
- InvalidParameter

pkg/resource/db_instance/delta.go

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

pkg/resource/db_instance/hooks.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,12 @@ var (
9090
errors.New("DB instance in 'deleting' state, cannot be modified or deleted."),
9191
ackrequeue.DefaultRequeueAfterDuration,
9292
)
93+
94+
customWaitAtferUpdate = ackrequeue.NeededAfter(
95+
errors.New("Requeueing resource after successful update; status fields "+
96+
"retrieved asynchronously"),
97+
ackrequeue.DefaultRequeueAfterDuration,
98+
)
9399
)
94100

95101
// requeueWaitUntilCanModify returns a `ackrequeue.RequeueNeededAfter` struct

pkg/resource/db_instance/sdk.go

Lines changed: 8 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Do not consider AvailabilityZone field for delta if it is missing in
2+
// desired(a) and is present in latest(b) because AvailabilityZone field is
3+
// late-initialized
4+
// This special handling is only needed for DBInstance because a requeue
5+
// error needs to be returned even after successful ModifyDBInstance call.
6+
// See sdk_update_post_set_output.go.tpl for more details.
7+
// The requeue error from update prevents the late initialization in
8+
// reconciler.go and without ignoring AvailabilityZone for delta , the
9+
// reconciler will keep updating the dbinstance and constantly requeueing it.
10+
if a != nil && a.ko.Spec.AvailabilityZone == nil && b != nil && b.ko.Spec.AvailabilityZone != nil {
11+
a.ko.Spec.AvailabilityZone = b.ko.Spec.AvailabilityZone
12+
}

templates/hooks/db_instance/sdk_read_many_post_set_output.go.tpl

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,5 @@
22
// Setting resource synced condition to false will trigger a requeue of
33
// the resource. No need to return a requeue error here.
44
ackcondition.SetSynced(&resource{ko}, corev1.ConditionFalse, nil, nil)
5-
} else {
6-
ackcondition.SetSynced(&resource{ko}, corev1.ConditionTrue, nil, nil)
7-
}
5+
}
86

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// If there was no error during update, requeue the request.
2+
// When ModifyDBInstance API is successful, it asynchronously
3+
// updates the DBInstanceStatus. Requeue to find the current
4+
// DBInstance status and set Synced condition accordingly
5+
if err == nil {
6+
return &resource{ko}, customWaitAtferUpdate
7+
}

test/e2e/resources/db_instance_postgres13_t3_micro.yaml renamed to test/e2e/resources/db_instance_postgres14_t3_micro.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,16 @@ kind: DBInstance
33
metadata:
44
name: $DB_INSTANCE_ID
55
spec:
6-
allocatedStorage: 20
6+
allocatedStorage: 5
77
copyTagsToSnapshot: $COPY_TAGS_TO_SNAPSHOT
88
dbInstanceClass: db.t3.micro
99
dbInstanceIdentifier: $DB_INSTANCE_ID
1010
dbSubnetGroupName: $DB_SUBNET_GROUP_NAME
1111
engine: postgres
12-
engineVersion: "13.2"
12+
engineVersion: "14.1"
1313
masterUsername: root
1414
masterUserPassword:
1515
namespace: $MASTER_USER_PASS_SECRET_NAMESPACE
1616
name: $MASTER_USER_PASS_SECRET_NAME
1717
key: $MASTER_USER_PASS_SECRET_KEY
18+
multiAZ: False

0 commit comments

Comments
 (0)