Ejemplo n.º 1
0
    def execute(self, context):
        eks_hook = EKSHook(
            aws_conn_id=self.aws_conn_id,
            region_name=self.region,
        )

        eks_hook.delete_nodegroup(clusterName=self.cluster_name, nodegroupName=self.nodegroup_name)
Ejemplo n.º 2
0
    def execute(self, context):
        eks_hook = EKSHook(
            aws_conn_id=self.aws_conn_id,
            region_name=self.region,
        )

        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)

                # 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):
                    if countdown >= CHECK_INTERVAL_SECONDS:
                        countdown -= CHECK_INTERVAL_SECONDS
                        sleep(CHECK_INTERVAL_SECONDS)
                        self.log.info(
                            "Waiting for the remaining %s nodegroups to delete.  "
                            "Checking again in %d seconds.",
                            nodegroup_count,
                            CHECK_INTERVAL_SECONDS,
                        )
                    else:
                        raise RuntimeError(
                            "Nodegroups are still inactive after the allocated time limit.  Aborting."
                        )
            self.log.info("No nodegroups remain, deleting cluster.")

        eks_hook.delete_cluster(name=self.cluster_name)