Skip to content

Commit a6bff3c

Browse files
authored
add checks for endpoint/endpoints field in status (#5)
The endpoint and endpoints field in the Domain.Status struct are filled in when the domain's endpoint URL or URLs (if VPC endpoints) are established. Adds an e2e test to verify these fields on the Status struct are indeed populated, which after adding requeue_on_success_seconds to the generator.yaml file, is indeed true. 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 6368981 commit a6bff3c

File tree

7 files changed

+89
-30
lines changed

7 files changed

+89
-30
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: "2021-11-04T22:37:28Z"
2+
build_date: "2021-11-05T21:04:24Z"
33
build_hash: 0a8fc32cdf2d33693e919e4a59da05599b9f916e
44
go_version: go1.17
55
version: v0.15.1
66
api_directory_checksum: 550c87ef2158e5b3d58bc5a8ff5d3367c192b04a
77
api_version: v1alpha1
88
aws_sdk_go_version: v1.40.51
99
generator_config_info:
10-
file_checksum: 1aa3cbb5df5c91de25b9935978e30138af9b696d
10+
file_checksum: bd75f4fe50f216466e8e62e7f5c40bd1550da7e3
1111
original_file_name: generator.yaml
1212
last_modification:
1313
reason: API generation

apis/v1alpha1/generator.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ ignore:
99
- CreateDomainInput.SnapshotOptions
1010
resources:
1111
Domain:
12+
reconcile:
13+
# Doing this because it takes a LONG time for the Domain's
14+
# endpoint/endpoints field to be populated, even after the Domain's
15+
# Processing field is set to False after creation...
16+
requeue_on_success_seconds: 60
1217
exceptions:
1318
errors:
1419
404:

generator.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ ignore:
99
- CreateDomainInput.SnapshotOptions
1010
resources:
1111
Domain:
12+
reconcile:
13+
# Doing this because it takes a LONG time for the Domain's
14+
# endpoint/endpoints field to be populated, even after the Domain's
15+
# Processing field is set to False after creation...
16+
requeue_on_success_seconds: 60
1217
exceptions:
1318
errors:
1419
404:

pkg/resource/domain/manager_factory.go

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

pkg/resource/domain/sdk.go

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

test/e2e/domain.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,3 +126,19 @@ def get(domain_name):
126126
except c.exceptions.ResourceNotFoundException:
127127
return None
128128

129+
130+
# Apparently, there is an 'endpoint' and an 'endpoints' field for a domain.
131+
# The 'endpoint' field is filled in with a URL when the domain does *not* use
132+
# VPC endpoints. The 'endpoints' field is filled in with a map when the domain
133+
# *does* use VPC endpoints. The following two assertion functions verify this
134+
# "one or the other" behaviour
135+
def assert_endpoint(cr):
136+
assert 'endpoint' in cr['status']
137+
assert cr['status']['endpoint'] != ""
138+
assert 'endpoints' not in cr['status'] or len(cr['status']['endpoints']) == 0
139+
140+
141+
def assert_endpoints(cr):
142+
assert 'endpoint' not in cr['status'] or cr['status']['endpoint'] == ""
143+
assert 'endpoints' in cr['status']
144+
assert len(cr['status']['endpoints']) > 0

test/e2e/tests/test_domain.py

Lines changed: 53 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,13 @@
3737
# Status.Conditions contains a True ResourceSynced condition.
3838
CHECK_STATUS_WAIT_SECONDS = 60
3939

40+
# It can take a LONG time for the domain's endpoint/endpoints field to be
41+
# returned, even after Processing=False and the ResourceSynced condition is set
42+
# to True on a domain. Domain resources are requeued on success which means the
43+
# controller will poll for latest status, including endpoint/endpoints, every
44+
# 30 seconds, so 2 minutes *should* be enough here.
45+
CHECK_ENDPOINT_WAIT_SECONDS = 60*2
46+
4047

4148
@dataclass
4249
class Domain:
@@ -93,7 +100,7 @@ def es_7_9_domain(os_client):
93100
time.sleep(CHECK_STATUS_WAIT_SECONDS)
94101
condition.assert_synced(ref)
95102

96-
yield resource
103+
yield ref, resource
97104

98105
# Delete the k8s resource on teardown of the module
99106
k8s.delete_custom_resource(ref)
@@ -135,7 +142,7 @@ def es_2d3m_multi_az_no_vpc_7_9_domain(os_client):
135142
time.sleep(CHECK_STATUS_WAIT_SECONDS)
136143
condition.assert_synced(ref)
137144

138-
yield resource
145+
yield ref, resource
139146

140147
# Delete the k8s resource on teardown of the module
141148
k8s.delete_custom_resource(ref)
@@ -187,7 +194,7 @@ def es_2d3m_multi_az_vpc_2_subnet7_9_domain(os_client, resources: BootstrapResou
187194
time.sleep(CHECK_STATUS_WAIT_SECONDS)
188195
condition.assert_synced(ref)
189196

190-
yield resource
197+
yield ref, resource
191198

192199
# Delete the k8s resource on teardown of the module
193200
k8s.delete_custom_resource(ref)
@@ -203,35 +210,56 @@ def es_2d3m_multi_az_vpc_2_subnet7_9_domain(os_client, resources: BootstrapResou
203210
@pytest.mark.canary
204211
class TestDomain:
205212
def test_create_delete_es_7_9(self, es_7_9_domain):
206-
resource = es_7_9_domain
213+
ref, resource = es_7_9_domain
214+
215+
latest = domain.get(resource.name)
207216

208-
aws_res = domain.get(resource.name)
217+
assert latest['DomainStatus']['EngineVersion'] == 'Elasticsearch_7.9'
218+
assert latest['DomainStatus']['Created'] == True
219+
assert latest['DomainStatus']['ClusterConfig']['InstanceCount'] == resource.data_node_count
220+
assert latest['DomainStatus']['ClusterConfig']['ZoneAwarenessEnabled'] == resource.is_zone_aware
209221

210-
assert aws_res['DomainStatus']['EngineVersion'] == 'Elasticsearch_7.9'
211-
assert aws_res['DomainStatus']['Created'] == True
212-
assert aws_res['DomainStatus']['ClusterConfig']['InstanceCount'] == resource.data_node_count
213-
assert aws_res['DomainStatus']['ClusterConfig']['ZoneAwarenessEnabled'] == resource.is_zone_aware
222+
time.sleep(CHECK_ENDPOINT_WAIT_SECONDS)
223+
224+
cr = k8s.get_resource(ref)
225+
assert cr is not None
226+
assert 'status' in cr
227+
domain.assert_endpoint(cr)
214228

215229
def test_create_delete_es_2d3m_multi_az_no_vpc_7_9(self, es_2d3m_multi_az_no_vpc_7_9_domain):
216-
resource = es_2d3m_multi_az_no_vpc_7_9_domain
230+
ref, resource = es_2d3m_multi_az_no_vpc_7_9_domain
231+
232+
latest = domain.get(resource.name)
217233

218-
aws_res = domain.get(resource.name)
234+
assert latest['DomainStatus']['EngineVersion'] == 'Elasticsearch_7.9'
235+
assert latest['DomainStatus']['Created'] == True
236+
assert latest['DomainStatus']['ClusterConfig']['InstanceCount'] == resource.data_node_count
237+
assert latest['DomainStatus']['ClusterConfig']['DedicatedMasterCount'] == resource.master_node_count
238+
assert latest['DomainStatus']['ClusterConfig']['ZoneAwarenessEnabled'] == resource.is_zone_aware
219239

220-
assert aws_res['DomainStatus']['EngineVersion'] == 'Elasticsearch_7.9'
221-
assert aws_res['DomainStatus']['Created'] == True
222-
assert aws_res['DomainStatus']['ClusterConfig']['InstanceCount'] == resource.data_node_count
223-
assert aws_res['DomainStatus']['ClusterConfig']['DedicatedMasterCount'] == resource.master_node_count
224-
assert aws_res['DomainStatus']['ClusterConfig']['ZoneAwarenessEnabled'] == resource.is_zone_aware
240+
time.sleep(CHECK_ENDPOINT_WAIT_SECONDS)
241+
242+
cr = k8s.get_resource(ref)
243+
assert cr is not None
244+
assert 'status' in cr
245+
domain.assert_endpoint(cr)
225246

226247
def test_create_delete_es_2d3m_multi_az_vpc_2_subnet7_9(self, es_2d3m_multi_az_vpc_2_subnet7_9_domain):
227-
resource = es_2d3m_multi_az_vpc_2_subnet7_9_domain
248+
ref, resource = es_2d3m_multi_az_vpc_2_subnet7_9_domain
249+
250+
latest = domain.get(resource.name)
251+
252+
assert latest['DomainStatus']['EngineVersion'] == 'Elasticsearch_7.9'
253+
assert latest['DomainStatus']['Created'] == True
254+
assert latest['DomainStatus']['ClusterConfig']['InstanceCount'] == resource.data_node_count
255+
assert latest['DomainStatus']['ClusterConfig']['DedicatedMasterCount'] == resource.master_node_count
256+
assert latest['DomainStatus']['ClusterConfig']['ZoneAwarenessEnabled'] == resource.is_zone_aware
257+
assert latest['DomainStatus']['VPCOptions']['VPCId'] == resource.vpc_id
258+
assert set(latest['DomainStatus']['VPCOptions']['SubnetIds']) == set(resource.vpc_subnets)
228259

229-
aws_res = domain.get(resource.name)
260+
time.sleep(CHECK_ENDPOINT_WAIT_SECONDS)
230261

231-
assert aws_res['DomainStatus']['EngineVersion'] == 'Elasticsearch_7.9'
232-
assert aws_res['DomainStatus']['Created'] == True
233-
assert aws_res['DomainStatus']['ClusterConfig']['InstanceCount'] == resource.data_node_count
234-
assert aws_res['DomainStatus']['ClusterConfig']['DedicatedMasterCount'] == resource.master_node_count
235-
assert aws_res['DomainStatus']['ClusterConfig']['ZoneAwarenessEnabled'] == resource.is_zone_aware
236-
assert aws_res['DomainStatus']['VPCOptions']['VPCId'] == resource.vpc_id
237-
assert set(aws_res['DomainStatus']['VPCOptions']['SubnetIds']) == set(resource.vpc_subnets)
262+
cr = k8s.get_resource(ref)
263+
assert cr is not None
264+
assert 'status' in cr
265+
domain.assert_endpoints(cr)

0 commit comments

Comments
 (0)