@@ -116,6 +116,9 @@ def test_create_delete(self, ec2_client):
116116 assert cr is not None
117117 assert k8s .get_resource_exists (ref )
118118
119+ # Check resource synced successfully
120+ assert k8s .wait_on_condition (ref , "ACK.ResourceSynced" , "True" , wait_periods = 5 )
121+
119122 resource = k8s .get_resource (ref )
120123 resource_id = resource ["status" ]["subnetID" ]
121124
@@ -134,6 +137,101 @@ def test_create_delete(self, ec2_client):
134137 # Check Subnet no longer exists in AWS
135138 ec2_validator .assert_subnet (resource_id , exists = False )
136139
140+ def test_crud_tags (self , ec2_client ):
141+ test_resource_values = REPLACEMENT_VALUES .copy ()
142+ resource_name = random_suffix_name ("subnet-test" , 24 )
143+ test_vpc = get_bootstrap_resources ().SharedTestVPC
144+ vpc_id = test_vpc .vpc_id
145+
146+ test_resource_values ["SUBNET_NAME" ] = resource_name
147+ test_resource_values ["VPC_ID" ] = vpc_id
148+ # CIDR needs to be within SharedTestVPC range and not overlap other subnets
149+ test_resource_values ["CIDR_BLOCK" ] = "10.0.255.0/24"
150+ test_resource_values ["KEY" ] = "initialtagkey"
151+ test_resource_values ["VALUE" ] = "initialtagvalue"
152+
153+ # Load Subnet CR
154+ resource_data = load_ec2_resource (
155+ "subnet" ,
156+ additional_replacements = test_resource_values ,
157+ )
158+ logging .debug (resource_data )
159+
160+ # Create k8s resource
161+ ref = k8s .CustomResourceReference (
162+ CRD_GROUP , CRD_VERSION , RESOURCE_PLURAL ,
163+ resource_name , namespace = "default" ,
164+ )
165+ k8s .create_custom_resource (ref , resource_data )
166+ cr = k8s .wait_resource_consumed_by_controller (ref )
167+
168+ assert cr is not None
169+ assert k8s .get_resource_exists (ref )
170+
171+ # Check resource synced successfully
172+ assert k8s .wait_on_condition (ref , "ACK.ResourceSynced" , "True" , wait_periods = 5 )
173+
174+ resource = k8s .get_resource (ref )
175+ resource_id = resource ["status" ]["subnetID" ]
176+ time .sleep (CREATE_WAIT_AFTER_SECONDS )
177+
178+ # Check Subnet exists in AWS
179+ ec2_validator = EC2Validator (ec2_client )
180+ ec2_validator .assert_subnet (resource_id )
181+
182+ # Check tags exist for subnet resource
183+ assert resource ["spec" ]["tags" ][0 ]["key" ] == "initialtagkey"
184+ assert resource ["spec" ]["tags" ][0 ]["value" ] == "initialtagvalue"
185+
186+ # New pair of tags
187+ new_tags = [
188+ {
189+ "key" : "updatedtagkey" ,
190+ "value" : "updatedtagvalue" ,
191+ }
192+
193+ ]
194+
195+ # Patch the subnet, updating the tags with new pair
196+ updates = {
197+ "spec" : {"tags" : new_tags },
198+ }
199+
200+ k8s .patch_custom_resource (ref , updates )
201+ time .sleep (MODIFY_WAIT_AFTER_SECONDS )
202+
203+ # Check resource synced successfully
204+ assert k8s .wait_on_condition (ref , "ACK.ResourceSynced" , "True" , wait_periods = 5 )
205+
206+ # Assert tags are updated for subnet resource
207+ resource = k8s .get_resource (ref )
208+ assert resource ["spec" ]["tags" ][0 ]["key" ] == "updatedtagkey"
209+ assert resource ["spec" ]["tags" ][0 ]["value" ] == "updatedtagvalue"
210+
211+ # Patch the subnet resource, deleting the tags
212+ updates = {
213+ "spec" : {"tags" : []},
214+ }
215+
216+ k8s .patch_custom_resource (ref , updates )
217+ time .sleep (MODIFY_WAIT_AFTER_SECONDS )
218+
219+ # Check resource synced successfully
220+ assert k8s .wait_on_condition (ref , "ACK.ResourceSynced" , "True" , wait_periods = 5 )
221+
222+ # Assert tags are deleted
223+ resource = k8s .get_resource (ref )
224+ assert len (resource ['spec' ]['tags' ]) == 0
225+
226+ # Delete k8s resource
227+ _ , deleted = k8s .delete_custom_resource (ref )
228+ assert deleted is True
229+
230+ time .sleep (DELETE_WAIT_AFTER_SECONDS )
231+
232+ # Check Subnet no longer exists in AWS
233+ ec2_validator .assert_subnet (resource_id , exists = False )
234+
137235 def test_route_table_assocations (self , ec2_client , default_route_tables ):
138236 test_resource_values = REPLACEMENT_VALUES .copy ()
139237 resource_name = random_suffix_name ("subnet-test" , 24 )
@@ -165,6 +263,9 @@ def test_route_table_assocations(self, ec2_client, default_route_tables):
165263 assert cr is not None
166264 assert k8s .get_resource_exists (ref )
167265
266+ # Check resource synced successfully
267+ assert k8s .wait_on_condition (ref , "ACK.ResourceSynced" , "True" , wait_periods = 5 )
268+
168269 resource = k8s .get_resource (ref )
169270 resource_id = resource ["status" ]["subnetID" ]
170271
@@ -185,6 +286,9 @@ def test_route_table_assocations(self, ec2_client, default_route_tables):
185286 k8s .patch_custom_resource (ref , updates )
186287 time .sleep (MODIFY_WAIT_AFTER_SECONDS )
187288
289+ # Check resource synced successfully
290+ assert k8s .wait_on_condition (ref , "ACK.ResourceSynced" , "True" , wait_periods = 5 )
291+
188292 assert ec2_validator .get_route_table_association (initial_rt_cr ["status" ]["routeTableID" ], resource_id ) is None
189293 assert ec2_validator .get_route_table_association (default_route_tables [1 ][1 ]["status" ]["routeTableID" ], resource_id ) is not None
190294
0 commit comments