Skip to content

Commit 8cce40e

Browse files
Terminal Codes Nat Gateway (#61)
Issue #, if available: [1362](aws-controllers-k8s/community#1362) Description of changes: - Mapped terminal codes for Nat Gateway resource. - Added integration tests for mapped 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 d9b6c57 commit 8cce40e

File tree

5 files changed

+137
-5
lines changed

5 files changed

+137
-5
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: "2022-07-21T17:09:05Z"
2+
build_date: "2022-07-22T19:16:29Z"
33
build_hash: 208b1e15257d57c46729698f47a40fd59441ecbd
44
go_version: go1.18.3
55
version: v0.19.2-1-g208b1e1
66
api_directory_checksum: 8c35bdcab21768638dfaa277896e05fdd8a11969
77
api_version: v1alpha1
88
aws_sdk_go_version: v1.42.0
99
generator_config_info:
10-
file_checksum: 2d139419a1025deea1337589c5831061d23499bb
10+
file_checksum: e6b4abcc020960d535a8a1022c087323ea2c40a6
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
@@ -263,6 +263,11 @@ resources:
263263
update_operation:
264264
custom_method_name: customUpdateInternetGateway
265265
NatGateway:
266+
exceptions:
267+
terminal_codes:
268+
- InvalidSubnet
269+
- InvalidElasticIpID.Malformed
270+
- MissingParameter
266271
fields:
267272
AllocationId:
268273
references:

generator.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,11 @@ resources:
263263
update_operation:
264264
custom_method_name: customUpdateInternetGateway
265265
NatGateway:
266+
exceptions:
267+
terminal_codes:
268+
- InvalidSubnet
269+
- InvalidElasticIpID.Malformed
270+
- MissingParameter
266271
fields:
267272
AllocationId:
268273
references:

pkg/resource/nat_gateway/sdk.go

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

test/e2e/tests/test_nat_gateway.py

Lines changed: 110 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,4 +117,113 @@ def test_create_delete(self, standard_elastic_address, ec2_client):
117117
time.sleep(DELETE_WAIT_AFTER_SECONDS)
118118

119119
# Check NAT Gateway no longer exists in AWS
120-
ec2_validator.assert_nat_gateway(resource_id, exists=False)
120+
ec2_validator.assert_nat_gateway(resource_id, exists=False)
121+
122+
def test_terminal_condition_invalid_subnet(self, standard_elastic_address):
123+
test_resource_values = REPLACEMENT_VALUES.copy()
124+
resource_name = random_suffix_name("nat-gateway-fail-1", 24)
125+
subnet_id = "InvalidSubnet"
126+
127+
(_, eip) = standard_elastic_address
128+
129+
test_resource_values["NAT_GATEWAY_NAME"] = resource_name
130+
test_resource_values["SUBNET_ID"] = subnet_id
131+
test_resource_values["ALLOCATION_ID"] = eip["status"]["allocationID"]
132+
133+
# Load NAT Gateway CR
134+
resource_data = load_ec2_resource(
135+
"nat_gateway",
136+
additional_replacements=test_resource_values,
137+
)
138+
logging.debug(resource_data)
139+
140+
# Create k8s resource
141+
ref = k8s.CustomResourceReference(
142+
CRD_GROUP, CRD_VERSION, RESOURCE_PLURAL,
143+
resource_name, namespace="default",
144+
)
145+
k8s.create_custom_resource(ref, resource_data)
146+
cr = k8s.wait_resource_consumed_by_controller(ref)
147+
148+
assert cr is not None
149+
assert k8s.get_resource_exists(ref)
150+
151+
expected_msg = "InvalidSubnet: The subnet ID 'InvalidSubnet' is malformed"
152+
terminal_condition = k8s.get_resource_condition(ref, "ACK.Terminal")
153+
# Example condition message:
154+
# An error occurred (InvalidSubnet) when calling the CreateNatGateway operation:
155+
# The subnet ID 'InvalidSubnet' is malformed
156+
assert expected_msg in terminal_condition['message']
157+
158+
def test_terminal_condition_malformed_elastic_ip(self):
159+
test_resource_values = REPLACEMENT_VALUES.copy()
160+
resource_name = random_suffix_name("nat-gateway-fail-2", 24)
161+
test_vpc = get_bootstrap_resources().SharedTestVPC
162+
subnet_id = test_vpc.public_subnets.subnet_ids[0]
163+
164+
test_resource_values["NAT_GATEWAY_NAME"] = resource_name
165+
test_resource_values["SUBNET_ID"] = subnet_id
166+
test_resource_values["ALLOCATION_ID"] = "MalformedElasticIpId"
167+
168+
# Load NAT Gateway CR
169+
resource_data = load_ec2_resource(
170+
"nat_gateway",
171+
additional_replacements=test_resource_values,
172+
)
173+
logging.debug(resource_data)
174+
175+
# Create k8s resource
176+
ref = k8s.CustomResourceReference(
177+
CRD_GROUP, CRD_VERSION, RESOURCE_PLURAL,
178+
resource_name, namespace="default",
179+
)
180+
k8s.create_custom_resource(ref, resource_data)
181+
cr = k8s.wait_resource_consumed_by_controller(ref)
182+
183+
assert cr is not None
184+
assert k8s.get_resource_exists(ref)
185+
186+
expected_msg = "InvalidElasticIpID.Malformed: The elastic-ip ID 'MalformedElasticIpId' is malformed"
187+
terminal_condition = k8s.get_resource_condition(ref, "ACK.Terminal")
188+
# Example condition message:
189+
# An error occurred (InvalidElasticIpID.Malformed) when calling the CreateNatGateway operation:
190+
# The elastic-ip ID 'MalformedElasticIpId' is malformed"
191+
assert expected_msg in terminal_condition['message']
192+
193+
def test_terminal_condition_missing_parameter(self):
194+
test_resource_values = REPLACEMENT_VALUES.copy()
195+
resource_name = random_suffix_name("nat-gateway-fail-3", 24)
196+
test_vpc = get_bootstrap_resources().SharedTestVPC
197+
subnet_id = test_vpc.public_subnets.subnet_ids[0]
198+
199+
test_resource_values["NAT_GATEWAY_NAME"] = resource_name
200+
test_resource_values["SUBNET_ID"] = subnet_id
201+
202+
# ALLOCATION_ID is required for creating public nat gateways only
203+
test_resource_values["ALLOCATION_ID"] = ""
204+
205+
# Load NAT Gateway CR
206+
resource_data = load_ec2_resource(
207+
"nat_gateway",
208+
additional_replacements=test_resource_values,
209+
)
210+
logging.debug(resource_data)
211+
212+
# Create k8s resource
213+
ref = k8s.CustomResourceReference(
214+
CRD_GROUP, CRD_VERSION, RESOURCE_PLURAL,
215+
resource_name, namespace="default",
216+
)
217+
k8s.create_custom_resource(ref, resource_data)
218+
cr = k8s.wait_resource_consumed_by_controller(ref)
219+
220+
assert cr is not None
221+
assert k8s.get_resource_exists(ref)
222+
223+
expected_msg = "MissingParameter: The request must include the AllocationId parameter. Add the required parameter and retry the request."
224+
terminal_condition = k8s.get_resource_condition(ref, "ACK.Terminal")
225+
# Example condition message:
226+
# An error occurred (MissingParameter) when calling the CreateNatGateway operation:
227+
# The request must include the AllocationId parameter.
228+
# Add the required parameter and retry the request.
229+
assert expected_msg in terminal_condition['message']

0 commit comments

Comments
 (0)