Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[YUNIKORN-521] Placeholder pods are not cleaned when the job is deleted #232

Merged
merged 5 commits into from
Mar 16, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pkg/appmgmt/general/general.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ func (os *Manager) getAppMetadata(pod *v1.Pod) (interfaces.ApplicationMetadata,
User: user,
Tags: tags,
TaskGroups: taskGroups,
PlaceholderOwnerReferences: pod.OwnerReferences,
kingamarton marked this conversation as resolved.
Show resolved Hide resolved
}, true
}

Expand Down
2 changes: 2 additions & 0 deletions pkg/appmgmt/interfaces/amprotocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package interfaces

import (
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/apache/incubator-yunikorn-k8shim/pkg/apis/yunikorn.apache.org/v1alpha1"
)
Expand Down Expand Up @@ -75,6 +76,7 @@ type ApplicationMetadata struct {
User string
Tags map[string]string
TaskGroups []v1alpha1.TaskGroup
PlaceholderOwnerReferences []metav1.OwnerReference
}

type TaskMetadata struct {
Expand Down
30 changes: 19 additions & 11 deletions pkg/cache/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/looplab/fsm"
"go.uber.org/zap"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/apache/incubator-yunikorn-core/pkg/api"
"github.com/apache/incubator-yunikorn-k8shim/pkg/apis/yunikorn.apache.org/v1alpha1"
Expand All @@ -40,17 +41,18 @@ import (
)

type Application struct {
applicationID string
queue string
partition string
user string
taskMap map[string]*Task
tags map[string]string
schedulingPolicy v1alpha1.SchedulingPolicy
taskGroups []v1alpha1.TaskGroup
sm *fsm.FSM
lock *sync.RWMutex
schedulerAPI api.SchedulerAPI
applicationID string
queue string
partition string
user string
taskMap map[string]*Task
tags map[string]string
schedulingPolicy v1alpha1.SchedulingPolicy
taskGroups []v1alpha1.TaskGroup
placeholderOwnerReferences []metav1.OwnerReference
sm *fsm.FSM
lock *sync.RWMutex
schedulerAPI api.SchedulerAPI
}

func (app *Application) String() string {
Expand Down Expand Up @@ -208,6 +210,12 @@ func (app *Application) getTaskGroups() []v1alpha1.TaskGroup {
return app.taskGroups
}

func (app *Application) setPlaceholderOwnReference(ref []metav1.OwnerReference) {
app.lock.RLock()
defer app.lock.RUnlock()
app.placeholderOwnerReferences = ref
}

func (app *Application) addTask(task *Task) {
app.lock.Lock()
defer app.lock.Unlock()
Expand Down
1 change: 1 addition & 0 deletions pkg/cache/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,7 @@ func (ctx *Context) AddApplication(request *interfaces.AddApplicationRequest) in
request.Metadata.Tags,
ctx.apiProvider.GetAPIs().SchedulerAPI)
app.setTaskGroups(request.Metadata.TaskGroups)
app.setPlaceholderOwnReference(request.Metadata.PlaceholderOwnerReferences)

// add into cache
ctx.applications[app.applicationID] = app
Expand Down
6 changes: 6 additions & 0 deletions pkg/cache/placeholder.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ type Placeholder struct {
}

func newPlaceholder(placeholderName string, app *Application, taskGroup v1alpha1.TaskGroup) *Placeholder {
ownerRef := app.placeholderOwnerReferences
kingamarton marked this conversation as resolved.
Show resolved Hide resolved
controller := false
for _, r := range ownerRef {
*r.Controller = controller
}
placeholderPod := &v1.Pod{
ObjectMeta: metav1.ObjectMeta{
Name: placeholderName,
Expand All @@ -48,6 +53,7 @@ func newPlaceholder(placeholderName string, app *Application, taskGroup v1alpha1
constants.AnnotationPlaceholderFlag: "true",
constants.AnnotationTaskGroupName: taskGroup.Name,
},
OwnerReferences: ownerRef,
},
Spec: v1.PodSpec{
Containers: []v1.Container{
Expand Down