def destroy_teams(context: "Context") -> None: stack_name: str = f"orbit-{context.name}" final_eks_stack_name: str = f"eksctl-{stack_name}-cluster" _logger.debug("EKSCTL stack name: %s", final_eks_stack_name) cluster_name = f"orbit-{context.name}" if cfn.does_stack_exist(stack_name=final_eks_stack_name) and context.teams: for team in context.teams: eks.delete_fargate_profile( profile_name=f"orbit-{context.name}-{team.name}", cluster_name=cluster_name, ) username = f"orbit-{context.name}-{team.name}-runner" arn = f"arn:aws:iam::{context.account_id}:role/{username}" for line in sh.run_iterating(f"eksctl get iamidentitymapping --cluster {cluster_name} --arn {arn}"): if line == f'Error: no iamidentitymapping with arn "{arn}" found': _logger.debug(f"Skipping non-existent IAM Identity Mapping - Role: {arn}") break else: _logger.debug(f"Removing IAM Identity Mapping - Role: {arn}") sh.run(f"eksctl delete iamidentitymapping --cluster {cluster_name} --arn {arn}") username = f"orbit-{context.name}-{team.name}" arn = cast(str, team.eks_pod_role_arn) for line in sh.run_iterating(f"eksctl get iamidentitymapping --cluster {cluster_name} --arn {arn}"): if line == f'Error: no iamidentitymapping with arn "{arn}" found': _logger.debug(f"Skipping non-existent IAM Identity Mapping - Role: {arn}") break else: _logger.debug(f"Removing IAM Identity Mapping - Role: {arn}") sh.run(f"eksctl delete iamidentitymapping --cluster {cluster_name} --arn {arn}") _logger.debug("EKSCTL Teams destroyed")
def delete_system_fargate_profile(context: Context) -> None: cluster_name = f"orbit-{context.name}" eks_stack_name = f"eksctl-{cluster_name}-cluster" if cfn.does_stack_exist( stack_name=eks_stack_name ) and not context.networking.data.internet_accessible: fargate_profile = f"orbit-{context.name}-system" _logger.info(f"Deleting Fargate Profile: {fargate_profile}") eks.delete_fargate_profile( profile_name=fargate_profile, cluster_name=cluster_name, ) else: _logger.info("Skipping Fargate Profile Deletion")