Skip to content

Commit d84c603

Browse files
feat(agent): eviction enhancement
1 parent 20b4bc7 commit d84c603

File tree

23 files changed

+1242
-54
lines changed

23 files changed

+1242
-54
lines changed

cmd/katalyst-agent/app/options/dynamic/adminqos/eviction/reclaimed_resources_eviction.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626

2727
type ReclaimedResourcesEvictionOptions struct {
2828
EvictionThreshold native.ResourceThreshold
29+
SoftEvictionThreshold native.ResourceThreshold
2930
GracePeriod int64
3031
ThresholdMetToleranceDuration int64
3132
}
@@ -36,6 +37,10 @@ func NewReclaimedResourcesEvictionOptions() *ReclaimedResourcesEvictionOptions {
3637
consts.ReclaimedResourceMilliCPU: 5.0,
3738
consts.ReclaimedResourceMemory: 5.0,
3839
},
40+
SoftEvictionThreshold: native.ResourceThreshold{
41+
consts.ReclaimedResourceMilliCPU: 1.5,
42+
consts.ReclaimedResourceMemory: 1.2,
43+
},
3944
GracePeriod: 60,
4045
ThresholdMetToleranceDuration: 0,
4146
}
@@ -54,6 +59,7 @@ func (o *ReclaimedResourcesEvictionOptions) AddFlags(fss *cliflag.NamedFlagSets)
5459

5560
func (o *ReclaimedResourcesEvictionOptions) ApplyTo(c *eviction.ReclaimedResourcesEvictionConfiguration) error {
5661
c.EvictionThreshold = o.EvictionThreshold
62+
c.SoftEvictionThreshold = o.SoftEvictionThreshold
5763
c.DeletionGracePeriod = o.GracePeriod
5864
c.ThresholdMetToleranceDuration = o.ThresholdMetToleranceDuration
5965
return nil

cmd/katalyst-agent/app/options/eviction/eviction_base.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ type GenericEvictionOptions struct {
5858

5959
// RecordManager specifies the eviction record manager to use
6060
RecordManager string
61+
62+
// HostPathNotifierPathRoot is the root path for host-path notifier
63+
HostPathNotifierRootPath string
6164
}
6265

6366
// NewGenericEvictionOptions creates a new Options with a default config.
@@ -69,6 +72,7 @@ func NewGenericEvictionOptions() *GenericEvictionOptions {
6972
EvictionSkippedAnnotationKeys: []string{},
7073
EvictionSkippedLabelKeys: []string{},
7174
EvictionBurst: 3,
75+
HostPathNotifierRootPath: "/opt/katalyst",
7276
PodKiller: consts.KillerNameEvictionKiller,
7377
StrictAuthentication: false,
7478
}
@@ -111,6 +115,9 @@ func (o *GenericEvictionOptions) AddFlags(fss *cliflag.NamedFlagSets) {
111115

112116
fs.StringVar(&o.RecordManager, "eviction-record-manager", o.RecordManager,
113117
"the eviction record manager to use")
118+
119+
fs.StringVar(&o.HostPathNotifierRootPath, "pod-notifier-root-path", o.HostPathNotifierRootPath,
120+
"root path of host-path notifier")
114121
}
115122

116123
// ApplyTo fills up config with options
@@ -126,6 +133,7 @@ func (o *GenericEvictionOptions) ApplyTo(c *evictionconfig.GenericEvictionConfig
126133
c.StrictAuthentication = o.StrictAuthentication
127134
c.PodMetricLabels.Insert(o.PodMetricLabels...)
128135
c.RecordManager = o.RecordManager
136+
c.HostPathNotifierRootPath = o.HostPathNotifierRootPath
129137
return nil
130138
}
131139

go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,8 @@ require (
175175
)
176176

177177
replace (
178+
// FIXME
179+
github.com/kubewharf/katalyst-api => github.com/funnydreamwinz/katalyst-api v0.0.0-20251210074241-6de02ad20eb1
178180
k8s.io/api => k8s.io/api v0.24.6
179181
k8s.io/apiextensions-apiserver => k8s.io/apiextensions-apiserver v0.24.6
180182
k8s.io/apimachinery => k8s.io/apimachinery v0.24.6

go.sum

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,6 @@ github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7
198198
github.com/coreos/go-systemd/v22 v22.1.0/go.mod h1:xO0FLkIi5MaZafQlIrOotqXZ90ih+1atmu1JpKERPPk=
199199
github.com/coreos/go-systemd/v22 v22.3.2/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
200200
github.com/coreos/go-systemd/v22 v22.5.0 h1:RrqgGjYQKalulkV8NGVIfkXQf6YYmOyiJKk8iXXhfZs=
201-
github.com/coreos/go-systemd/v22 v22.5.0 h1:RrqgGjYQKalulkV8NGVIfkXQf6YYmOyiJKk8iXXhfZs=
202-
github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
203201
github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
204202
github.com/coreos/pkg v0.0.0-20160727233714-3ac0863d7acf/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA=
205203
github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA=
@@ -282,6 +280,8 @@ github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMo
282280
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
283281
github.com/fsnotify/fsnotify v1.5.4 h1:jRbGcIw6P2Meqdwuo0H1p6JVLbL5DHKAKlYndzMwVZI=
284282
github.com/fsnotify/fsnotify v1.5.4/go.mod h1:OVB6XrOHzAwXMpEM7uPOzcehqUV2UqJxmVXmkdnm1bU=
283+
github.com/funnydreamwinz/katalyst-api v0.0.0-20251210074241-6de02ad20eb1 h1:8rO7CkA+Iis5iacxyjH4v5cXUaVhRpK8ladQowBxxqU=
284+
github.com/funnydreamwinz/katalyst-api v0.0.0-20251210074241-6de02ad20eb1/go.mod h1:Y2IeIorxQamF2a3oa0+URztl5QCSty6Jj3zD83R8J9k=
285285
github.com/fvbommel/sortorder v1.0.1/go.mod h1:uk88iVf1ovNn1iLfgUVU2F9o5eO30ui720w+kxuqRs0=
286286
github.com/getkin/kin-openapi v0.76.0/go.mod h1:660oXbgy5JFMKreazJaQTw7o+X00qeSyhcnluiMv+Xg=
287287
github.com/getsentry/raven-go v0.2.0/go.mod h1:KungGk8q33+aIAZUIVWZDr2OfAEBsO49PX4NzFV5kcQ=
@@ -576,8 +576,6 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
576576
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
577577
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
578578
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
579-
github.com/kubewharf/katalyst-api v0.5.8-0.20251209195727-bde2ce2b9b13 h1:/R3HuWFoJkynuCnYF7wZ9p9KkzUgYgtDXZlxCeggMgM=
580-
github.com/kubewharf/katalyst-api v0.5.8-0.20251209195727-bde2ce2b9b13/go.mod h1:Y2IeIorxQamF2a3oa0+URztl5QCSty6Jj3zD83R8J9k=
581579
github.com/kubewharf/kubelet v1.24.6-kubewharf.9 h1:jOTYZt7h/J7I8xQMKMUcJjKf5UFBv37jHWvNp5VRFGc=
582580
github.com/kubewharf/kubelet v1.24.6-kubewharf.9/go.mod h1:MxbSZUx3wXztFneeelwWWlX7NAAStJ6expqq7gY2J3c=
583581
github.com/kyoh86/exportloopref v0.1.7/go.mod h1:h1rDl2Kdj97+Kwh4gdz3ujE7XHmH51Q0lUiZ1z4NLj8=
@@ -605,20 +603,15 @@ github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaO
605603
github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
606604
github.com/mattn/go-colorable v0.1.7/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
607605
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
608-
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
609-
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
610606
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
611607
github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
612608
github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
613609
github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
614610
github.com/mattn/go-isatty v0.0.11/go.mod h1:PhnuNfih5lzO57/f3n+odYbM4JtupLOxQOAqxQCu2WE=
615611
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
616612
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
617-
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
618-
github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA=
619613
github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA=
620614
github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
621-
github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
622615
github.com/mattn/go-runewidth v0.0.2/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
623616
github.com/mattn/go-runewidth v0.0.7/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
624617
github.com/mattn/go-sqlite3 v1.9.0/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc=
@@ -811,11 +804,8 @@ github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6L
811804
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
812805
github.com/rogpeppe/go-internal v1.6.0/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc=
813806
github.com/rs/xid v1.6.0/go.mod h1:7XoLgs4eV+QndskICGsho+ADou8ySMSjJKDIan90Nz0=
814-
github.com/rs/xid v1.6.0/go.mod h1:7XoLgs4eV+QndskICGsho+ADou8ySMSjJKDIan90Nz0=
815-
github.com/rs/zerolog v1.34.0 h1:k43nTLIwcTVQAncfCw4KZ2VY6ukYoZaBPNOE8txlOeY=
816807
github.com/rs/zerolog v1.34.0 h1:k43nTLIwcTVQAncfCw4KZ2VY6ukYoZaBPNOE8txlOeY=
817808
github.com/rs/zerolog v1.34.0/go.mod h1:bJsvje4Z08ROH4Nhs5iH600c3IkWhwp44iRc54W6wYQ=
818-
github.com/rs/zerolog v1.34.0/go.mod h1:bJsvje4Z08ROH4Nhs5iH600c3IkWhwp44iRc54W6wYQ=
819809
github.com/rubiojr/go-vhd v0.0.0-20200706105327-02e210299021/go.mod h1:DM5xW0nvfNNm2uytzsvhI3OnX8uzaRAg8UX/CnDqbto=
820810
github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g=
821811
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
@@ -1286,12 +1276,9 @@ golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBc
12861276
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
12871277
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
12881278
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
1289-
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
12901279
golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
12911280
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
12921281
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
1293-
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
1294-
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
12951282
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
12961283
golang.org/x/sys v0.29.0 h1:TPYlXGxvx1MGTn2GiZDhnjPA9wZzZeGKHHmKhHYvgaU=
12971284
golang.org/x/sys v0.29.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=

pkg/agent/evictionmanager/eviction_resp_collector.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,42 @@ func (e *evictionRespCollector) collectMetThreshold(dryRunPlugins []string, plug
169169
}
170170
}
171171

172+
func (e *evictionRespCollector) collectTopSoftEvictionPods(dryRunPlugins []string, pluginName string,
173+
threshold *pluginapi.ThresholdMetResponse, resp *pluginapi.GetTopEvictionPodsResponse,
174+
) {
175+
dryRun := e.isDryRun(dryRunPlugins, pluginName)
176+
177+
targetPods := make([]*v1.Pod, 0, len(resp.TargetPods))
178+
for i, pod := range resp.TargetPods {
179+
if pod == nil {
180+
continue
181+
}
182+
183+
general.Infof("%v plugin %v request to notify topN pod %v/%v, reason: met threshold in scope [%v]",
184+
e.getLogPrefix(dryRun), pluginName, pod.Namespace, pod.Name, threshold.EvictionScope)
185+
if dryRun {
186+
metricsPodToEvict(e.emitter, e.conf.GenericConfiguration.QoSConfiguration, pluginName, pod, dryRun, e.conf.GenericEvictionConfiguration.PodMetricLabels)
187+
} else {
188+
targetPods = append(targetPods, resp.TargetPods[i])
189+
}
190+
}
191+
192+
for _, pod := range targetPods {
193+
reason := fmt.Sprintf("plugin %s met threshold in scope %s, target %v, observed %v",
194+
pluginName, threshold.EvictionScope, threshold.ThresholdValue, threshold.ObservedValue)
195+
196+
e.getSoftEvictPods()[string(pod.UID)] = &rule.RuledEvictPod{
197+
EvictPod: &pluginapi.EvictPod{
198+
Pod: pod.DeepCopy(),
199+
Reason: reason,
200+
ForceEvict: false,
201+
EvictionPluginName: pluginName,
202+
},
203+
Scope: threshold.EvictionScope,
204+
}
205+
}
206+
}
207+
172208
func (e *evictionRespCollector) collectTopEvictionPods(dryRunPlugins []string, pluginName string,
173209
threshold *pluginapi.ThresholdMetResponse, resp *pluginapi.GetTopEvictionPodsResponse,
174210
) {

pkg/agent/evictionmanager/manager.go

Lines changed: 59 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import (
3737
clocks "k8s.io/utils/clock"
3838

3939
"github.com/kubewharf/katalyst-api/pkg/apis/node/v1alpha1"
40+
apiconsts "github.com/kubewharf/katalyst-api/pkg/consts"
4041
"github.com/kubewharf/katalyst-api/pkg/plugins/registration"
4142
pluginapi "github.com/kubewharf/katalyst-api/pkg/protocol/evictionplugin/v1alpha1"
4243
endpointpkg "github.com/kubewharf/katalyst-core/pkg/agent/evictionmanager/endpoint"
@@ -46,6 +47,7 @@ import (
4647
"github.com/kubewharf/katalyst-core/pkg/agent/evictionmanager/plugin/resource"
4748
"github.com/kubewharf/katalyst-core/pkg/agent/evictionmanager/plugin/rootfs"
4849
"github.com/kubewharf/katalyst-core/pkg/agent/evictionmanager/podkiller"
50+
"github.com/kubewharf/katalyst-core/pkg/agent/evictionmanager/podnotifier"
4951
"github.com/kubewharf/katalyst-core/pkg/agent/evictionmanager/record"
5052
"github.com/kubewharf/katalyst-core/pkg/agent/evictionmanager/rule"
5153
"github.com/kubewharf/katalyst-core/pkg/client"
@@ -109,7 +111,8 @@ type EvictionManger struct {
109111
// easy to test the code.
110112
clock clocks.WithTickerAndDelayedExecution
111113

112-
podKiller podkiller.PodKiller
114+
podNotifier podnotifier.PodNotifier
115+
podKiller podkiller.PodKiller
113116

114117
killQueue rule.EvictionQueue
115118
killStrategy rule.EvictionStrategy
@@ -236,6 +239,12 @@ func NewEvictionManager(genericClient *client.GenericClientSet, recorder events.
236239

237240
podKiller := podkiller.NewAsynchronizedPodKiller(killer, metaServer.PodFetcher, genericClient.KubeClient)
238241

242+
notifier, err := podnotifier.NewHostPathPodNotifier(conf, genericClient.KubeClient, metaServer, recorder, emitter)
243+
if err != nil {
244+
return nil, fmt.Errorf("failed to create pod notifier: %v", err)
245+
}
246+
podNotifier := podnotifier.NewSynchronizedPodNotifier(notifier)
247+
239248
cnrTaintReporter, err := control.NewGenericReporterPlugin(cnrTaintReporterPluginName, conf, emitter)
240249
if err != nil {
241250
return nil, fmt.Errorf("failed to initialize cnr taint reporter plugin: %v", err)
@@ -264,6 +273,7 @@ func NewEvictionManager(genericClient *client.GenericClientSet, recorder events.
264273
metaGetter: metaServer,
265274
emitter: emitter,
266275
podKiller: podKiller,
276+
podNotifier: podNotifier,
267277
cnrTaintReporter: cnrTaintReporter,
268278
endpoints: make(map[string]endpointpkg.Endpoint),
269279
conf: conf,
@@ -317,6 +327,7 @@ func (m *EvictionManger) Run(ctx context.Context) {
317327
general.RegisterHeartbeatCheck(reportTaintHealthCheckName, reportTaintToleration,
318328
general.HealthzCheckStateNotReady, reportTaintToleration)
319329
m.podKiller.Start(ctx)
330+
m.podNotifier.Start(ctx)
320331
for _, endpoint := range m.endpoints {
321332
endpoint.Start()
322333
}
@@ -360,6 +371,11 @@ func (m *EvictionManger) sync(ctx context.Context) {
360371
}
361372

362373
errList := make([]error, 0)
374+
notifyErr := m.doNotify(collector.getSoftEvictPods())
375+
if notifyErr != nil {
376+
errList = append(errList, notifyErr)
377+
}
378+
363379
evictErr := m.doEvict(collector.getSoftEvictPods(), collector.getForceEvictPods())
364380
if evictErr != nil {
365381
errList = append(errList, evictErr)
@@ -430,8 +446,8 @@ func (m *EvictionManger) collectEvictionResult(ctx context.Context, pods []*v1.P
430446
records := m.getEvictionRecords(ctx, collector.currentCandidatePods)
431447

432448
for pluginName, threshold := range thresholdsMet {
433-
if threshold.MetType != pluginapi.ThresholdMetType_HARD_MET {
434-
general.Infof(" the type: %s of met threshold from plugin: %s isn't %s", threshold.MetType.String(), pluginName, pluginapi.ThresholdMetType_HARD_MET.String())
449+
if threshold.MetType == pluginapi.ThresholdMetType_NOT_MET {
450+
general.Infof("resp from plugin: %s not met threshold", pluginName)
435451
continue
436452
}
437453

@@ -453,13 +469,20 @@ func (m *EvictionManger) collectEvictionResult(ctx context.Context, pods []*v1.P
453469
}
454470
}
455471
}
472+
473+
topN := uint64(0)
474+
forceEvict := false
475+
if threshold.MetType == pluginapi.ThresholdMetType_HARD_MET {
476+
topN = 1
477+
forceEvict = true
478+
}
479+
456480
resp, err := m.endpoints[pluginName].GetTopEvictionPods(context.Background(), &pluginapi.GetTopEvictionPodsRequest{
457481
ActivePods: activePods,
458-
TopN: 1,
482+
TopN: topN,
459483
EvictionScope: threshold.EvictionScope,
460484
CandidateEvictionRecords: candidateEvictionRecords,
461485
})
462-
463486
m.endpointLock.RUnlock()
464487
if err != nil {
465488
general.Errorf(" calling GetTopEvictionPods of plugin: %s failed with error: %v", pluginName, err)
@@ -473,12 +496,38 @@ func (m *EvictionManger) collectEvictionResult(ctx context.Context, pods []*v1.P
473496
continue
474497
}
475498

476-
collector.collectTopEvictionPods(dynamicConfig.DryRun, pluginName, threshold, resp)
499+
if forceEvict {
500+
collector.collectTopEvictionPods(dynamicConfig.DryRun, pluginName, threshold, resp)
501+
} else {
502+
collector.collectTopSoftEvictionPods(dynamicConfig.DryRun, pluginName, threshold, resp)
503+
}
504+
477505
}
478506

479507
return collector, errors.NewAggregate(errList)
480508
}
481509

510+
func (m *EvictionManger) doNotify(softEvictPods map[string]*rule.RuledEvictPod) error {
511+
errList := make([]error, 0)
512+
513+
for _, pod := range softEvictPods {
514+
if pod == nil || pod.EvictPod.Pod == nil {
515+
continue
516+
}
517+
518+
if _, ok := pod.EvictPod.Pod.Annotations[apiconsts.PodAnnotationSoftEvictNotificationKey]; !ok {
519+
continue
520+
}
521+
522+
err := m.podNotifier.NotifyPod(pod)
523+
if err != nil {
524+
errList = append(errList, err)
525+
}
526+
}
527+
528+
return errors.NewAggregate(errList)
529+
}
530+
482531
func (m *EvictionManger) doEvict(softEvictPods, forceEvictPods map[string]*rule.RuledEvictPod) error {
483532
softEvictPods = filterOutCandidatePodsWithForcePods(softEvictPods, forceEvictPods)
484533
bestSuitedCandidate := m.getEvictPodFromCandidates(softEvictPods)
@@ -637,6 +686,10 @@ func (m *EvictionManger) getEvictPodFromCandidates(candidateEvictPods map[string
637686
for _, rp := range candidateEvictPods {
638687
// only killing pods that pass candidate validation
639688
if rp != nil && rp.Pod != nil && m.killStrategy.CandidateValidate(rp) {
689+
// do NOT select soft evict pod with notification-enable as candidate
690+
if _, ok := rp.Pod.Annotations[apiconsts.PodAnnotationSoftEvictNotificationKey]; ok {
691+
continue
692+
}
640693
rpList = append(rpList, rp)
641694
}
642695
}

0 commit comments

Comments
 (0)