Skip to content

Commit

Permalink
descheduler: add a cache timeout argument for nodeAnomalyDetectors in…
Browse files Browse the repository at this point in the history
… lowNodeLoad plugin. (koordinator-sh#1955)

Signed-off-by: bogo <bogo.ysh@gmail.com>
Co-authored-by: zengwang1 <zengwang1@xiaomi.com>
  • Loading branch information
2 people authored and ls-2018 committed Mar 25, 2024
1 parent 2de9f08 commit 08223fa
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 4 deletions.
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

0 comments on commit 08223fa

Please sign in to comment.