Skip to content

Commit

Permalink
[KYUUBI #5714][FOLLOWUP] Fix NPE when deleting terminated application…
Browse files Browse the repository at this point in the history
… pod

# 🔍 Description
#5714 followup to prevent NPE when deleting pod.
## Issue References 🔗

This pull request fixes #

## Describe Your Solution 🔧

Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change.

## Types of changes 🔖

- [x] Bugfix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to change)

## Test Plan 🧪

#### Behavior Without This Pull Request ⚰️

#### Behavior With This Pull Request 🎉

#### Related Unit Tests

---

# Checklists
## 📝 Author Self Checklist

- [x] My code follows the [style guidelines](https://kyuubi.readthedocs.io/en/master/contributing/code/style.html) of this project
- [ ] I have performed a self-review
- [ ] I have commented my code, particularly in hard-to-understand areas
- [ ] I have made corresponding changes to the documentation
- [ ] My changes generate no new warnings
- [ ] I have added tests that prove my fix is effective or that my feature works
- [ ] New and existing unit tests pass locally with my changes
- [ ] This patch was not authored or co-authored using [Generative Tooling](https://www.apache.org/legal/generative-tooling.html)

## 📝 Committer Pre-Merge Checklist

- [x] Pull request title is okay.
- [ ] No license issues.
- [ ] Milestone correctly set?
- [ ] Test coverage is ok
- [ ] Assignees are selected.
- [ ] Minimum number of approvals
- [ ] No changes are requested

**Be nice. Be informative.**

Closes #5718 from turboFei/npe_fix.

Closes #5714

74349a3 [fwang12] nit
7093ed8 [Cheng Pan] Update kyuubi-server/src/main/scala/org/apache/kyuubi/engine/KubernetesApplicationOperation.scala
558381e [fwang12] fix npe
454be88 [fwang12] prevent npe

Lead-authored-by: fwang12 <[email protected]>
Co-authored-by: Cheng Pan <[email protected]>
Signed-off-by: fwang12 <[email protected]>
  • Loading branch information
turboFei and pan3793 committed Nov 17, 2023
1 parent 3ec97fd commit d4fa6fd
Showing 1 changed file with 15 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,25 +105,31 @@ class KubernetesApplicationOperation extends ApplicationOperation with Logging {
.expireAfterWrite(retainPeriod, TimeUnit.MILLISECONDS)
.removalListener((notification: RemovalNotification[String, ApplicationState]) => {
Option(appInfoStore.remove(notification.getKey)).foreach { case (kubernetesInfo, removed) =>
val appLabel = notification.getKey
if (deleteSparkDriverPodOnTermination) {
val podName = removed.name
try {
val kubernetesClient = getOrCreateKubernetesClient(kubernetesInfo)
if (!kubernetesClient.pods().withName(removed.name).delete().isEmpty) {
info(s"[$kubernetesInfo] Operation of delete pod ${removed.name} with" +
s" ${toLabel(notification.getKey)} is completed.")
val deleted = if (podName == null) {
!kubernetesClient.pods()
.withLabel(LABEL_KYUUBI_UNIQUE_KEY, appLabel)
.delete().isEmpty
} else {
warn(s"[$kubernetesInfo] Failed to delete pod ${removed.name} with" +
s" ${toLabel(notification.getKey)}.")
!kubernetesClient.pods().withName(podName).delete().isEmpty
}
if (deleted) {
info(s"[$kubernetesInfo] Operation of delete pod $podName with" +
s" ${toLabel(appLabel)} is completed.")
} else {
warn(s"[$kubernetesInfo] Failed to delete pod $podName with ${toLabel(appLabel)}.")
}
} catch {
case NonFatal(e) => error(
s"[$kubernetesInfo] Failed to delete pod ${removed.name} with" +
s" ${toLabel(notification.getKey)}",
s"[$kubernetesInfo] Failed to delete pod $podName with ${toLabel(appLabel)}",
e)
}
}
info(s"Remove terminated application ${removed.id} with " +
s"[${toLabel(notification.getKey)}, state: ${removed.state}]")
info(s"Remove terminated application $removed with ${toLabel(appLabel)}")
}
})
.build()
Expand Down

0 comments on commit d4fa6fd

Please sign in to comment.