Skip to content

Commit f5e15c0

Browse files
Terminal code mappings for Subnet (#67)
Issue #, if available: [1362](aws-controllers-k8s/community#1362) Description of changes: - Mapped terminal codes for **Subnet** resource. - Added integration tests for mapped terminal codes. - Removed VPC Invalid and malformed errors from terminal codes. By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent 0efa43f commit f5e15c0

File tree

4 files changed

+40
-43
lines changed

4 files changed

+40
-43
lines changed

apis/v1alpha1/generator.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -398,8 +398,7 @@ resources:
398398
path: Status.VPCID
399399
exceptions:
400400
terminal_codes:
401-
- InvalidVpcID.Malformed
402-
- InvalidVpcID.NotFound
401+
- InvalidParameterValue
403402
hooks:
404403
sdk_create_post_build_request:
405404
template_path: hooks/subnet/sdk_create_post_build_request.go.tpl

generator.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -398,8 +398,7 @@ resources:
398398
path: Status.VPCID
399399
exceptions:
400400
terminal_codes:
401-
- InvalidVpcID.Malformed
402-
- InvalidVpcID.NotFound
401+
- InvalidParameterValue
403402
hooks:
404403
sdk_create_post_build_request:
405404
template_path: hooks/subnet/sdk_create_post_build_request.go.tpl

pkg/resource/subnet/sdk.go

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

test/e2e/tests/test_subnet.py

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -134,42 +134,6 @@ def test_create_delete(self, ec2_client):
134134
# Check Subnet no longer exists in AWS
135135
ec2_validator.assert_subnet(resource_id, exists=False)
136136

137-
def test_terminal_condition(self):
138-
test_resource_values = REPLACEMENT_VALUES.copy()
139-
resource_name = random_suffix_name("subnet-fail", 24)
140-
test_vpc = get_bootstrap_resources().SharedTestVPC
141-
vpc_cidr = test_vpc.vpc_cidr_block
142-
143-
test_resource_values["SUBNET_NAME"] = resource_name
144-
test_resource_values["VPC_ID"] = "InvalidVpcId"
145-
test_resource_values["CIDR_BLOCK"] = vpc_cidr
146-
147-
# Load Subnet CR
148-
resource_data = load_ec2_resource(
149-
"subnet",
150-
additional_replacements=test_resource_values,
151-
)
152-
logging.debug(resource_data)
153-
154-
# Create k8s resource
155-
ref = k8s.CustomResourceReference(
156-
CRD_GROUP, CRD_VERSION, RESOURCE_PLURAL,
157-
resource_name, namespace="default",
158-
)
159-
k8s.create_custom_resource(ref, resource_data)
160-
cr = k8s.wait_resource_consumed_by_controller(ref)
161-
162-
assert cr is not None
163-
assert k8s.get_resource_exists(ref)
164-
165-
expected_msg = "InvalidVpcID.NotFound: The vpc ID 'InvalidVpcId' does not exist"
166-
terminal_condition = k8s.get_resource_condition(ref, "ACK.Terminal")
167-
# Example condition message:
168-
# InvalidVpcID.NotFound: The vpc ID 'InvalidVpcId' does not exist
169-
# status code: 400, request id: 5801fc80-67cf-465f-8b83-5e02d517d554
170-
# This check only verifies the error message; the request hash is irrelevant and therefore can be ignored.
171-
assert expected_msg in terminal_condition['message']
172-
173137
def test_route_table_assocations(self, ec2_client, default_route_tables):
174138
test_resource_values = REPLACEMENT_VALUES.copy()
175139
resource_name = random_suffix_name("subnet-test", 24)
@@ -231,4 +195,40 @@ def test_route_table_assocations(self, ec2_client, default_route_tables):
231195
time.sleep(DELETE_WAIT_AFTER_SECONDS)
232196

233197
# Check Subnet no longer exists in AWS
234-
ec2_validator.assert_subnet(resource_id, exists=False)
198+
ec2_validator.assert_subnet(resource_id, exists=False)
199+
200+
def test_terminal_condition_invalid_parameter_value(self):
201+
test_resource_values = REPLACEMENT_VALUES.copy()
202+
resource_name = random_suffix_name("subnet-fail", 24)
203+
test_vpc = get_bootstrap_resources().SharedTestVPC
204+
vpc_id = test_vpc.vpc_id
205+
206+
test_resource_values["SUBNET_NAME"] = resource_name
207+
test_resource_values["CIDR_BLOCK"] = "InvalidCidrBlock"
208+
test_resource_values["VPC_ID"] = vpc_id
209+
210+
# Load Subnet CR
211+
resource_data = load_ec2_resource(
212+
"subnet",
213+
additional_replacements=test_resource_values,
214+
)
215+
logging.debug(resource_data)
216+
217+
# Create k8s resource
218+
ref = k8s.CustomResourceReference(
219+
CRD_GROUP, CRD_VERSION, RESOURCE_PLURAL,
220+
resource_name, namespace="default",
221+
)
222+
k8s.create_custom_resource(ref, resource_data)
223+
cr = k8s.wait_resource_consumed_by_controller(ref)
224+
225+
assert cr is not None
226+
assert k8s.get_resource_exists(ref)
227+
228+
expected_msg = "InvalidParameterValue: Value (InvalidCidrBlock) for parameter cidrBlock is invalid. This is not a valid CIDR block."
229+
terminal_condition = k8s.get_resource_condition(ref, "ACK.Terminal")
230+
# Example condition message:
231+
# An error occurred (InvalidParameterValue) when calling the CreateSubnet operation:
232+
# Value (InvalidCidrBlock) for parameter cidrBlock is invalid.
233+
# This is not a valid CIDR block.
234+
assert expected_msg in terminal_condition['message']

0 commit comments

Comments
 (0)