Skip to content

Commit 944d51d

Browse files
committed
Add tests for adopting VPC endpoint service
1 parent 98e52a4 commit 944d51d

File tree

5 files changed

+128
-2
lines changed

5 files changed

+128
-2
lines changed

test/e2e/bootstrap_resources.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from acktest.bootstrapping.s3 import Bucket
2020
from acktest.bootstrapping.vpc import VPC
2121
from acktest.bootstrapping.vpc import TransitGateway
22+
from acktest.bootstrapping.vpc_endpoint_service import VpcEndpointServiceConfiguration
2223
from e2e import bootstrap_directory
2324

2425
@dataclass
@@ -28,6 +29,7 @@ class BootstrapResources(Resources):
2829
AdoptedVPC: VPC
2930
NetworkLoadBalancer: NetworkLoadBalancer
3031
TestTransitGateway: TransitGateway
32+
AdoptedVpcEndpointService: VpcEndpointServiceConfiguration
3133

3234
_bootstrap_resources = None
3335

test/e2e/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
acktest @ git+https://github.com/aws-controllers-k8s/test-infra.git@72e9d798ad4f22e0e1ff4e227cfd69f7e301479a
1+
acktest @ git+https://github.com/knottnt/ack-test-infra.git@93adae31a050a11a67567e1e8d3c440b47f4044e
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
apiVersion: ec2.services.k8s.aws/v1alpha1
2+
kind: VPCEndpointServiceConfiguration
3+
metadata:
4+
name: $VPC_ENDPOINT_SERVICE_ADOPTED_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
9+
spec: {}

test/e2e/service_bootstrap.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from acktest.bootstrapping.elbv2 import NetworkLoadBalancer
2020
from acktest.bootstrapping.vpc import VPC
2121
from acktest.bootstrapping.vpc import TransitGateway
22+
from acktest.bootstrapping.vpc_endpoint_service import VpcEndpointServiceConfiguration
2223
from acktest.bootstrapping.s3 import Bucket
2324
from e2e import bootstrap_directory
2425
from e2e.bootstrap_resources import BootstrapResources
@@ -37,7 +38,8 @@ def service_bootstrap() -> Resources:
3738
),
3839
NetworkLoadBalancer=NetworkLoadBalancer("e2e-vpc-ep-service-test"),
3940
AdoptedVPC=VPC(name_prefix="e2e-adopted-vpc", num_public_subnet=1, num_private_subnet=0),
40-
TestTransitGateway=TransitGateway()
41+
TestTransitGateway=TransitGateway(),
42+
AdoptedVpcEndpointService=VpcEndpointServiceConfiguration(name_prefix="e2e-adopted-vpc-es"),
4143
)
4244

4345
try:
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
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 Endpoint Service Configuraion Adoption.
15+
"""
16+
17+
# Default to us-west-2 since that's where prow is deployed
18+
import logging
19+
from os import environ
20+
import time
21+
22+
import pytest
23+
24+
from e2e import service_marker
25+
from e2e import CRD_GROUP, CRD_VERSION, load_ec2_resource
26+
from e2e.bootstrap_resources import get_bootstrap_resources
27+
from e2e.replacement_values import REPLACEMENT_VALUES
28+
from acktest.resources import random_suffix_name
29+
from acktest.k8s import resource as k8s
30+
31+
from e2e.tests.helper import EC2Validator
32+
33+
34+
REGION = "us-west-2" if environ.get('AWS_DEFAULT_REGION') is None else environ.get('AWS_DEFAULT_REGION')
35+
RESOURCE_PLURAL = "vpcendpointserviceconfigurations"
36+
37+
CREATE_WAIT_AFTER_SECONDS = 10
38+
DELETE_WAIT_AFTER_SECONDS = 10
39+
MODIFY_WAIT_AFTER_SECONDS = 5
40+
41+
@pytest.fixture
42+
def vpc_endpoint_service_adoption():
43+
replacements = REPLACEMENT_VALUES.copy()
44+
resource_name = random_suffix_name("vpc-es-adoption", 32)
45+
service_id = get_bootstrap_resources().AdoptedVpcEndpointService.service_id
46+
replacements["VPC_ADOPTION_NAME"] = resource_name
47+
replacements["ADOPTION_POLICY"] = "adopt"
48+
replacements["ADOPTION_FIELDS"] = f"{{\\\"serviceId\\\": \\\"{service_id}\\\"}}"
49+
50+
resource_data = load_ec2_resource(
51+
"vpc_endpoint_service_adoption",
52+
additional_replacements=replacements,
53+
)
54+
logging.debug(resource_data)
55+
56+
ref = k8s.CustomResourceReference(
57+
CRD_GROUP, CRD_VERSION, RESOURCE_PLURAL,
58+
resource_name, namespace="default",
59+
)
60+
61+
k8s.create_custom_resource(ref, resource_data)
62+
time.sleep(CREATE_WAIT_AFTER_SECONDS)
63+
64+
cr = k8s.wait_resource_consumed_by_controller(ref)
65+
assert cr is not None
66+
assert k8s.get_resource_exists(ref)
67+
68+
yield (ref, cr)
69+
70+
_, deleted = k8s.delete_custom_resource(ref, DELETE_WAIT_AFTER_SECONDS)
71+
assert deleted
72+
73+
@service_marker
74+
@pytest.mark.canary
75+
class TestVpcAdoption:
76+
77+
def test_vpc_endpoint_service_configuration_adopt_update(self, ec2_client, vpc_endpoint_service_adoption):
78+
(ref, cr) = vpc_endpoint_service_adoption
79+
80+
assert cr is not None
81+
assert 'status' in cr
82+
assert 'serviceID' in cr['status']
83+
resource_id = cr['status']['serviceID']
84+
85+
assert 'spec' in cr
86+
assert 'tags' in cr['spec']
87+
88+
# Check VPC Endpoint Service exists in AWS
89+
ec2_validator = EC2Validator(ec2_client)
90+
ec2_validator.assert_vpc_endpoint_service_configuration(resource_id)
91+
92+
endpoint_service_config = ec2_validator.get_vpc_endpoint_service_configuration(resource_id)
93+
assert len(endpoint_service_config['Tags']) == 1
94+
current_tag = endpoint_service_config['Tags'][0]
95+
new_tag = {'Key': 'TestName', 'Value': 'test-value'}
96+
97+
updates = {
98+
"spec": {"tags": [current_tag, new_tag]}
99+
}
100+
k8s.patch_custom_resource(ref, updates)
101+
time.sleep(MODIFY_WAIT_AFTER_SECONDS)
102+
103+
assert k8s.wait_on_condition(ref, "ACK.ResourceSynced", "True", wait_periods=5)
104+
105+
endpoint_service_config = ec2_validator.get_vpc_endpoint_service_configuration(resource_id)
106+
assert len(endpoint_service_config['Tags']) == 2
107+
assert endpoint_service_config['Tags'][0] == current_tag
108+
assert endpoint_service_config['Tags'][1] == new_tag
109+
110+
111+
112+
113+

0 commit comments

Comments
 (0)