Skip to content

Commit c6afdbc

Browse files
Terminal codes for elastic ip address (#71)
Issue #, if available: [1362](aws-controllers-k8s/community#1362) Description of changes: - Removed existing terminal codes except `InvalidParameterValue` and `InvalidParameterCombination`. - Added integration tests for the mapped terminal codes. - Created separate `elastic_ip_invalid_combination` yaml file to test the `InvalidParameterCombination` terminal condition. Initially added `IPV4Pool` and `address` in the same `elastic_ip_address.yaml` file but tests failed as spec's required for each test were different, so added a separate yaml file in order to easily differentiate the valid and invalid spec combinations of resources for future use. By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent b877c7f commit c6afdbc

File tree

8 files changed

+80
-54
lines changed

8 files changed

+80
-54
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-08-15T17:56:40Z"
2+
build_date: "2022-08-15T18:59:03Z"
33
build_hash: 87477ae8ca8ac6ddb8c565bbd910cc7e30f55ed0
44
go_version: go1.18.3
55
version: v0.19.3
66
api_directory_checksum: ff86d89efc3212fed4eb14bdc83af54601428a83
77
api_version: v1alpha1
88
aws_sdk_go_version: v1.42.0
99
generator_config_info:
10-
file_checksum: ca6ca773378da313559135dd2c614353077be06f
10+
file_checksum: 2b16ea041c64881794dd4167b1388dd2210045fb
1111
original_file_name: generator.yaml
1212
last_modification:
1313
reason: API generation

apis/v1alpha1/generator.yaml

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -196,24 +196,8 @@ resources:
196196
ElasticIPAddress:
197197
exceptions:
198198
terminal_codes:
199-
- IdempotentParameterMismatch
200-
- InvalidAction
201-
- InvalidCharacter
202-
- InvalidClientTokenId
203-
- InvalidPaginationToken
204-
- InvalidParameter
205199
- InvalidParameterCombination
206200
- InvalidParameterValue
207-
- InvalidQueryParameter
208-
- MalformedQueryString
209-
- MissingAction
210-
- MissingAuthenticationToken
211-
- MissingParameter
212-
- UnknownParameter
213-
- UnsupportedInstanceAttribute
214-
- UnsupportedOperation
215-
- UnsupportedProtocol
216-
- ValidationError
217201
fields:
218202
AllocationId:
219203
is_primary_key: true

generator.yaml

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -196,24 +196,8 @@ resources:
196196
ElasticIPAddress:
197197
exceptions:
198198
terminal_codes:
199-
- IdempotentParameterMismatch
200-
- InvalidAction
201-
- InvalidCharacter
202-
- InvalidClientTokenId
203-
- InvalidPaginationToken
204-
- InvalidParameter
205199
- InvalidParameterCombination
206200
- InvalidParameterValue
207-
- InvalidQueryParameter
208-
- MalformedQueryString
209-
- MissingAction
210-
- MissingAuthenticationToken
211-
- MissingParameter
212-
- UnknownParameter
213-
- UnsupportedInstanceAttribute
214-
- UnsupportedOperation
215-
- UnsupportedProtocol
216-
- ValidationError
217201
fields:
218202
AllocationId:
219203
is_primary_key: true

pkg/resource/elastic_ip_address/sdk.go

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

test/e2e/resources/elastic_ip_address.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ kind: ElasticIPAddress
33
metadata:
44
name: $ADDRESS_NAME
55
spec:
6-
domain: vpc
6+
domain: vpc
7+
publicIPv4Pool: $PUBLIC_IPV4_POOL
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
apiVersion: ec2.services.k8s.aws/v1alpha1
2+
kind: ElasticIPAddress
3+
metadata:
4+
name: $ADDRESS_NAME
5+
spec:
6+
domain: vpc
7+
publicIPv4Pool: $PUBLIC_IPV4_POOL
8+
address: $ADDRESS

test/e2e/tests/test_elastic_ip_address.py

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ def test_create_delete(self, ec2_client):
5353
resource_name = random_suffix_name("elastic-ip-ack-test", 24)
5454
replacements = REPLACEMENT_VALUES.copy()
5555
replacements["ADDRESS_NAME"] = resource_name
56+
replacements["PUBLIC_IPV4_POOL"] = "amazon"
5657

5758
# Load ElasticIPAddress CR
5859
resource_data = load_ec2_resource(
@@ -89,4 +90,67 @@ def test_create_delete(self, ec2_client):
8990

9091
# Check Address doesn't exist
9192
exists = address_exists(ec2_client, resource_id)
92-
assert not exists
93+
assert not exists
94+
95+
def test_terminal_condition_invalid_parameter_value(self):
96+
resource_name = random_suffix_name("elastic-ip-ack-fail-1", 24)
97+
test_resource_values = REPLACEMENT_VALUES.copy()
98+
test_resource_values["ADDRESS_NAME"] = resource_name
99+
test_resource_values["PUBLIC_IPV4_POOL"] = "InvalidIpV4Address"
100+
101+
# Load ElasticIPAddress CR
102+
resource_data = load_ec2_resource(
103+
"elastic_ip_address",
104+
additional_replacements=test_resource_values,
105+
)
106+
logging.debug(resource_data)
107+
108+
# Create k8s resource
109+
ref = k8s.CustomResourceReference(
110+
CRD_GROUP, CRD_VERSION, RESOURCE_PLURAL,
111+
resource_name, namespace="default",
112+
)
113+
k8s.create_custom_resource(ref, resource_data)
114+
cr = k8s.wait_resource_consumed_by_controller(ref)
115+
116+
assert cr is not None
117+
assert k8s.get_resource_exists(ref)
118+
119+
expected_msg = "InvalidParameterValue: invalid value for parameter pool: InvalidIpV4Address"
120+
terminal_condition = k8s.get_resource_condition(ref, "ACK.Terminal")
121+
# Example condition message:
122+
# An error occurred (InvalidParameterValue) when calling the AllocateAddress operation:
123+
# invalid value for parameter pool: InvalidIpV4Address
124+
assert expected_msg in terminal_condition['message']
125+
126+
def test_terminal_condition_invalid_parameter_combination(self):
127+
resource_name = random_suffix_name("elastic-ip-ack-fail-2", 24)
128+
test_resource_values = REPLACEMENT_VALUES.copy()
129+
test_resource_values["ADDRESS_NAME"] = resource_name
130+
test_resource_values["PUBLIC_IPV4_POOL"] = "amazon"
131+
test_resource_values["ADDRESS"] = "52.27.68.220"
132+
133+
# Load ElasticIPAddress CR
134+
resource_data = load_ec2_resource(
135+
"invalid/elastic_ip_invalid_combination",
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 = "InvalidParameterCombination: The parameter PublicIpv4Pool cannot be used with the parameter Address"
152+
terminal_condition = k8s.get_resource_condition(ref, "ACK.Terminal")
153+
# Example condition message:
154+
# An error occurred (InvalidParameterCombination) when calling the AllocateAddress operation:
155+
# The parameter PublicIpv4Pool cannot be used with the parameter Address
156+
assert expected_msg in terminal_condition['message']

test/e2e/tests/test_nat_gateway.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ def standard_elastic_address():
3737

3838
replacements = REPLACEMENT_VALUES.copy()
3939
replacements["ADDRESS_NAME"] = cluster_name
40+
replacements["PUBLIC_IPV4_POOL"] = "amazon"
4041

4142
resource_data = load_ec2_resource(
4243
"elastic_ip_address",

0 commit comments

Comments
 (0)