Skip to content

Commit 647df8e

Browse files
committed
correct delta_pre_compare for DBInstance
In PR #95, we added a `customPreCompare` function to `pkg/resource/db_instance/hooks.go` and changed the `generator.yaml` to use a code snippet instead of the `templates/hooks/db_instance/delta_pre_compare.go.tpl` template file. However, we did not delete the `templates/hooks/db_instance/delta_pre_compare.go.tpl` file and when I went to do the updating DB instance tags patch, mobody noticed that I had added a call to `compareTags` into the (now-unused) template file. This meant that `compareTags` is never called which means changes to tags were not being properly on DBInstance resources. This patch moves all the custom code for delta pre-checks back into the template file and gets rid of the custom code snippet in generator.yaml, consolidating all this logic into the template file. Signed-off-by: Jay Pipes <[email protected]>
1 parent f0864ae commit 647df8e

File tree

8 files changed

+83
-68
lines changed

8 files changed

+83
-68
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-08-04T21:32:49Z"
2+
build_date: "2022-08-13T17:21:53Z"
33
build_hash: fe61d04673fd4d9848d5f726b01e0689a16d3733
44
go_version: go1.18.1
55
version: v0.19.3-1-gfe61d04
66
api_directory_checksum: 6a967cc8a62d521d4f4816dbccc48f81d0cb271d
77
api_version: v1alpha1
88
aws_sdk_go_version: v1.44.27
99
generator_config_info:
10-
file_checksum: dc22b2b5295201b27341f95c1cec0b0dcead98b3
10+
file_checksum: 48d8a87d42545d99ddabf9bea4ab180e08ab79b7
1111
original_file_name: generator.yaml
1212
last_modification:
1313
reason: API generation

apis/v1alpha1/generator.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,8 @@ resources:
183183
is_ignored: true
184184
DBInstance:
185185
hooks:
186+
delta_pre_compare:
187+
template_path: hooks/db_instance/delta_pre_compare.go.tpl
186188
sdk_create_pre_build_request:
187189
template_path: hooks/db_instance/sdk_create_pre_build_request.go.tpl
188190
sdk_create_post_set_output:
@@ -199,8 +201,6 @@ resources:
199201
template_path: hooks/db_instance/sdk_delete_pre_build_request.go.tpl
200202
sdk_file_end:
201203
template_path: hooks/db_instance/sdk_file_end.go.tpl
202-
delta_pre_compare:
203-
code: customPreCompare(a, b)
204204
exceptions:
205205
terminal_codes:
206206
- InvalidParameter

generator.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,8 @@ resources:
183183
is_ignored: true
184184
DBInstance:
185185
hooks:
186+
delta_pre_compare:
187+
template_path: hooks/db_instance/delta_pre_compare.go.tpl
186188
sdk_create_pre_build_request:
187189
template_path: hooks/db_instance/sdk_create_pre_build_request.go.tpl
188190
sdk_create_post_set_output:
@@ -199,8 +201,6 @@ resources:
199201
template_path: hooks/db_instance/sdk_delete_pre_build_request.go.tpl
200202
sdk_file_end:
201203
template_path: hooks/db_instance/sdk_file_end.go.tpl
202-
delta_pre_compare:
203-
code: customPreCompare(a, b)
204204
exceptions:
205205
terminal_codes:
206206
- InvalidParameter

pkg/resource/db_instance/delta.go

Lines changed: 37 additions & 1 deletion
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: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -384,45 +384,6 @@ func (rm *resourceManager) createDBInstanceReadReplica(
384384
return &resource{r.ko}, nil
385385
}
386386

387-
func customPreCompare(a *resource, b *resource) {
388-
// Do not consider any of the following fields for delta if they are missing in
389-
// desired(a) but are present in latest(b) because each of these fields is
390-
// late-initialized
391-
// This special handling is only needed for DBInstance because late
392-
// initialized values are not returned after successful ModifyDBInstance
393-
// call. They are only populated once the DBInstance returns back to
394-
// available.
395-
if a.ko.Spec.AvailabilityZone == nil &&
396-
b.ko.Spec.AvailabilityZone != nil {
397-
a.ko.Spec.AvailabilityZone = b.ko.Spec.AvailabilityZone
398-
}
399-
if a.ko.Spec.BackupTarget == nil &&
400-
b.ko.Spec.BackupTarget != nil &&
401-
*b.ko.Spec.BackupTarget == ServiceDefaultBackupTarget {
402-
a.ko.Spec.BackupTarget = b.ko.Spec.BackupTarget
403-
}
404-
if a.ko.Spec.NetworkType == nil &&
405-
b.ko.Spec.NetworkType != nil &&
406-
*b.ko.Spec.NetworkType == ServiceDefaultNetworkType {
407-
a.ko.Spec.NetworkType = b.ko.Spec.NetworkType
408-
}
409-
if a.ko.Spec.PerformanceInsightsRetentionPeriod == nil &&
410-
b.ko.Spec.PerformanceInsightsRetentionPeriod != nil &&
411-
*b.ko.Spec.PerformanceInsightsRetentionPeriod == ServiceDefaultInsightsRetentionPeriod {
412-
a.ko.Spec.PerformanceInsightsRetentionPeriod = b.ko.Spec.PerformanceInsightsRetentionPeriod
413-
}
414-
if a.ko.Spec.PerformanceInsightsKMSKeyID == nil &&
415-
b.ko.Spec.PerformanceInsightsKMSKeyID != nil {
416-
a.ko.Spec.PerformanceInsightsKMSKeyID = b.ko.Spec.PerformanceInsightsKMSKeyID
417-
}
418-
419-
// RDS will choose preferred engine minor version if only
420-
// engine major version is provided and controler should not
421-
// treat them as different, such as spec has 14, status has 14.1
422-
// controller should treat them as same
423-
reconcileEngineVersion(a, b)
424-
}
425-
426387
// RDS will choose preferred engine minor version if only
427388
// engine major version is provided and controler should not
428389
// treat them as different, such as spec has 14, status has 14.1

pkg/resource/db_instance/sdk.go

Lines changed: 0 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,37 @@
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-
}
1+
// Do not consider any of the following fields for delta if they are missing in
2+
// desired(a) but are present in latest(b) because each of these fields is
3+
// late-initialized
4+
// This special handling is only needed for DBInstance because late
5+
// initialized values are not returned after successful ModifyDBInstance
6+
// call. They are only populated once the DBInstance returns back to
7+
// available.
8+
if a.ko.Spec.AvailabilityZone == nil &&
9+
b.ko.Spec.AvailabilityZone != nil {
10+
a.ko.Spec.AvailabilityZone = b.ko.Spec.AvailabilityZone
11+
}
12+
if a.ko.Spec.BackupTarget == nil &&
13+
b.ko.Spec.BackupTarget != nil &&
14+
*b.ko.Spec.BackupTarget == ServiceDefaultBackupTarget {
15+
a.ko.Spec.BackupTarget = b.ko.Spec.BackupTarget
16+
}
17+
if a.ko.Spec.NetworkType == nil &&
18+
b.ko.Spec.NetworkType != nil &&
19+
*b.ko.Spec.NetworkType == ServiceDefaultNetworkType {
20+
a.ko.Spec.NetworkType = b.ko.Spec.NetworkType
21+
}
22+
if a.ko.Spec.PerformanceInsightsRetentionPeriod == nil &&
23+
b.ko.Spec.PerformanceInsightsRetentionPeriod != nil &&
24+
*b.ko.Spec.PerformanceInsightsRetentionPeriod == ServiceDefaultInsightsRetentionPeriod {
25+
a.ko.Spec.PerformanceInsightsRetentionPeriod = b.ko.Spec.PerformanceInsightsRetentionPeriod
26+
}
27+
if a.ko.Spec.PerformanceInsightsKMSKeyID == nil &&
28+
b.ko.Spec.PerformanceInsightsKMSKeyID != nil {
29+
a.ko.Spec.PerformanceInsightsKMSKeyID = b.ko.Spec.PerformanceInsightsKMSKeyID
30+
}
31+
32+
// RDS will choose preferred engine minor version if only
33+
// engine major version is provided and controler should not
34+
// treat them as different, such as spec has 14, status has 14.1
35+
// controller should treat them as same
36+
reconcileEngineVersion(a, b)
1337
compareTags(delta, a, b)

test/e2e/tests/test_db_instance.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
from e2e import condition
2626
from e2e import db_instance
2727
from e2e.fixtures import k8s_secret
28+
from e2e import tag
2829

2930
RESOURCE_PLURAL = 'dbinstances'
3031

@@ -180,7 +181,7 @@ def test_crud_postgres14_t3_micro(
180181
expect_tags = [
181182
{"Key": "environment", "Value": "dev"}
182183
]
183-
latest_tags = db_instance.get_tags(arn)
184+
latest_tags = tag.clean(db_instance.get_tags(arn))
184185
assert expect_tags == latest_tags
185186

186187
# OK, now let's update the tag set and check that the tags are
@@ -197,7 +198,7 @@ def test_crud_postgres14_t3_micro(
197198
k8s.patch_custom_resource(ref, updates)
198199
time.sleep(MODIFY_WAIT_AFTER_SECONDS)
199200

200-
latest_tags = db_instance.get_tags(arn)
201+
latest_tags = tag.clean(db_instance.get_tags(arn))
201202
after_update_expected_tags = [
202203
{
203204
"Key": "environment",
@@ -259,4 +260,4 @@ def test_enable_pi_postgres14_t3_micro(
259260

260261
# TODO: Ensure that the server side defaults
261262
# (PerformanceInsightsRetentionPeriod and PerformanceInsightsKMSKeyID)
262-
# are also persisted back into the spec. This currently does not work
263+
# are also persisted back into the spec. This currently does not work

0 commit comments

Comments
 (0)