3333ENDPOINT_SERVICE_NAME = "com.amazonaws.%s.s3" % REGION
3434
3535CREATE_WAIT_AFTER_SECONDS = 10
36- DELETE_WAIT_AFTER_SECONDS = 10
36+ DELETE_WAIT_AFTER_SECONDS = 180
3737MODIFY_WAIT_AFTER_SECONDS = 5
3838
3939@pytest .fixture
@@ -82,6 +82,57 @@ def simple_vpc_endpoint(request):
8282 assert deleted
8383 except :
8484 pass
85+
86+ @pytest .fixture
87+ def modify_vpc_endpoint (request ):
88+ test_resource_values = REPLACEMENT_VALUES .copy ()
89+ resource_name = random_suffix_name ("vpc-endpoint-test" , 24 )
90+ test_vpc = get_bootstrap_resources ().SharedTestVPC
91+ vpc_id = test_vpc .vpc_id
92+
93+ test_resource_values ["VPC_ENDPOINT_NAME" ] = resource_name
94+ test_resource_values ["SERVICE_NAME" ] = ENDPOINT_SERVICE_NAME
95+ test_resource_values ["VPC_ID" ] = vpc_id
96+ test_resource_values ["SUBNET_ID" ] = test_vpc .public_subnets .subnet_ids [0 ]
97+
98+
99+ marker = request .node .get_closest_marker ("resource_data" )
100+ if marker is not None :
101+ data = marker .args [0 ]
102+ if 'tag_key' in data :
103+ test_resource_values ["TAG_KEY" ] = data ["tag_key" ]
104+ if 'tag_value' in data :
105+ test_resource_values ["TAG_VALUE" ] = data ["tag_value" ]
106+
107+ # Load VPC Endpoint CR
108+ resource_data = load_ec2_resource (
109+ "vpc_endpoint_modify" ,
110+ additional_replacements = test_resource_values ,
111+ )
112+ logging .debug (resource_data )
113+
114+ # Create k8s resource
115+ ref = k8s .CustomResourceReference (
116+ CRD_GROUP , CRD_VERSION , RESOURCE_PLURAL ,
117+ resource_name , namespace = "default" ,
118+ )
119+ k8s .create_custom_resource (ref , resource_data )
120+ time .sleep (CREATE_WAIT_AFTER_SECONDS )
121+
122+ cr = k8s .wait_resource_consumed_by_controller (ref )
123+ assert cr is not None
124+ assert k8s .get_resource_exists (ref )
125+
126+ yield (ref , cr )
127+
128+ # Try to delete, if doesn't already exist
129+ try :
130+ _ , deleted = k8s .delete_custom_resource (ref , 3 , 10 )
131+ assert deleted
132+ except :
133+ pass
134+
135+
85136@service_marker
86137@pytest .mark .canary
87138class TestVpcEndpoint :
@@ -272,4 +323,51 @@ def test_terminal_condition_invalid_service(self):
272323
273324 expected_msg = "InvalidServiceName: The Vpc Endpoint Service 'InvalidService' does not exist"
274325 terminal_condition = k8s .get_resource_condition (ref , "ACK.Terminal" )
275- assert expected_msg in terminal_condition ['message' ]
326+ assert expected_msg in terminal_condition ['message' ]
327+
328+ def test_update_subnets (self , ec2_client , modify_vpc_endpoint ):
329+ (ref , cr ) = modify_vpc_endpoint
330+ resource_id = cr ["status" ]["vpcEndpointID" ]
331+
332+ time .sleep (CREATE_WAIT_AFTER_SECONDS )
333+
334+ # Check VPC Endpoint exists in AWS
335+ ec2_validator = EC2Validator (ec2_client )
336+ ec2_validator .assert_vpc_endpoint (resource_id )
337+
338+ # Get initial state
339+ vpc_endpoint = ec2_validator .get_vpc_endpoint (resource_id )
340+ initial_subnets = vpc_endpoint .get ("SubnetIds" , [])
341+
342+ # Get an additional subnet from the test VPC
343+ test_vpc = get_bootstrap_resources ().SharedTestVPC
344+ available_subnets = test_vpc .public_subnets .subnet_ids
345+ new_subnet = next (subnet for subnet in available_subnets if subnet not in initial_subnets )
346+
347+ # Update subnets
348+ updated_subnets = initial_subnets + [new_subnet ]
349+
350+ # Patch the VPC Endpoint
351+ updates = {
352+ "spec" : {"subnetIDs" : updated_subnets }
353+ }
354+
355+ k8s .patch_custom_resource (ref , updates )
356+ time .sleep (MODIFY_WAIT_AFTER_SECONDS )
357+
358+ # Check resource synced successfully
359+ assert k8s .wait_on_condition (
360+ ref , "ACK.ResourceSynced" , "True" , wait_periods = 5 )
361+
362+ # Verify the update in AWS
363+ vpc_endpoint = ec2_validator .get_vpc_endpoint (resource_id )
364+ assert set (vpc_endpoint ["SubnetIds" ]) == set (updated_subnets )
365+
366+ # Delete k8s resource
367+ _ , deleted = k8s .delete_custom_resource (ref )
368+ assert deleted is True
369+
370+ time .sleep (DELETE_WAIT_AFTER_SECONDS )
371+
372+ # Check VPC Endpoint no longer exists in AWS
373+ ec2_validator .assert_vpc_endpoint (resource_id , exists = False )
0 commit comments