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

feat(eviction): add rootfs eviction options #465

Merged
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ type EvictionOptions struct {
*MemoryPressureEvictionOptions
*ReclaimedResourcesEvictionOptions
*SystemLoadPressureEvictionOptions
*RootfsPressureEvictionOptions
}

func NewEvictionOptions() *EvictionOptions {
Expand All @@ -40,6 +41,7 @@ func NewEvictionOptions() *EvictionOptions {
MemoryPressureEvictionOptions: NewMemoryPressureEvictionOptions(),
ReclaimedResourcesEvictionOptions: NewReclaimedResourcesEvictionOptions(),
SystemLoadPressureEvictionOptions: NewSystemLoadPressureEvictionOptions(),
RootfsPressureEvictionOptions: NewRootfsPressureEvictionOptions(),
}
}

Expand All @@ -52,6 +54,7 @@ func (o *EvictionOptions) AddFlags(fss *cliflag.NamedFlagSets) {
o.MemoryPressureEvictionOptions.AddFlags(fss)
o.ReclaimedResourcesEvictionOptions.AddFlags(fss)
o.SystemLoadPressureEvictionOptions.AddFlags(fss)
o.RootfsPressureEvictionOptions.AddFlags(fss)
}

func (o *EvictionOptions) ApplyTo(c *eviction.EvictionConfiguration) error {
Expand All @@ -61,5 +64,6 @@ func (o *EvictionOptions) ApplyTo(c *eviction.EvictionConfiguration) error {
errList = append(errList, o.MemoryPressureEvictionOptions.ApplyTo(c.MemoryPressureEvictionConfiguration))
errList = append(errList, o.ReclaimedResourcesEvictionOptions.ApplyTo(c.ReclaimedResourcesEvictionConfiguration))
errList = append(errList, o.SystemLoadPressureEvictionOptions.ApplyTo(c.SystemLoadEvictionPluginConfiguration))
errList = append(errList, o.RootfsPressureEvictionOptions.ApplyTo(c.RootfsPressureEvictionConfiguration))
return errors.NewAggregate(errList)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
/*
Copyright 2022 The Katalyst Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package eviction

import (
"github.com/pkg/errors"
cliflag "k8s.io/component-base/cli/flag"

"github.com/kubewharf/katalyst-core/pkg/config/agent/dynamic/adminqos/eviction"
)

const (
defaultEnableRootfsEviction = false
defaultMinimumFreeThreshold = ""
defaultMinimumInodesFreeThreshold = ""
defaultPodMinimumUsedThreshold = ""
defaultPodMinimumInodesUsedThreshold = ""
defaultReclaimedQoSPodUsedPriorityThreshold = ""
defaultReclaimedQoSPodInodesUsedPriorityThreshold = ""
)

type RootfsPressureEvictionOptions struct {
EnableRootfsPressureEviction bool
MinimumFreeThreshold string
MinimumInodesFreeThreshold string
PodMinimumUsedThreshold string
PodMinimumInodesUsedThreshold string
ReclaimedQoSPodUsedPriorityThreshold string
ReclaimedQoSPodInodesUsedPriorityThreshold string
GracePeriod int64
}

func NewRootfsPressureEvictionOptions() *RootfsPressureEvictionOptions {
return &RootfsPressureEvictionOptions{
EnableRootfsPressureEviction: defaultEnableRootfsEviction,
MinimumFreeThreshold: defaultMinimumFreeThreshold,
MinimumInodesFreeThreshold: defaultMinimumInodesFreeThreshold,
PodMinimumUsedThreshold: defaultPodMinimumUsedThreshold,
PodMinimumInodesUsedThreshold: defaultPodMinimumInodesUsedThreshold,
ReclaimedQoSPodUsedPriorityThreshold: defaultReclaimedQoSPodUsedPriorityThreshold,
ReclaimedQoSPodInodesUsedPriorityThreshold: defaultReclaimedQoSPodInodesUsedPriorityThreshold,
GracePeriod: defaultGracePeriod,
}
}

func (o *RootfsPressureEvictionOptions) AddFlags(fss *cliflag.NamedFlagSets) {
fs := fss.FlagSet("eviction-rootfs-pressure")
fs.BoolVar(&o.EnableRootfsPressureEviction, "eviction-rootfs-enable", false,
"set true to enable rootfs pressure eviction")
fs.StringVar(&o.MinimumFreeThreshold, "eviction-rootfs-minimum-free", "",
"the minimum rootfs free threshold for nodes. once the rootfs free space of current node is lower than this threshold, the eviction manager will try to evict some pods. example 200G, 10%")
fs.StringVar(&o.MinimumInodesFreeThreshold, "eviction-rootfs-minimum-inodes-free", "",
"the minimum rootfs inodes free for nodes. once the rootfs free inodes of current node is lower than this threshold, the eviction manager will try to evict some pods. example 20000, 10%")
fs.StringVar(&o.PodMinimumUsedThreshold, "eviction-rootfs-pod-minimum-used", "",
"the minimum rootfs used for pod. the eviction manager will ignore this pod if its rootfs used in bytes is lower than this threshold. example 500M, 1%")
fs.StringVar(&o.PodMinimumInodesUsedThreshold, "eviction-rootfs-pod-minimum-inodes-used", "",
"the minimum rootfs inodes used for pod. the eviction manager will ignore this pod if its rootfs inodes used is lower than this threshold. example 2000, 1%")
fs.StringVar(&o.ReclaimedQoSPodUsedPriorityThreshold, "eviction-rootfs-reclaimed-qos-pod-used-priority", "",
"the rootfs used priority threshold for reclaimed qos pod. the eviction manager will prioritize the eviction of offline pods that reach this threshold. example 800M, 2%")
fs.StringVar(&o.ReclaimedQoSPodInodesUsedPriorityThreshold, "eviction-rootfs-reclaimed-qos-pod-inodes-used-priority", "",
"the rootfs inodes used priority threshold for reclaimed qos pod. the eviction manager will prioritize the eviction of reclaimed pods that reach this threshold. example 3000, 2%")
fs.Int64Var(&o.GracePeriod, "eviction-rootfs-grace-period", 0,
"the grace period of pod deletion")
}

func (o *RootfsPressureEvictionOptions) ApplyTo(c *eviction.RootfsPressureEvictionConfiguration) error {
c.EnableRootfsPressureEviction = o.EnableRootfsPressureEviction
if o.MinimumFreeThreshold != "" {
value, err := eviction.ParseThresholdValue(o.MinimumFreeThreshold)
if err != nil {
return errors.Wrapf(err, "failed to parse option: 'eviction-rootfs-minimum-free'")
}
c.MinimumFreeThreshold = value
}
if o.MinimumInodesFreeThreshold != "" {
value, err := eviction.ParseThresholdValue(o.MinimumInodesFreeThreshold)
if err != nil {
return errors.Wrapf(err, "failed to parse option: 'eviction-rootfs-minimm-inodes-free'")
}
c.MinimumInodesFreeThreshold = value
}
if o.PodMinimumUsedThreshold != "" {
value, err := eviction.ParseThresholdValue(o.PodMinimumUsedThreshold)
if err != nil {
return errors.Wrapf(err, "failed to parse option: 'eviction-rootfs-pod-minimum-used-threshold'")
}
c.PodMinimumUsedThreshold = value
}
if o.PodMinimumInodesUsedThreshold != "" {
value, err := eviction.ParseThresholdValue(o.PodMinimumInodesUsedThreshold)
if err != nil {
return errors.Wrapf(err, "failed to parse option: 'eviction-rootfs-pod-minimum-inodes-used")
}
c.PodMinimumInodesUsedThreshold = value
}
if o.ReclaimedQoSPodUsedPriorityThreshold != "" {
value, err := eviction.ParseThresholdValue(o.ReclaimedQoSPodUsedPriorityThreshold)
if err != nil {
return errors.Wrapf(err, "failed to parse option: 'eviction-rootfs-reclaimed-qos-pod-used-priority'")
}
c.ReclaimedQoSPodUsedPriorityThreshold = value
}
if o.ReclaimedQoSPodInodesUsedPriorityThreshold != "" {
value, err := eviction.ParseThresholdValue(o.ReclaimedQoSPodInodesUsedPriorityThreshold)
if err != nil {
return errors.Wrapf(err, "failed to parse option: 'eviction-rootfs-reclaimed-qos-pod-inodes-used-priority'")
}
c.ReclaimedQoSPodInodesUsedPriorityThreshold = value
}
c.GracePeriod = o.GracePeriod
return nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,47 +51,47 @@ func (c *RootfsPressureEvictionConfiguration) ApplyTo(conf *crd.DynamicConfigCRD
c.EnableRootfsPressureEviction = *config.EnableRootfsPressureEviction
}
if config.MinimumFreeThreshold != "" {
thresholdValue, err := parseThresholdValue(config.MinimumFreeThreshold)
thresholdValue, err := ParseThresholdValue(config.MinimumFreeThreshold)
if err == nil {
c.MinimumFreeThreshold = thresholdValue
} else {
general.Warningf("failed to parse minimumFreeThreshold, ignore this configuration: %q", err)
}
}
if config.MinimumInodesFreeThreshold != "" {
thresholdValue, err := parseThresholdValue(config.MinimumInodesFreeThreshold)
thresholdValue, err := ParseThresholdValue(config.MinimumInodesFreeThreshold)
if err == nil {
c.MinimumInodesFreeThreshold = thresholdValue
} else {
general.Warningf("failed to parse minimumInodesFreeThreshold, ignore this configuration: %q", err)
}
}
if config.PodMinimumUsedThreshold != "" {
thresholdValue, err := parseThresholdValue(config.PodMinimumUsedThreshold)
thresholdValue, err := ParseThresholdValue(config.PodMinimumUsedThreshold)
if err == nil {
c.PodMinimumUsedThreshold = thresholdValue
} else {
general.Warningf("failed to parse podMinimumUsedThreshold, ignore this configuration: %q", err)
}
}
if config.PodMinimumInodesUsedThreshold != "" {
thresholdValue, err := parseThresholdValue(config.PodMinimumInodesUsedThreshold)
thresholdValue, err := ParseThresholdValue(config.PodMinimumInodesUsedThreshold)
if err == nil {
c.PodMinimumInodesUsedThreshold = thresholdValue
} else {
general.Warningf("failed to parse podMinimumInodesUsedThreshold, ignore this configuration: %q", err)
}
}
if config.ReclaimedQoSPodUsedPriorityThreshold != "" {
thresholdValue, err := parseThresholdValue(config.ReclaimedQoSPodUsedPriorityThreshold)
thresholdValue, err := ParseThresholdValue(config.ReclaimedQoSPodUsedPriorityThreshold)
if err == nil {
c.ReclaimedQoSPodUsedPriorityThreshold = thresholdValue
} else {
general.Warningf("failed to parse reclaimedQoSPodUsedPriorityThreshold, ignore this configuration: %q", err)
}
}
if config.ReclaimedQoSPodInodesUsedPriorityThreshold != "" {
thresholdValue, err := parseThresholdValue(config.ReclaimedQoSPodInodesUsedPriorityThreshold)
thresholdValue, err := ParseThresholdValue(config.ReclaimedQoSPodInodesUsedPriorityThreshold)
if err == nil {
c.ReclaimedQoSPodInodesUsedPriorityThreshold = thresholdValue
} else {
Expand All @@ -104,7 +104,7 @@ func (c *RootfsPressureEvictionConfiguration) ApplyTo(conf *crd.DynamicConfigCRD
}
}

func parseThresholdValue(val string) (*evictionapi.ThresholdValue, error) {
func ParseThresholdValue(val string) (*evictionapi.ThresholdValue, error) {
if strings.HasSuffix(val, "%") {
// ignore 0% and 100%
if val == "0%" || val == "100%" {
Expand Down
Loading