Skip to content

Commit

Permalink
feat: evict pod only called api successed for memory eviction
Browse files Browse the repository at this point in the history
Signed-off-by: j4ckstraw <j4ckstraw@foxmail.com>
  • Loading branch information
j4ckstraw committed Jan 5, 2024
1 parent 336f4f9 commit 6e920a1
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 10 deletions.
35 changes: 25 additions & 10 deletions pkg/koordlet/qosmanager/plugins/memoryevict/memory_evict.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
"github.com/koordinator-sh/koordinator/pkg/koordlet/qosmanager/helpers"
"github.com/koordinator-sh/koordinator/pkg/koordlet/resourceexecutor"
"github.com/koordinator-sh/koordinator/pkg/koordlet/statesinformer"
"github.com/koordinator-sh/koordinator/pkg/util"
)

const (
Expand All @@ -50,6 +51,7 @@ type memoryEvictor struct {
metricCache metriccache.MetricCache
evictor *framework.Evictor
lastEvictTime time.Time
onlyEvictByAPI bool
}

type podInfo struct {
Expand All @@ -64,6 +66,7 @@ func New(opt *framework.Options) framework.QOSStrategy {
metricCollectInterval: opt.MetricAdvisorConfig.CollectResUsedInterval,
statesInformer: opt.StatesInformer,
metricCache: opt.MetricCache,
onlyEvictByAPI: opt.Config.OnlyEvictByAPI,
}
}

Expand Down Expand Up @@ -164,24 +167,36 @@ func (m *memoryEvictor) killAndEvictBEPods(node *corev1.Node, podMetrics map[str
bePodInfos := m.getSortedBEPodInfos(podMetrics)
message := fmt.Sprintf("killAndEvictBEPods for node, need to release memory: %v", memoryNeedRelease)
memoryReleased := int64(0)

var killedPods []*corev1.Pod
hasKillPods := false
for _, bePod := range bePodInfos {
if memoryReleased >= memoryNeedRelease {
break
}

killMsg := fmt.Sprintf("%v, kill pod: %v", message, bePod.pod.Name)
helpers.KillContainers(bePod.pod, killMsg)
killedPods = append(killedPods, bePod.pod)
if bePod.memUsed != 0 {
memoryReleased += int64(bePod.memUsed)
if m.onlyEvictByAPI {
if m.evictor.EvictPodIfNotEvicted(bePod.pod, node, resourceexecutor.EvictPodByNodeMemoryUsage, message) {
hasKillPods = true
if bePod.memUsed != 0 {
memoryReleased += int64(bePod.memUsed)
}
klog.V(5).Infof("memoryEvict pick pod %s to evict", util.GetPodKey(bePod.pod))
} else {
klog.V(5).Infof("memoryEvict pick pod %s to evict", util.GetPodKey(bePod.pod))
}
} else {
killMsg := fmt.Sprintf("%v, kill pod: %v", message, bePod.pod.Name)
helpers.KillContainers(bePod.pod, killMsg)
hasKillPods = true
if bePod.memUsed != 0 {
memoryReleased += int64(bePod.memUsed)
}
klog.V(5).Infof("memoryEvict pick pod %s to evict", util.GetPodKey(bePod.pod))
}
}
if hasKillPods {
m.lastEvictTime = time.Now()
}

m.evictor.EvictPodsIfNotEvicted(killedPods, node, resourceexecutor.EvictPodByNodeMemoryUsage, message)

m.lastEvictTime = time.Now()
klog.Infof("killAndEvictBEPods completed, memoryNeedRelease(%v) memoryReleased(%v)", memoryNeedRelease, memoryReleased)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,7 @@ func Test_memoryEvict(t *testing.T) {
memoryEvictor := m.(*memoryEvictor)
memoryEvictor.Setup(&framework.Context{Evictor: evictor})
memoryEvictor.lastEvictTime = time.Now().Add(-30 * time.Second)
memoryEvictor.onlyEvictByAPI = true
memoryEvictor.memoryEvict()

for _, pod := range tt.expectEvictPods {
Expand Down

0 comments on commit 6e920a1

Please sign in to comment.