Skip to content

Commit ce5980c

Browse files
authored
update Synced condition for DDB resources (#49)
Adds logic to the resource managers for GlobalTable, Table and Backup resources to properly understand when `ACK.ResourceSynced=True` condition should be applied. Issue aws-controllers-k8s/community#1500 Signed-off-by: Jay Pipes <[email protected]> By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent f8a357c commit ce5980c

File tree

13 files changed

+234
-11
lines changed

13 files changed

+234
-11
lines changed
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
ack_generate_info:
2-
build_date: "2022-09-12T19:55:03Z"
3-
build_hash: 2944c8772f216656d84ee02d392eaca501274c1e
4-
go_version: go1.17.5
5-
version: v0.20.1
6-
api_directory_checksum: b9de9af5f2fec85ab3fb5397e7a989da29087a01
2+
build_date: "2022-10-14T17:11:08Z"
3+
build_hash: 5ee0ac052c54f008dff50f6f5ebb73f2cf3a0bd7
4+
go_version: go1.18.1
5+
version: v0.20.1-4-g5ee0ac0-dirty
6+
api_directory_checksum: 69846f77247f7420db696a47cedbb5bd19190601
77
api_version: v1alpha1
88
aws_sdk_go_version: v1.44.93
99
generator_config_info:
10-
file_checksum: 9b6326bdc07bc55fe8d97cc6b3adb1a6e8a15c29
10+
file_checksum: cf8320749a4188537376f8cec2b93e5aea7b3b52
1111
original_file_name: generator.yaml
1212
last_modification:
1313
reason: API generation

apis/v1alpha1/generator.yaml

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ resources:
3434
template_path: hooks/table/sdk_read_one_post_set_output.go.tpl
3535
sdk_delete_pre_build_request:
3636
template_path: hooks/table/sdk_delete_pre_build_request.go.tpl
37+
synced:
38+
when:
39+
- path: Status.TableStatus
40+
in:
41+
- ACTIVE
42+
- ARCHIVED
3743
GlobalTable:
3844
exceptions:
3945
errors:
@@ -44,6 +50,11 @@ resources:
4450
code: customSetDeleteInput(r, input)
4551
tags:
4652
ignore: true
53+
synced:
54+
when:
55+
- path: Status.GlobalTableStatus
56+
in:
57+
- ACTIVE
4758
Backup:
4859
exceptions:
4960
errors:
@@ -53,4 +64,10 @@ resources:
5364
sdk_read_one_post_set_output:
5465
template_path: hooks/backup/sdk_read_one_post_set_output.go.tpl
5566
tags:
56-
ignore: true
67+
ignore: true
68+
synced:
69+
when:
70+
- path: Status.BackupStatus
71+
in:
72+
- AVAILABLE
73+
- DELETED

generator.yaml

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ resources:
3434
template_path: hooks/table/sdk_read_one_post_set_output.go.tpl
3535
sdk_delete_pre_build_request:
3636
template_path: hooks/table/sdk_delete_pre_build_request.go.tpl
37+
synced:
38+
when:
39+
- path: Status.TableStatus
40+
in:
41+
- ACTIVE
42+
- ARCHIVED
3743
GlobalTable:
3844
exceptions:
3945
errors:
@@ -44,6 +50,11 @@ resources:
4450
code: customSetDeleteInput(r, input)
4551
tags:
4652
ignore: true
53+
synced:
54+
when:
55+
- path: Status.GlobalTableStatus
56+
in:
57+
- ACTIVE
4758
Backup:
4859
exceptions:
4960
errors:
@@ -53,4 +64,10 @@ resources:
5364
sdk_read_one_post_set_output:
5465
template_path: hooks/backup/sdk_read_one_post_set_output.go.tpl
5566
tags:
56-
ignore: true
67+
ignore: true
68+
synced:
69+
when:
70+
- path: Status.BackupStatus
71+
in:
72+
- AVAILABLE
73+
- DELETED

helm/templates/cluster-role-controller.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,19 @@ kind: ClusterRole
44
metadata:
55
creationTimestamp: null
66
name: ack-dynamodb-controller
7+
labels:
8+
{{- range $key, $value := .Values.role.labels }}
9+
{{ $key }}: {{ $value | quote }}
10+
{{- end }}
711
{{ else }}
812
kind: Role
913
metadata:
1014
creationTimestamp: null
1115
name: ack-dynamodb-controller
16+
labels:
17+
{{- range $key, $value := .Values.role.labels }}
18+
{{ $key }}: {{ $value | quote }}
19+
{{- end }}
1220
namespace: {{ .Release.Namespace }}
1321
{{ end }}
1422
rules:

helm/values.schema.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,14 @@
6565
],
6666
"type": "object"
6767
},
68+
"role": {
69+
"description": "Role settings",
70+
"properties": {
71+
"labels": {
72+
"type": "object"
73+
}
74+
}
75+
},
6876
"metrics": {
6977
"description": "Metrics settings",
7078
"properties": {

helm/values.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ deployment:
2828
# Which priorityClassName to set?
2929
# See: https://kubernetes.io/docs/concepts/scheduling-eviction/pod-priority-preemption/#pod-priority
3030
priorityClassName: ""
31+
32+
# If "installScope: cluster" then these labels will be applied to ClusterRole
33+
role:
34+
labels: {}
3135

3236
metrics:
3337
service:

pkg/resource/backup/manager.go

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

pkg/resource/global_table/manager.go

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

pkg/resource/table/manager.go

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

test/e2e/condition.py

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
# Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License"). You may
4+
# not use this file except in compliance with the License. A copy of the
5+
# License is located at
6+
#
7+
# http://aws.amazon.com/apache2.0/
8+
#
9+
# or in the "license" file accompanying this file. This file is distributed
10+
# on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
11+
# express or implied. See the License for the specific language governing
12+
# permissions and limitations under the License.
13+
14+
"""Utility functions to help processing Kubernetes resource conditions"""
15+
16+
import pytest
17+
18+
from acktest.k8s import resource
19+
20+
CONDITION_TYPE_ADOPTED = "ACK.Adopted"
21+
CONDITION_TYPE_RESOURCE_SYNCED = "ACK.ResourceSynced"
22+
CONDITION_TYPE_TERMINAL = "ACK.Terminal"
23+
CONDITION_TYPE_RECOVERABLE = "ACK.Recoverable"
24+
CONDITION_TYPE_ADVISORY = "ACK.Advisory"
25+
CONDITION_TYPE_LATE_INITIALIZED = "ACK.LateInitialized"
26+
CONDITION_TYPE_REFERENCES_RESOLVED = "ACK.ReferencesResolved"
27+
28+
29+
def assert_type_status(
30+
ref: resource.CustomResourceReference,
31+
cond_type_match: str = CONDITION_TYPE_RESOURCE_SYNCED,
32+
cond_status_match: bool = True,
33+
):
34+
"""Asserts that the supplied resource has a condition of type
35+
ACK.ResourceSynced and that the Status of this condition is True.
36+
37+
Usage:
38+
from acktest.k8s import resource
39+
from acktest.k8s import condition
40+
41+
ref = resource.CustomResourceReference(
42+
CRD_GROUP, CRD_VERSION, RESOURCE_PLURAL,
43+
db_cluster_id, namespace="default",
44+
)
45+
resource.create_custom_resource(ref, resource_data)
46+
resource.wait_resource_consumed_by_controller(ref)
47+
condition.assert_type_status(
48+
ref,
49+
condition.CONDITION_TYPE_RESOURCE_SYNCED,
50+
False)
51+
52+
Raises:
53+
pytest.fail when condition of the specified type is not found or is not
54+
in the supplied status.
55+
"""
56+
cond = resource.get_resource_condition(ref, cond_type_match)
57+
if cond is None:
58+
msg = (f"Failed to find {cond_type_match} condition in "
59+
f"resource {ref}")
60+
pytest.fail(msg)
61+
62+
cond_status = cond.get('status', None)
63+
if str(cond_status) != str(cond_status_match):
64+
msg = (f"Expected {cond_type_match} condition to "
65+
f"have status {cond_status_match} but found {cond_status}")
66+
pytest.fail(msg)
67+
68+
69+
def assert_synced_status(
70+
ref: resource.CustomResourceReference,
71+
cond_status_match: bool,
72+
):
73+
"""Asserts that the supplied resource has a condition of type
74+
ACK.ResourceSynced and that the Status of this condition is True.
75+
76+
Usage:
77+
from acktest.k8s import resource
78+
from acktest.k8s import condition
79+
80+
ref = resource.CustomResourceReference(
81+
CRD_GROUP, CRD_VERSION, RESOURCE_PLURAL,
82+
db_cluster_id, namespace="default",
83+
)
84+
resource.create_custom_resource(ref, resource_data)
85+
resource.wait_resource_consumed_by_controller(ref)
86+
condition.assert_synced_status(ref, False)
87+
88+
Raises:
89+
pytest.fail when ACK.ResourceSynced condition is not found or is not in
90+
a True status.
91+
"""
92+
assert_type_status(ref, CONDITION_TYPE_RESOURCE_SYNCED, cond_status_match)
93+
94+
95+
def assert_synced(ref: resource.CustomResourceReference):
96+
"""Asserts that the supplied resource has a condition of type
97+
ACK.ResourceSynced and that the Status of this condition is True.
98+
99+
Usage:
100+
from acktest.k8s import resource
101+
from acktest.k8s import condition
102+
103+
ref = resource.CustomResourceReference(
104+
CRD_GROUP, CRD_VERSION, RESOURCE_PLURAL,
105+
db_cluster_id, namespace="default",
106+
)
107+
resource.create_custom_resource(ref, resource_data)
108+
resource.wait_resource_consumed_by_controller(ref)
109+
condition.assert_synced(ref)
110+
111+
Raises:
112+
pytest.fail when ACK.ResourceSynced condition is not found or is not in
113+
a True status.
114+
"""
115+
return assert_synced_status(ref, True)
116+
117+
118+
def assert_not_synced(ref: resource.CustomResourceReference):
119+
"""Asserts that the supplied resource has a condition of type
120+
ACK.ResourceSynced and that the Status of this condition is False.
121+
122+
Usage:
123+
from acktest.k8s import resource
124+
from acktest.k8s import condition
125+
126+
ref = resource.CustomResourceReference(
127+
CRD_GROUP, CRD_VERSION, RESOURCE_PLURAL,
128+
db_cluster_id, namespace="default",
129+
)
130+
resource.create_custom_resource(ref, resource_data)
131+
resource.wait_resource_consumed_by_controller(ref)
132+
condition.assert_not_synced(ref)
133+
134+
Raises:
135+
pytest.fail when ACK.ResourceSynced condition is not found or is not in
136+
a False status.
137+
"""
138+
return assert_synced_status(ref, False)
139+

0 commit comments

Comments
 (0)