Skip to content

Commit def8072

Browse files
authored
Copy IAM authentication state from status (#159)
Issue #, if available: #1937 Description of changes: Like the parameter groups the IAM authentication flag has different names in the input and output to the API. A hook is need to correctly set the value. By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent 1e6f3fb commit def8072

File tree

6 files changed

+116
-10
lines changed

6 files changed

+116
-10
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-09-14T23:59:25Z"
2+
build_date: "2023-11-07T03:25:11Z"
33
build_hash: 892f29d00a4c4ad21a2fa32919921de18190979d
4-
go_version: go1.21.0
4+
go_version: go1.21.3
55
version: v0.27.1
66
api_directory_checksum: ec327bd746176accff503d6ca1306e08a55ac61b
77
api_version: v1alpha1

pkg/resource/db_cluster/sdk.go

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

templates/hooks/db_cluster/sdk_read_many_post_set_output.go.tpl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,9 @@
3030
// resource with the value from the status.
3131
ko.Spec.DBClusterParameterGroupName = ko.Status.DBClusterParameterGroup
3232
}
33+
34+
if r.ko.Spec.EnableIAMDatabaseAuthentication != nil {
35+
// If the desired resource has IAM authentication explicitly enabled or disabled then update the spec of the
36+
// latest resource with the value from the status.
37+
ko.Spec.EnableIAMDatabaseAuthentication = ko.Status.IAMDatabaseAuthenticationEnabled
38+
}

test/e2e/db_cluster.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,18 @@
3030
typing.Callable[[dict], bool],
3131
)
3232

33-
class StatusMatcher:
34-
def __init__(self, status):
35-
self.match_on = status
33+
class AttributeMatcher:
34+
def __init__(self, match_on: str, expected_value: typing.Any):
35+
self.match_on = match_on
36+
self.expected_value = expected_value
3637

37-
def __call__(self, record: dict) -> bool:
38-
return (record is not None and 'Status' in record
39-
and record['Status'] == self.match_on)
38+
def __call__(self, record: typing.Dict[str, typing.Any]) -> bool:
39+
return (record is not None and self.match_on in record
40+
and record[self.match_on] == self.expected_value)
4041

4142

4243
def status_matches(status: str) -> ClusterMatchFunc:
43-
return StatusMatcher(status)
44+
return AttributeMatcher("Status", status)
4445

4546

4647
def wait_until(
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
apiVersion: rds.services.k8s.aws/v1alpha1
2+
kind: DBCluster
3+
metadata:
4+
name: $DB_CLUSTER_ID
5+
spec:
6+
autoMinorVersionUpgrade: false
7+
copyTagsToSnapshot: false
8+
dbClusterIdentifier: $DB_CLUSTER_ID
9+
enableIAMDatabaseAuthentication: false
10+
engine: aurora-postgresql
11+
engineMode: provisioned
12+
engineVersion: "14.9"
13+
masterUsername: root
14+
masterUserPassword:
15+
namespace: $MASTER_USER_PASS_SECRET_NAMESPACE
16+
name: $MASTER_USER_PASS_SECRET_NAME
17+
key: $MASTER_USER_PASS_SECRET_KEY
18+
port: 5432
19+
storageEncrypted: true

test/e2e/tests/test_db_cluster.py

Lines changed: 75 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def aurora_mysql_cluster(k8s_secret):
6565
db_name = "mydb"
6666
secret = k8s_secret(
6767
MUP_NS,
68-
MUP_SEC_NAME,
68+
f"{MUP_SEC_NAME}-mysql",
6969
MUP_SEC_KEY,
7070
MUP_SEC_VAL,
7171
)
@@ -108,6 +108,53 @@ def aurora_mysql_cluster(k8s_secret):
108108

109109
db_cluster.wait_until_deleted(db_cluster_id)
110110

111+
112+
@pytest.fixture
113+
def aurora_postgres_cluster(k8s_secret):
114+
db_cluster_id = random_suffix_name("my-aurora-postgres", 20)
115+
secret = k8s_secret(
116+
MUP_NS,
117+
f"{MUP_SEC_NAME}-postgres",
118+
MUP_SEC_KEY,
119+
MUP_SEC_VAL,
120+
)
121+
122+
resource_data = load_rds_resource(
123+
"db_cluster_aurora_postgres",
124+
additional_replacements={
125+
"DB_CLUSTER_ID": db_cluster_id,
126+
"MASTER_USER_PASS_SECRET_NAMESPACE": secret.ns,
127+
"MASTER_USER_PASS_SECRET_NAME": secret.name,
128+
"MASTER_USER_PASS_SECRET_KEY": secret.key,
129+
},
130+
)
131+
132+
ref = k8s.CustomResourceReference(
133+
CRD_GROUP, CRD_VERSION, RESOURCE_PLURAL,
134+
db_cluster_id, namespace="default",
135+
)
136+
k8s.create_custom_resource(ref, resource_data)
137+
cr = k8s.wait_resource_consumed_by_controller(ref)
138+
139+
assert cr is not None
140+
assert 'status' in cr
141+
assert 'status' in cr['status']
142+
assert cr['status']['status'] == 'creating'
143+
condition.assert_not_synced(ref)
144+
145+
yield (ref, cr, db_cluster_id)
146+
147+
# Try to delete, if doesn't already exist
148+
try:
149+
_, deleted = k8s.delete_custom_resource(ref, 3, 10)
150+
assert deleted
151+
time.sleep(DELETE_WAIT_AFTER_SECONDS)
152+
except:
153+
pass
154+
155+
db_cluster.wait_until_deleted(db_cluster_id)
156+
157+
111158
@service_marker
112159
@pytest.mark.canary
113160
class TestDBCluster:
@@ -183,3 +230,30 @@ def test_crud_mysql_serverless(
183230
}
184231
]
185232
assert latest_tags == after_update_expected_tags
233+
234+
def test_flip_enable_iam_db_authn(
235+
self, aurora_postgres_cluster,
236+
):
237+
ref, _, db_cluster_id = aurora_postgres_cluster
238+
239+
db_cluster.wait_until(
240+
db_cluster_id,
241+
db_cluster.status_matches('available'),
242+
)
243+
244+
current = db_cluster.get(db_cluster_id)
245+
assert current is not None
246+
assert current["IAMDatabaseAuthenticationEnabled"] == False
247+
k8s.patch_custom_resource(
248+
ref,
249+
{"spec": {"enableIAMDatabaseAuthentication": True}},
250+
)
251+
252+
db_cluster.wait_until(
253+
db_cluster_id,
254+
db_cluster.AttributeMatcher("IAMDatabaseAuthenticationEnabled", True),
255+
)
256+
257+
latest = db_cluster.get(db_cluster_id)
258+
assert latest is not None
259+
assert latest["IAMDatabaseAuthenticationEnabled"] == True

0 commit comments

Comments
 (0)