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-469]Implement recycling service in PlaceholderManager that cleans up orphan placeholders #208

Merged
merged 4 commits into from
Dec 9, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
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
20 changes: 20 additions & 0 deletions pkg/cache/placeholder_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package cache

import (
"sync"
"time"

"go.uber.org/zap"
v1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -97,3 +98,22 @@ func (mgr *PlaceholderManager) setMockedClients(mockedClients *client.Clients) {
defer mgr.Unlock()
mgr.clients = mockedClients
}

func (mgr *PlaceholderManager) cleanOrphanPlaceholders() {
yangwwei marked this conversation as resolved.
Show resolved Hide resolved
for taskID, pod := range mgr.orphanPod {
err := mgr.clients.KubeClient.Delete(pod)
yangwwei marked this conversation as resolved.
Show resolved Hide resolved
if err == nil {
delete(mgr.orphanPod, taskID)
}
}
}

func (mgr *PlaceholderManager) Start() {
yangwwei marked this conversation as resolved.
Show resolved Hide resolved
go func() {
for {
// clean orphan placeholders every 5 seconds
mgr.cleanOrphanPlaceholders()
time.Sleep(5 * time.Second)
}
}()
}
23 changes: 23 additions & 0 deletions pkg/cache/placeholder_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,3 +173,26 @@ func TestCleanUp(t *testing.T) {
assert.Equal(t, exist, false)
assert.Equal(t, len(placeholderMgr.orphanPod), 0)
}

yangwwei marked this conversation as resolved.
Show resolved Hide resolved
func TestCleanOrphanPlaceholders(t *testing.T) {
mockedAPIProvider := client.NewMockedAPIProvider()
placeholderMgr := &PlaceholderManager{
clients: mockedAPIProvider.GetAPIs(),
orphanPod: make(map[string]*v1.Pod),
RWMutex: sync.RWMutex{},
}
pod1 := &v1.Pod{
TypeMeta: apis.TypeMeta{
Kind: "Pod",
APIVersion: "v1",
},
ObjectMeta: apis.ObjectMeta{
Name: "pod-01",
UID: "UID-01",
},
}
placeholderMgr.orphanPod["task01"] = pod1
assert.Equal(t, len(placeholderMgr.orphanPod), 1)
placeholderMgr.cleanOrphanPlaceholders()
assert.Equal(t, len(placeholderMgr.orphanPod), 0)
}