Skip to content

Commit 4ac9aa8

Browse files
authored
ensure all resources sync for RDS (#143)
This patch fixes both the DB Parameter Group and the DB Cluster Parameter Group resources failure to properly get to ACK.ResourceSynced=True quickly and reliably. I removed the manual requeueWhileCreating condition for both Param Group and Cluster Param Group resources, replacing that sdk_create_post_set_output hook with a call to `syncParameters`, supplying a `nil` `latest` parameter. This allowed the parameter overrides to be immediately set after the parameter group was created. Added a lengthy e2e test for RDS resource references based on the YAML definitions present in the related issue (aws-controllers-k8s/community#1727) with a DBCluster resource that references a DB Cluster Parameter Group, a DBInstance resource that references a DB Parameter Group (by AWSResourceReference) and the DB Cluster (by DBClusterIdentifier). Fixes Issue aws-controllers-k8s/community#1727 By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent 9106387 commit 4ac9aa8

File tree

16 files changed

+406
-31
lines changed

16 files changed

+406
-31
lines changed

apis/v1alpha1/ack-generate-metadata.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
ack_generate_info:
2-
build_date: "2023-03-22T21:52:47Z"
2+
build_date: "2023-03-24T19:44:43Z"
33
build_hash: fa24753ea8b657d8815ae3eac7accd0958f5f9fb
4-
go_version: go1.19
4+
go_version: go1.19.4
55
version: v0.25.0
66
api_directory_checksum: 249bb23477dbb69a88064ea191a078f41f4966d0
77
api_version: v1alpha1

pkg/resource/db_cluster_parameter_group/hooks.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -216,12 +216,18 @@ func (rm *resourceManager) syncParameters(
216216
exit := rlog.Trace("rm.syncParameters")
217217
defer func() { exit(err) }()
218218

219-
groupName := latest.ko.Spec.Name
220-
family := latest.ko.Spec.Family
219+
groupName := desired.ko.Spec.Name
220+
family := desired.ko.Spec.Family
221+
222+
desiredOverrides := desired.ko.Spec.ParameterOverrides
223+
latestOverrides := util.Parameters{}
224+
// In the create code paths, we pass a nil latest...
225+
if latest != nil {
226+
latestOverrides = latest.ko.Spec.ParameterOverrides
227+
}
221228

222229
toModify, _, toDelete := util.GetParametersDifference(
223-
desired.ko.Spec.ParameterOverrides,
224-
latest.ko.Spec.ParameterOverrides,
230+
desiredOverrides, latestOverrides,
225231
)
226232

227233
if len(toDelete) > 0 {

pkg/resource/db_cluster_parameter_group/sdk.go

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

pkg/resource/db_parameter_group/hooks.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -215,12 +215,18 @@ func (rm *resourceManager) syncParameters(
215215
exit := rlog.Trace("rm.syncParameters")
216216
defer func() { exit(err) }()
217217

218-
groupName := latest.ko.Spec.Name
219-
family := latest.ko.Spec.Family
218+
groupName := desired.ko.Spec.Name
219+
family := desired.ko.Spec.Family
220+
221+
desiredOverrides := desired.ko.Spec.ParameterOverrides
222+
latestOverrides := util.Parameters{}
223+
// In the create code paths, we pass a nil latest...
224+
if latest != nil {
225+
latestOverrides = latest.ko.Spec.ParameterOverrides
226+
}
220227

221228
toModify, _, toDelete := util.GetParametersDifference(
222-
desired.ko.Spec.ParameterOverrides,
223-
latest.ko.Spec.ParameterOverrides,
229+
desiredOverrides, latestOverrides,
224230
)
225231

226232
// NOTE(jaypipes): ResetDBParameterGroup and ModifyDBParameterGroup only

pkg/resource/db_parameter_group/sdk.go

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// We need to instantly requeue after a create operation, otherwise the controller
2-
// will override the latest resource with the desired resource overrideParameters
3-
// and cause the controller to not properly compare latest and desired resources.
4-
return &resource{ko}, requeueWaitWhileCreating
1+
if err = rm.syncParameters(ctx, desired, nil); err != nil {
2+
return nil, err
3+
}
Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// We need to instantly requeue after a create operation, otherwise the controller
2-
// will override the latest resource with the desired resource overrideParameters
3-
// and cause the controller to not properly compare latest and desired resources.
4-
return &resource{ko}, requeueWaitWhileCreating
1+
if err = rm.syncParameters(ctx, desired, nil); err != nil {
2+
return nil, err
3+
}

test/e2e/db_cluster.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ def __init__(self, status):
3535
self.match_on = status
3636

3737
def __call__(self, record: dict) -> bool:
38-
return 'Status' in record and record['Status'] == self.match_on
38+
return (record is not None and 'Status' in record
39+
and record['Status'] == self.match_on)
3940

4041

4142
def status_matches(status: str) -> ClusterMatchFunc:

test/e2e/db_instance.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
DEFAULT_WAIT_UNTIL_TIMEOUT_SECONDS = 60*30
2424
DEFAULT_WAIT_UNTIL_INTERVAL_SECONDS = 15
25-
DEFAULT_WAIT_UNTIL_DELETED_TIMEOUT_SECONDS = 60*10
25+
DEFAULT_WAIT_UNTIL_DELETED_TIMEOUT_SECONDS = 60*20
2626
DEFAULT_WAIT_UNTIL_DELETED_INTERVAL_SECONDS = 15
2727

2828
InstanceMatchFunc = typing.NewType(
@@ -35,7 +35,7 @@ def __init__(self, status):
3535
self.match_on = status
3636

3737
def __call__(self, record: dict) -> bool:
38-
return ('DBInstanceStatus' in record
38+
return (record is not None and 'DBInstanceStatus' in record
3939
and record['DBInstanceStatus'] == self.match_on)
4040

4141

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
apiVersion: rds.services.k8s.aws/v1alpha1
2+
kind: DBClusterParameterGroup
3+
metadata:
4+
name: $DB_CLUSTER_PARAMETER_GROUP_NAME
5+
spec:
6+
name: $DB_CLUSTER_PARAMETER_GROUP_NAME
7+
description: $DB_CLUSTER_PARAMETER_GROUP_DESC
8+
family: aurora-postgresql14

0 commit comments

Comments
 (0)