ci: read the EKS cluster name from Terraform state, not from outputs - #38731
Conversation
bosconi
left a comment
There was a problem hiding this comment.
Looks good. TIL about the output going away before the resources.
QA LLM Review1. MEDIUM -- unblock_destroy now really fires, and deletes healthy node groups, killing Karpenter mid-teardown
This PR is what makes DetailsIn the scenario the hook targets, this is harmless: the destroy got all the way to the cluster delete, so Terraform has already torn down The divergence is when the destroy fails earlier. Two supporting details: Suggested fix, gate on status so only the stuck node group is touched and only it is waited on: def _node_group_status(self, cluster: str, node_group: str) -> str:
"""Node group status, empty if it cannot be read."""
try:
return json.loads(
spawn.capture([
"aws", "eks", "describe-nodegroup",
"--cluster-name", cluster,
"--nodegroup-name", node_group,
"--region", "us-east-1",
"--output", "json",
])
)["nodegroup"]["status"]
except (subprocess.CalledProcessError, json.JSONDecodeError, KeyError):
return ""then in |
|
Good catch, fixed in 2ac511f. I verified the Karpenter dependency before taking it:
|
Follow-up to #38721, which does not work.
unblock_destroytook the cluster name fromterraform output -raw eks_cluster_name, but a destroy removes the root outputs before the resources they reference, so by the time a destroy has failed the state has no outputs left while the cluster is still in it.terraform output -rawthen exits 0 and writes a 540-character "No outputs found" warning to stdout rather than stderr, so noCalledProcessErrorfires and theif not clusterguard sees a non-empty string. The banner was passed toaws eks list-nodegroups --cluster-name, which failed, and the swallowed error left the hook silently inert: the leak it targets still happened, with no log line to say so. Thanks @def- for catching it._eks_cluster_namenow reads theaws_eks_clusterresource out ofterraform state pull, since resources survive a failed destroy, and requires the name to match[A-Za-z0-9][A-Za-z0-9_-]*so no future unexpected stdout can reach the AWS CLI. It also logs when no cluster is found, so an inert hook is distinguishable from one that ran with nothing to do.Test plan
The reported behavior is confirmed against the CI-pinned Terraform 1.13.5: with a state carrying resources and
"outputs": {},terraform output -raw eks_cluster_nameexits 0 with 540 bytes on stdout and nothing on stderr. The new parser was exercised against the real leaked state from Nightly 18272 and returnsaws-test-dev-eksboth as uploaded and with its outputs stripped, returns empty for a fully destroyed state, and rejects the warning banner as a name. End to end it still needs a destroy that fails with a node group attached, so the AWS nightlies remain the real check.🤖 Generated with Claude Code