Skip to content

Commit

Permalink
Support deletion when it existed
Browse files Browse the repository at this point in the history
  • Loading branch information
zhuqi-lucas committed Sep 27, 2024
1 parent 89171d1 commit 5ea3ac0
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion pkg/cache/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"github.com/looplab/fsm"
"go.uber.org/zap"
v1 "k8s.io/api/core/v1"
k8serrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/apache/yunikorn-k8shim/pkg/common"
Expand Down Expand Up @@ -636,7 +637,19 @@ func (app *Application) handleReleaseAppAllocationEvent(taskID string, terminati

if task, ok := app.taskMap[taskID]; ok {
task.setTaskTerminationType(terminationType)
err := task.DeleteTaskPod()
pod := task.GetTaskPod()
// Get the pod first to check if it exists
// For example, users manually killed the pod, so the pod already deleted before release.
_, err := task.context.apiProvider.GetAPIs().KubeClient.Get(pod.Namespace, pod.Name)
if err != nil {
if k8serrors.IsNotFound(err) {
// Pod does not exist, no need to delete
log.Log(log.ShimCacheApplication).Info("pod not found, it already deleted or released")
} else {
log.Log(log.ShimCacheApplication).Error("failed to get pod", zap.Error(err))
}
}
err = task.DeleteTaskPod()
if err != nil {
log.Log(log.ShimCacheApplication).Error("failed to release allocation from application", zap.Error(err))
}
Expand Down

0 comments on commit 5ea3ac0

Please sign in to comment.