Skip to content

Commit 7175d52

Browse files
authored
Merge branch 'main' into ack-bot/rt-v0.40.0-codegen-v0.40.0
2 parents 3625f67 + e03df45 commit 7175d52

11 files changed

+241
-2
lines changed

apis/v1alpha1/ack-generate-metadata.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ api_directory_checksum: 585098fc7c99c27ca523f83e860107d22aaa5a10
77
api_version: v1alpha1
88
aws_sdk_go_version: v1.44.93
99
generator_config_info:
10-
file_checksum: 2c5ef491ef62c9347bcb87918f715692adf727bc
10+
file_checksum: 4a977c2334f44fd0ea8d09dd6afe759cd7459eb1
1111
original_file_name: generator.yaml
1212
last_modification:
1313
reason: API generation

apis/v1alpha1/generator.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,8 @@ resources:
351351
template_path: hooks/flow_log/sdk_file_end.go.tpl
352352
post_set_resource_identifiers:
353353
template_path: hooks/flow_log/post_set_resource_identifiers.go.tpl
354+
post_populate_resource_from_annotation:
355+
template_path: hooks/flow_log/post_populate_resource_from_annotation.go.tpl
354356
update_operation:
355357
custom_method_name: customUpdateFlowLog
356358
InternetGateway:

generator.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,8 @@ resources:
351351
template_path: hooks/flow_log/sdk_file_end.go.tpl
352352
post_set_resource_identifiers:
353353
template_path: hooks/flow_log/post_set_resource_identifiers.go.tpl
354+
post_populate_resource_from_annotation:
355+
template_path: hooks/flow_log/post_populate_resource_from_annotation.go.tpl
354356
update_operation:
355357
custom_method_name: customUpdateFlowLog
356358
InternetGateway:

pkg/resource/flow_log/resource.go

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
if resourceID, ok := fields["resourceID"]; ok {
2+
r.ko.Spec.ResourceID = &resourceID
3+
} else {
4+
return ackerrors.MissingNameIdentifier
5+
}
6+
7+
if resourceType, ok := fields["resourceType"]; ok {
8+
r.ko.Spec.ResourceType = &resourceType
9+
} else {
10+
return ackerrors.MissingNameIdentifier
11+
}

test/e2e/bootstrap_resources.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
class BootstrapResources(Resources):
2525
FlowLogsBucket: Bucket
2626
SharedTestVPC: VPC
27+
AdoptedVPC: VPC
2728
NetworkLoadBalancer: NetworkLoadBalancer
2829

2930
_bootstrap_resources = None
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: Subnet
3+
metadata:
4+
name: $SUBNET_ADOPTION_NAME
5+
annotations:
6+
services.k8s.aws/adoption-policy: $ADOPTION_POLICY
7+
services.k8s.aws/adoption-fields: "$ADOPTION_FIELDS"
8+
services.k8s.aws/deletion-policy: retain

test/e2e/resources/vpc_adoption.yaml

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: VPC
3+
metadata:
4+
name: $VPC_ADOPTION_NAME
5+
annotations:
6+
services.k8s.aws/adoption-policy: $ADOPTION_POLICY
7+
services.k8s.aws/adoption-fields: "$ADOPTION_FIELDS"
8+
services.k8s.aws/deletion-policy: retain

test/e2e/service_bootstrap.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ def service_bootstrap() -> Resources:
3030
FlowLogsBucket=Bucket(
3131
"ack-ec2-controller-flow-log-tests",
3232
),
33-
NetworkLoadBalancer=NetworkLoadBalancer("e2e-vpc-ep-service-test")
33+
NetworkLoadBalancer=NetworkLoadBalancer("e2e-vpc-ep-service-test"),
34+
AdoptedVPC=VPC(name_prefix="e2e-adopted-vpc", num_public_subnet=1, num_private_subnet=0)
3435
)
3536

3637
try:
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
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+
"""Integration tests for the Subnet Adoption API.
15+
"""
16+
17+
import pytest
18+
import time
19+
import logging
20+
21+
from acktest import tags
22+
from acktest.resources import random_suffix_name
23+
from acktest.k8s import resource as k8s
24+
from e2e import service_marker, CRD_GROUP, CRD_VERSION, load_ec2_resource
25+
from e2e.bootstrap_resources import get_bootstrap_resources
26+
from e2e.replacement_values import REPLACEMENT_VALUES
27+
from e2e.tests.helper import EC2Validator
28+
29+
SUBNET_RESOURCE_PLURAL = "subnets"
30+
31+
CREATE_WAIT_AFTER_SECONDS = 10
32+
UPDATE_WAIT_AFTER_SECONDS = 10
33+
DELETE_WAIT_AFTER_SECONDS = 10
34+
35+
@pytest.fixture
36+
def subnet_adoption(request):
37+
replacements = REPLACEMENT_VALUES.copy()
38+
resource_name = random_suffix_name("subnet-adoption", 32)
39+
subnet_id = get_bootstrap_resources().AdoptedVPC.public_subnets.subnet_ids[0]
40+
replacements["SUBNET_ADOPTION_NAME"] = resource_name
41+
replacements["ADOPTION_POLICY"] = "adopt"
42+
replacements["ADOPTION_FIELDS"] = f"{{\\\"subnetID\\\": \\\"{subnet_id}\\\"}}"
43+
44+
resource_data = load_ec2_resource(
45+
"subnet_adoption",
46+
additional_replacements=replacements,
47+
)
48+
logging.debug(resource_data)
49+
50+
ref = k8s.CustomResourceReference(
51+
CRD_GROUP, CRD_VERSION, SUBNET_RESOURCE_PLURAL,
52+
resource_name, namespace="default",
53+
)
54+
k8s.create_custom_resource(ref, resource_data)
55+
time.sleep(CREATE_WAIT_AFTER_SECONDS)
56+
57+
cr = k8s.wait_resource_consumed_by_controller(ref)
58+
assert cr is not None
59+
assert k8s.get_resource_exists(ref)
60+
61+
yield (ref, cr)
62+
63+
_, deleted = k8s.delete_custom_resource(ref, DELETE_WAIT_AFTER_SECONDS)
64+
assert deleted
65+
66+
67+
@service_marker
68+
@pytest.mark.canary
69+
class TestSubnetAdoption:
70+
def test_subnet_adopt_update(self, ec2_client, subnet_adoption):
71+
(ref, cr) = subnet_adoption
72+
73+
assert cr is not None
74+
assert 'status' in cr
75+
assert 'subnetID' in cr['status']
76+
resource_id = cr['status']['subnetID']
77+
78+
assert 'spec' in cr
79+
assert 'vpcID' in cr['spec']
80+
assert 'mapPublicIPOnLaunch' in cr['spec']
81+
mapPublicIPOnLaunch = not cr['spec']['mapPublicIPOnLaunch']
82+
# Check Subnet exists in AWS
83+
ec2_validator = EC2Validator(ec2_client)
84+
ec2_validator.assert_subnet(resource_id)
85+
86+
updates = {
87+
"spec": {"mapPublicIPOnLaunch": mapPublicIPOnLaunch},
88+
}
89+
k8s.patch_custom_resource(ref, updates)
90+
time.sleep(UPDATE_WAIT_AFTER_SECONDS)
91+
92+
assert k8s.wait_on_condition(ref, "ACK.ResourceSynced", "True", wait_periods=5)
93+
subnet = ec2_validator.get_subnet(resource_id)
94+
assert subnet['MapPublicIpOnLaunch'] == mapPublicIPOnLaunch

test/e2e/tests/test_vpc_adoption.py

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
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+
"""Integration tests for the Vpc Adoption API.
15+
"""
16+
17+
import pytest
18+
import time
19+
import logging
20+
21+
from acktest import tags
22+
from acktest.resources import random_suffix_name
23+
from acktest.k8s import resource as k8s
24+
from e2e import service_marker, CRD_GROUP, CRD_VERSION, load_ec2_resource
25+
from e2e.bootstrap_resources import get_bootstrap_resources
26+
from e2e.replacement_values import REPLACEMENT_VALUES
27+
from e2e.tests.helper import EC2Validator
28+
29+
VPC_RESOURCE_PLURAL = "vpcs"
30+
31+
CREATE_WAIT_AFTER_SECONDS = 10
32+
UPDATE_WAIT_AFTER_SECONDS = 10
33+
DELETE_WAIT_AFTER_SECONDS = 10
34+
35+
@pytest.fixture
36+
def vpc_adoption(request):
37+
replacements = REPLACEMENT_VALUES.copy()
38+
resource_name = random_suffix_name("vpc-adoption", 32)
39+
vpc_id = get_bootstrap_resources().AdoptedVPC.vpc_id
40+
replacements["VPC_ADOPTION_NAME"] = resource_name
41+
replacements["ADOPTION_POLICY"] = "adopt"
42+
replacements["ADOPTION_FIELDS"] = f"{{\\\"vpcID\\\": \\\"{vpc_id}\\\"}}"
43+
44+
resource_data = load_ec2_resource(
45+
"vpc_adoption",
46+
additional_replacements=replacements,
47+
)
48+
logging.debug(resource_data)
49+
50+
ref = k8s.CustomResourceReference(
51+
CRD_GROUP, CRD_VERSION, VPC_RESOURCE_PLURAL,
52+
resource_name, namespace="default",
53+
)
54+
k8s.create_custom_resource(ref, resource_data)
55+
time.sleep(CREATE_WAIT_AFTER_SECONDS)
56+
57+
cr = k8s.wait_resource_consumed_by_controller(ref)
58+
assert cr is not None
59+
assert k8s.get_resource_exists(ref)
60+
61+
yield (ref, cr)
62+
63+
_, deleted = k8s.delete_custom_resource(ref, DELETE_WAIT_AFTER_SECONDS)
64+
assert deleted
65+
66+
67+
@service_marker
68+
@pytest.mark.canary
69+
class TestVpcAdoption:
70+
def test_vpc_adopt_update(self, ec2_client, vpc_adoption):
71+
(ref, cr) = vpc_adoption
72+
73+
assert cr is not None
74+
assert 'status' in cr
75+
assert 'vpcID' in cr['status']
76+
resource_id = cr['status']['vpcID']
77+
78+
assert 'spec' in cr
79+
assert 'tags' in cr['spec']
80+
81+
# Check VPC exists in AWS
82+
ec2_validator = EC2Validator(ec2_client)
83+
ec2_validator.assert_vpc(resource_id)
84+
85+
vpc = ec2_validator.get_vpc(resource_id)
86+
assert len(vpc['CidrBlockAssociationSet']) == 1
87+
primary_cidr = vpc['CidrBlockAssociationSet'][0]['CidrBlock']
88+
secondary_cidr = "10.2.0.0/16"
89+
updates = {
90+
"spec": {"cidrBlocks": [primary_cidr, secondary_cidr]}
91+
}
92+
k8s.patch_custom_resource(ref, updates)
93+
time.sleep(UPDATE_WAIT_AFTER_SECONDS)
94+
95+
assert k8s.wait_on_condition(ref, "ACK.ResourceSynced", "True", wait_periods=5)
96+
97+
vpc = ec2_validator.get_vpc(resource_id)
98+
assert len(vpc['CidrBlockAssociationSet']) == 2
99+
assert vpc['CidrBlockAssociationSet'][0]['CidrBlock'] == primary_cidr
100+
assert vpc['CidrBlockAssociationSet'][1]['CidrBlock'] == secondary_cidr

0 commit comments

Comments
 (0)