mik-laj commented on a change in pull request #18645:
URL: https://github.com/apache/airflow/pull/18645#discussion_r719868965
##########
File path: airflow/providers/amazon/aws/operators/eks.py
##########
@@ -280,41 +409,83 @@ def execute(self, context):
)
if self.force_delete_compute:
- nodegroups =
eks_hook.list_nodegroups(clusterName=self.cluster_name)
- nodegroup_count = len(nodegroups)
- if nodegroup_count:
- self.log.info(
- "A cluster can not be deleted with attached nodegroups.
Deleting %d nodegroups.",
- nodegroup_count,
- )
- for group in nodegroups:
- eks_hook.delete_nodegroup(clusterName=self.cluster_name,
nodegroupName=group)
+ self.delete_any_nodegroups(eks_hook)
+ self.delete_any_fargate_profiles(eks_hook)
- # Scaling up the timeout based on the number of nodegroups
that are being processed.
- additional_seconds = 5 * 60
- countdown = TIMEOUT_SECONDS + (nodegroup_count *
additional_seconds)
- while eks_hook.list_nodegroups(clusterName=self.cluster_name):
+ eks_hook.delete_cluster(name=self.cluster_name)
+
+ def delete_any_nodegroups(self, eks_hook) -> None:
+ """
+ Deletes all Amazon EKS managed node groups for a provided Amazon EKS
Cluster.
+
+ Amazon EKS managed node groups can be deleted in parallel, so we can
send all
+ of the delete commands in bulk and move on once the count of
nodegroups is zero.
+ """
+ nodegroups = eks_hook.list_nodegroups(clusterName=self.cluster_name)
+ nodegroup_count = len(nodegroups)
+ if nodegroup_count:
+
self.log.info(CAN_NOT_DELETE_MSG.format(compute=NODEGROUP_FULL_NAME,
count=nodegroup_count))
Review comment:
```suggestion
if nodegroups:
self.log.info(CAN_NOT_DELETE_MSG.format(compute=NODEGROUP_FULL_NAME,
count=len(nodegroups)))
```
More pythonic approach.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]