@@ -192,7 +192,8 @@ def __generate_cluster_resources_list_by_vpc(self, resources_list: list, input_r
192192 @return:
193193 """
194194 result_resources_list = []
195- vpc_data = self .get_cluster_vpc ()
195+ vpcs_data = self .ec2_operations .get_vpcs ()
196+ vpc_data = self .get_cluster_vpc (vpcs_data = vpcs_data )
196197 for resource in resources_list :
197198 resource_id = resource [input_resource_id ]
198199 if resource .get ('VpcId' ):
@@ -202,10 +203,15 @@ def __generate_cluster_resources_list_by_vpc(self, resources_list: list, input_r
202203 all_tags .extend (vpc_data .get (vpc_id ))
203204 all_tags = self .__check_name_in_tags (tags = all_tags , resource_id = resource_id )
204205 all_tags = self .__filter_resource_tags_by_add_tags (resource .get ('Tags' ), all_tags )
205- cluster_tag = [tag for tag in vpc_data .get (vpc_id , []) if any (prefix in tag .get ('Key' , '' ) for prefix in self .cluster_prefix )]
206+ raw_vpc_tags = next (
207+ (v .get ('Tags' ) for v in vpcs_data if v .get ('VpcId' ) == vpc_id ),
208+ None ,
209+ ) or []
210+ cluster_tag = [t for t in raw_vpc_tags if
211+ any (prefix in t .get ('Key' , '' ) for prefix in self .cluster_prefix )]
206212 if all_tags :
207213 if self .cluster_name :
208- if self .cluster_name in cluster_tag [0 ].get ('Key' ):
214+ if cluster_tag and self .cluster_name in cluster_tag [0 ].get ('Key' , ' ' ):
209215 if self .dry_run == 'no' :
210216 self .utils .tag_aws_resources (client_method = self .ec2_client .create_tags ,
211217 resource_ids = [resource_id ], tags = all_tags )
@@ -572,19 +578,26 @@ def cluster_vpc(self):
572578 self .cluster_network_acl ()
573579 return sorted (vpc_ids )
574580
575- def get_cluster_vpc (self ):
581+ def get_cluster_vpc (self , vpcs_data : list = None ):
576582 """
577583 This method get cluster vpc ids and it's tags.
578584 Missing OpenShift Tags for it based on VPCs
579585 @return:
580586 """
581- vpcs_data = self .ec2_operations .get_vpcs ()
587+ if vpcs_data is None :
588+ vpcs_data = self .ec2_operations .get_vpcs ()
589+ cluster_prefix = environment_variables .environment_variables_dict ['CLUSTER_PREFIX' ]
590+ no_propagate_prefixes = tuple (p .split ('/' , 1 )[0 ] + '/' for p in cluster_prefix )
582591 vpc_ids = {}
583592 for vpc in vpcs_data :
584593 if vpc .get ('Tags' ):
585594 for tag in vpc .get ('Tags' ):
586595 if any (prefix in tag .get ('Key' , '' ) for prefix in self .cluster_prefix ):
587- vpc_ids [vpc .get ('VpcId' )] = [tag for tag in vpc .get ('Tags' ) if tag .get ('Key' ) != 'Name' ]
596+ vpc_ids [vpc .get ('VpcId' )] = [t for t in vpc .get ('Tags' ) if
597+ t .get ('Key' ) != 'Name' and
598+ not any ((t .get ('Key' ) or '' ).startswith (prefix )
599+ for prefix in self .cluster_prefix ) and
600+ not (t .get ('Key' ) or '' ).startswith (no_propagate_prefixes )]
588601 break
589602 return vpc_ids
590603
0 commit comments