Skip to content

[K8s] Rename checkPodAppCanceled to cleanupOrphanPodIfBatchTerminated and improve orphan pod log messages - #7620

Open
turboFei wants to merge 5 commits into
apache:masterfrom
turboFei:cleanup
Open

[K8s] Rename checkPodAppCanceled to cleanupOrphanPodIfBatchTerminated and improve orphan pod log messages#7620
turboFei wants to merge 5 commits into
apache:masterfrom
turboFei:cleanup

Conversation

@turboFei

@turboFei turboFei commented Aug 9, 2026

Copy link
Copy Markdown
Member

Why are the changes needed?

checkPodAppCanceled was misleading: the method handles two distinct orphan-pod scenarios:

  1. CANCELED batch — user explicitly canceled the batch, but the pod appeared after Kyuubi gave up tracking it.
  2. Submit-timeout batchkyuubi.engine.kubernetes.submit.timeout elapsed, Kyuubi recorded app state as NOT_FOUND and marked the batch FAILED, but the pod started up afterwards.
    In both cases the pod is orphaned (no owning session), and the old name only hinted at case 1.

Log messages were also vague ("try to delete the pod", "is in error state and application not found") — they didn't identify the pod as an orphan or state the delete action directly.

How was this patch tested?

The ERROR+NOT_FOUND branch (submit-timeout orphan pod cleanup) is a behavior change:
pods that previously went uncleared when a batch failed due to submit timeout will now
be deleted when the informer observes them. The rename and log changes are non-behavioral.

Manual verification: confirmed the orphan-pod cleanup path is triggered correctly
under the CANCELED and submit-timeout ERROR scenarios.

Was this patch authored or co-authored using generative AI tooling?

Assisted-by: Claude:claude-sonnet-4-6

Rename `checkPodAppCanceled` to `cleanupOrphanPodIfBatchTerminated` to
accurately reflect that both the CANCELED path and the submit-timeout
ERROR+NOT_FOUND path result in orphan pods that need cleanup.

Improve log messages to:
- Lead with "Found orphan pod" so the subject is the pod being deleted
- State the action directly ("deleting it") rather than hedging ("try to delete")
- Make the submit-timeout branch explicit about the causal chain
  (submit timeout elapsed → app state recorded as NOT_FOUND → pod arrived late)
Keep the original log messages as-is; only the method rename from
checkPodAppCanceled to cleanupOrphanPodIfBatchTerminated is intended.
Clarify that the ERROR+NOT_FOUND branch is triggered by submit timeout,
and that the pod being deleted is an orphan.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates Kyuubi’s Kubernetes engine pod event handling to better reflect (via naming and logs) the intent to clean up pods that become orphaned when a batch session has already terminated.

Changes:

  • Renames checkPodAppCanceled to cleanupOrphanPodIfBatchTerminated and updates call sites.
  • Adds an additional orphan-pod cleanup condition for ERROR + appState=NOT_FOUND (submit-timeout scenario).
  • Adjusts orphan-pod warning logs (partially) to be more descriptive.
Suppressed comments (2)

kyuubi-server/src/main/scala/org/apache/kyuubi/engine/KubernetesApplicationOperation.scala:589

  • The CANCELED-branch log message still doesn’t identify the pod as an orphan or state the delete action directly, which conflicts with the PR description’s stated logging improvements. Consider making the message explicit (orphan + deleting).
            warn(s"[$kubernetesInfo] Batch[$kyuubiUniqueKey] is canceled, " +
              s"try to delete the pod ${pod.getMetadata.getName}")

kyuubi-server/src/main/scala/org/apache/kyuubi/engine/KubernetesApplicationOperation.scala:595

  • This new ERROR + appState=NOT_FOUND branch changes behavior by deleting pods that previously would not be cleaned up by this code path. The PR description says there is “No behavior change” and that existing tests cover this branch, but there doesn’t appear to be any unit test exercising orphan-pod deletion in KubernetesApplicationOperationSuite (it currently only covers URL building and container-state mapping). Either adjust the PR description to reflect the behavior change and add a focused test for this branch, or move the behavior change to a separate PR.
          } else if (batchState.exists(_ == OperationState.ERROR) &&
            batch.flatMap(_.appState).exists(_ == ApplicationState.NOT_FOUND)) {
            warn(s"[$kubernetesInfo] Batch[$kyuubiUniqueKey] failed due to submit timeout" +
              s" (app state: NOT_FOUND), try to delete the orphan pod ${pod.getMetadata.getName}")
            deletePod(kubernetesInfo, pod.getMetadata.getName, kyuubiUniqueKey)

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants