Skip to content

Commit ac8784d

Browse files
authored
always ApplyImmediately for DBCluster/Instance (#20)
Sets the ApplyImmediately field in the ModifyDBInstance and ModifyDBCluster API Input shapes to always be `true`, enabling immediate modification of the DB cluster or instance. Issue aws-controllers-k8s/community#865 By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent 8151424 commit ac8784d

File tree

9 files changed

+101
-5
lines changed

9 files changed

+101
-5
lines changed
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
ack_generate_info:
2-
build_date: "2021-07-19T15:18:11Z"
2+
build_date: "2021-07-19T15:47:38Z"
33
build_hash: c77aa9c75d944952dee198029ba9822691cd82b0
44
go_version: go1.15.5 linux/amd64
55
version: v0.6.0
66
api_directory_checksum: c2500a34cb9377122cf5382a6456812006d8261b
77
api_version: v1alpha1
88
aws_sdk_go_version: ""
99
generator_config_info:
10-
file_checksum: 39e5c7eb8d1a39ab0a1c27e9185f412972ce84be
10+
file_checksum: bb80f830d61e1a1c6016fde6102463862f9dc8dd
1111
original_file_name: generator.yaml
1212
last_modification:
1313
reason: API generation
14-
timestamp: 2021-07-19 15:18:16.161125161 +0000 UTC
14+
timestamp: 2021-07-19 15:47:43.42123851 +0000 UTC

apis/v1alpha1/generator.yaml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,40 @@ ignore:
1818
- OptionGroup
1919
field_paths:
2020
operations:
21+
ModifyDBCluster:
22+
override_values:
23+
# The whole concept of a "maintenance window" isn't aligned with the
24+
# declarative state model in Kubernetes. Users should build "maintenance
25+
# window" functionality at a higher layer than the APIs that manage the
26+
# lifecycle of individual resources like a DB cluster or DB instance. For
27+
# example, users can build maintenance window functionality into their
28+
# deployment pipeline solution or GitOps solution.
29+
#
30+
# We override the value of the ApplyImmediately field in the modify
31+
# operations to "true" because we want changes that a Kubernetes user
32+
# makes to a resource's Spec to be reconciled by the ACK service
33+
# controller, not a different service.
34+
ApplyImmediately: true
2135
DeleteDBCluster:
2236
override_values:
2337
# Clearly this is not ideal, but will suffice until we add custom hook
2438
# points to the build_request methods to enable a genmeration of the
2539
# final snapshot identifier to use.
2640
SkipFinalSnapshot: true
41+
ModifyDBInstance:
42+
override_values:
43+
# The whole concept of a "maintenance window" isn't aligned with the
44+
# declarative state model in Kubernetes. Users should build "maintenance
45+
# window" functionality at a higher layer than the APIs that manage the
46+
# lifecycle of individual resources like a DB cluster or DB instance. For
47+
# example, users can build maintenance window functionality into their
48+
# deployment pipeline solution or GitOps solution.
49+
#
50+
# We override the value of the ApplyImmediately field in the modify
51+
# operations to "true" because we want changes that a Kubernetes user
52+
# makes to a resource's Spec to be reconciled by the ACK service
53+
# controller, not a different service.
54+
ApplyImmediately: true
2755
DeleteDBInstance:
2856
override_values:
2957
# Clearly this is not ideal, but will suffice until we add custom hook

generator.yaml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,40 @@ ignore:
1818
- OptionGroup
1919
field_paths:
2020
operations:
21+
ModifyDBCluster:
22+
override_values:
23+
# The whole concept of a "maintenance window" isn't aligned with the
24+
# declarative state model in Kubernetes. Users should build "maintenance
25+
# window" functionality at a higher layer than the APIs that manage the
26+
# lifecycle of individual resources like a DB cluster or DB instance. For
27+
# example, users can build maintenance window functionality into their
28+
# deployment pipeline solution or GitOps solution.
29+
#
30+
# We override the value of the ApplyImmediately field in the modify
31+
# operations to "true" because we want changes that a Kubernetes user
32+
# makes to a resource's Spec to be reconciled by the ACK service
33+
# controller, not a different service.
34+
ApplyImmediately: true
2135
DeleteDBCluster:
2236
override_values:
2337
# Clearly this is not ideal, but will suffice until we add custom hook
2438
# points to the build_request methods to enable a genmeration of the
2539
# final snapshot identifier to use.
2640
SkipFinalSnapshot: true
41+
ModifyDBInstance:
42+
override_values:
43+
# The whole concept of a "maintenance window" isn't aligned with the
44+
# declarative state model in Kubernetes. Users should build "maintenance
45+
# window" functionality at a higher layer than the APIs that manage the
46+
# lifecycle of individual resources like a DB cluster or DB instance. For
47+
# example, users can build maintenance window functionality into their
48+
# deployment pipeline solution or GitOps solution.
49+
#
50+
# We override the value of the ApplyImmediately field in the modify
51+
# operations to "true" because we want changes that a Kubernetes user
52+
# makes to a resource's Spec to be reconciled by the ACK service
53+
# controller, not a different service.
54+
ApplyImmediately: true
2755
DeleteDBInstance:
2856
override_values:
2957
# Clearly this is not ideal, but will suffice until we add custom hook

pkg/resource/db_cluster/sdk.go

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

pkg/resource/db_instance/sdk.go

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

test/e2e/resources/db_cluster_mysql_serverless.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ kind: DBCluster
33
metadata:
44
name: $DB_CLUSTER_ID
55
spec:
6+
copyTagsToSnapshot: $COPY_TAGS_TO_SNAPSHOT
67
dbClusterIdentifier: $DB_CLUSTER_ID
78
databaseName: $DB_NAME
89
engine: aurora-mysql

test/e2e/resources/db_instance_postgres13_t3_micro.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ metadata:
44
name: $DB_INSTANCE_ID
55
spec:
66
allocatedStorage: 20
7+
copyTagsToSnapshot: $COPY_TAGS_TO_SNAPSHOT
78
dbInstanceClass: db.t3.micro
89
dbInstanceIdentifier: $DB_INSTANCE_ID
910
engine: postgres

test/e2e/tests/test_db_cluster.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
CREATE_INTERVAL_SLEEP_SECONDS = 15
3737
CREATE_TIMEOUT_SECONDS = 600
3838

39+
MODIFY_WAIT_AFTER_SECONDS = 20
40+
3941

4042
@pytest.fixture(scope="module")
4143
def rds_client():
@@ -66,6 +68,7 @@ def test_create_delete_mysql_serverless(
6668
mup_sec_ns, mup_sec_name, mup_sec_key = master_user_pass_secret
6769

6870
replacements = REPLACEMENT_VALUES.copy()
71+
replacements['COPY_TAGS_TO_SNAPSHOT'] = "False"
6972
replacements["DB_CLUSTER_ID"] = db_cluster_id
7073
replacements["DB_NAME"] = db_name
7174
replacements["MASTER_USER_PASS_SECRET_NAMESPACE"] = mup_sec_ns
@@ -104,6 +107,22 @@ def test_create_delete_mysql_serverless(
104107
assert len(aws_res['DBClusters']) == 1
105108
dbc_rec = aws_res['DBClusters'][0]
106109

110+
# We're now going to modify the CopyTagsToSnapshot field of the DB
111+
# instance, wait some time and verify that the RDS server-side resource
112+
# shows the new value of the field.
113+
assert dbc_rec['CopyTagsToSnapshot'] == False
114+
updates = {
115+
"spec": {"copyTagsToSnapshot": True},
116+
}
117+
k8s.patch_custom_resource(ref, updates)
118+
time.sleep(MODIFY_WAIT_AFTER_SECONDS)
119+
120+
aws_res = rds_client.describe_db_clusters(DBClusterIdentifier=db_cluster_id)
121+
assert aws_res is not None
122+
assert len(aws_res['DBClusters']) == 1
123+
dbc_rec = aws_res['DBClusters'][0]
124+
assert dbc_rec['CopyTagsToSnapshot'] == True
125+
107126
# Delete the k8s resource on teardown of the module
108127
k8s.delete_custom_resource(ref)
109128

@@ -126,4 +145,3 @@ def test_create_delete_mysql_serverless(
126145
pytest.fail("Status is not 'deleting' for DB cluster that was deleted. Status is "+dbc_rec['Status'])
127146
except rds_client.exceptions.DBClusterNotFoundFault:
128147
break
129-

test/e2e/tests/test_db_instance.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
# Time to wait before we get to an expected `available` state.
4141
CREATE_TIMEOUT_SECONDS = 600
4242

43+
MODIFY_WAIT_AFTER_SECONDS = 20
4344

4445
@pytest.fixture(scope="module")
4546
def rds_client():
@@ -60,7 +61,7 @@ def master_user_pass_secret():
6061
@service_marker
6162
@pytest.mark.canary
6263
class TestDBInstance:
63-
def test_create_delete_postgres13_t3_micro(
64+
def test_crud_postgres13_t3_micro(
6465
self,
6566
rds_client,
6667
master_user_pass_secret,
@@ -69,6 +70,7 @@ def test_create_delete_postgres13_t3_micro(
6970
mup_sec_ns, mup_sec_name, mup_sec_key = master_user_pass_secret
7071

7172
replacements = REPLACEMENT_VALUES.copy()
73+
replacements['COPY_TAGS_TO_SNAPSHOT'] = "False"
7274
replacements["DB_INSTANCE_ID"] = db_id
7375
replacements["MASTER_USER_PASS_SECRET_NAMESPACE"] = mup_sec_ns
7476
replacements["MASTER_USER_PASS_SECRET_NAME"] = mup_sec_name
@@ -108,6 +110,22 @@ def test_create_delete_postgres13_t3_micro(
108110
assert len(aws_res['DBInstances']) == 1
109111
dbi_rec = aws_res['DBInstances'][0]
110112

113+
# We're now going to modify the CopyTagsToSnapshot field of the DB
114+
# instance, wait some time and verify that the RDS server-side resource
115+
# shows the new value of the field.
116+
assert dbi_rec['CopyTagsToSnapshot'] == False
117+
updates = {
118+
"spec": {"copyTagsToSnapshot": True},
119+
}
120+
k8s.patch_custom_resource(ref, updates)
121+
time.sleep(MODIFY_WAIT_AFTER_SECONDS)
122+
123+
aws_res = rds_client.describe_db_instances(DBInstanceIdentifier=db_id)
124+
assert aws_res is not None
125+
assert len(aws_res['DBInstances']) == 1
126+
dbi_rec = aws_res['DBInstances'][0]
127+
assert dbi_rec['CopyTagsToSnapshot'] == True
128+
111129
# Delete the k8s resource on teardown of the module
112130
k8s.delete_custom_resource(ref)
113131

0 commit comments

Comments
 (0)