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

descheduler: add a cache timeout argument for nodeAnomalyDetectors in lowNodeLoad plugin. #1955

Merged
merged 4 commits into from
Mar 19, 2024
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
3 changes: 3 additions & 0 deletions pkg/descheduler/apis/config/types_loadaware.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ type LowNodeLoadArgs struct {
// it is determined that the node is abnormal, and the Pods need to be migrated to reduce the load.
AnomalyCondition *LoadAnomalyCondition

// DetectorCacheTimeout indicates the cache expiration time of nodeAnomalyDetectors, the default is 5 minutes
DetectorCacheTimeout *metav1.Duration

// NodePools supports multiple different types of batch nodes to configure different strategies
NodePools []LowNodeLoadNodePool
}
Expand Down
4 changes: 4 additions & 0 deletions pkg/descheduler/apis/config/v1alpha2/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ const (
defaultMigrationEvictBurst = 1
defaultSchedulerSupportReservation = "koord-scheduler"
defaultArbitrationInterval = 500 * time.Millisecond
defaultDetectorCacheTimeout = 5 * time.Minute
)

var (
Expand Down Expand Up @@ -263,6 +264,9 @@ func SetDefaults_LowNodeLoadArgs(obj *LowNodeLoadArgs) {
} else if obj.AnomalyCondition.ConsecutiveAbnormalities == 0 {
obj.AnomalyCondition.ConsecutiveAbnormalities = defaultLoadAnomalyCondition.ConsecutiveAbnormalities
}
if obj.DetectorCacheTimeout == nil {
obj.DetectorCacheTimeout = &metav1.Duration{Duration: defaultDetectorCacheTimeout}
}

if obj.NodeMetricExpirationSeconds == nil {
obj.NodeMetricExpirationSeconds = pointer.Int64(defaultNodeMetricExpirationSeconds)
Expand Down
19 changes: 19 additions & 0 deletions pkg/descheduler/apis/config/v1alpha2/defaults_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,23 @@ func TestSetDefaults_LowNodeLoadArgs(t *testing.T) {
NodeFit: pointer.Bool(false),
NodeMetricExpirationSeconds: pointer.Int64(defaultNodeMetricExpirationSeconds),
AnomalyCondition: defaultLoadAnomalyCondition,
DetectorCacheTimeout: &metav1.Duration{Duration: 5 * time.Minute},
ResourceWeights: map[corev1.ResourceName]int64{
corev1.ResourceCPU: 1,
corev1.ResourceMemory: 1,
},
},
},
{
name: "set detectorCacheTimeout",
args: &LowNodeLoadArgs{
DetectorCacheTimeout: &metav1.Duration{Duration: 10 * time.Minute},
},
expected: &LowNodeLoadArgs{
NodeFit: pointer.Bool(true),
NodeMetricExpirationSeconds: pointer.Int64(defaultNodeMetricExpirationSeconds),
AnomalyCondition: defaultLoadAnomalyCondition,
DetectorCacheTimeout: &metav1.Duration{Duration: 10 * time.Minute},
ResourceWeights: map[corev1.ResourceName]int64{
corev1.ResourceCPU: 1,
corev1.ResourceMemory: 1,
Expand All @@ -64,6 +81,7 @@ func TestSetDefaults_LowNodeLoadArgs(t *testing.T) {
ConsecutiveAbnormalities: defaultLoadAnomalyCondition.ConsecutiveAbnormalities,
ConsecutiveNormalities: 3,
},
DetectorCacheTimeout: &metav1.Duration{Duration: 5 * time.Minute},
ResourceWeights: map[corev1.ResourceName]int64{
corev1.ResourceCPU: 1,
corev1.ResourceMemory: 1,
Expand All @@ -87,6 +105,7 @@ func TestSetDefaults_LowNodeLoadArgs(t *testing.T) {
NodeFit: pointer.Bool(true),
NodeMetricExpirationSeconds: pointer.Int64(defaultNodeMetricExpirationSeconds),
AnomalyCondition: defaultLoadAnomalyCondition,
DetectorCacheTimeout: &metav1.Duration{Duration: 5 * time.Minute},
LowThresholds: ResourceThresholds{
corev1.ResourceCPU: 30,
corev1.ResourceMemory: 30,
Expand Down
3 changes: 3 additions & 0 deletions pkg/descheduler/apis/config/v1alpha2/types_loadaware.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ type LowNodeLoadArgs struct {
// it is determined that the node is abnormal, and the Pods need to be migrated to reduce the load.
AnomalyCondition *LoadAnomalyCondition `json:"anomalyCondition,omitempty"`

// DetectorCacheTimeout indicates the cache expiration time of nodeAnomalyDetectors, the default is 5 minute
DetectorCacheTimeout *metav1.Duration `json:"detectorCacheTimeout,omitempty"`

// NodePools supports multiple different types of batch nodes to configure different strategies
NodePools []LowNodeLoadNodePool `json:"nodePools,omitempty"`
}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions pkg/descheduler/apis/config/v1alpha2/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions pkg/descheduler/apis/config/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions pkg/descheduler/framework/plugins/loadaware/low_node_load.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"fmt"
"sort"
"strings"
"time"

gocache "github.com/patrickmn/go-cache"
corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -107,7 +106,7 @@ func NewLowNodeLoad(args runtime.Object, handle framework.Handle) (framework.Plu
koordSharedInformerFactory.Start(context.TODO().Done())
koordSharedInformerFactory.WaitForCacheSync(context.TODO().Done())

nodeAnomalyDetectors := gocache.New(5*time.Minute, 5*time.Minute)
nodeAnomalyDetectors := gocache.New(loadLoadUtilizationArgs.DetectorCacheTimeout.Duration, loadLoadUtilizationArgs.DetectorCacheTimeout.Duration)

return &LowNodeLoad{
handle: handle,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1030,7 +1030,8 @@ func TestLowNodeLoad(t *testing.T) {
},
},
},
EvictableNamespaces: tt.evictableNamespaces,
DetectorCacheTimeout: &metav1.Duration{Duration: 5 * time.Minute},
EvictableNamespaces: tt.evictableNamespaces,
},
})
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ func evictPods(
"nodePool", nodePoolName,
}
for k, v := range nodeInfo.usage {
keysAndValues = append(keysAndValues, k, v.String())
keysAndValues = append(keysAndValues, k.String(), v.String())
}
for resourceName, quantity := range totalAvailableUsages {
keysAndValues = append(keysAndValues, fmt.Sprintf("%s/totalAvailable", resourceName), quantity.String())
Expand Down
Loading