diff --git a/pkg/scheduler/api/node_info.go b/pkg/scheduler/api/node_info.go index 52f573438c..948e5ebcf5 100644 --- a/pkg/scheduler/api/node_info.go +++ b/pkg/scheduler/api/node_info.go @@ -94,20 +94,20 @@ type NodeState struct { } type NodeUsage struct { - CpuUsageAvg map[string]float64 - MemUsageAvg map[string]float64 + CPUUsageAvg map[string]float64 + MEMUsageAvg map[string]float64 } func (nu *NodeUsage) DeepCopy() *NodeUsage { newUsage := &NodeUsage{ - CpuUsageAvg: make(map[string]float64), - MemUsageAvg: make(map[string]float64), + CPUUsageAvg: make(map[string]float64), + MEMUsageAvg: make(map[string]float64), } - for k, v := range nu.CpuUsageAvg { - newUsage.CpuUsageAvg[k] = v + for k, v := range nu.CPUUsageAvg { + newUsage.CPUUsageAvg[k] = v } - for k, v := range nu.MemUsageAvg { - newUsage.MemUsageAvg[k] = v + for k, v := range nu.MEMUsageAvg { + newUsage.MEMUsageAvg[k] = v } return newUsage } diff --git a/pkg/scheduler/api/node_info_test.go b/pkg/scheduler/api/node_info_test.go index c14e3c3a46..fb6615c6e4 100644 --- a/pkg/scheduler/api/node_info_test.go +++ b/pkg/scheduler/api/node_info_test.go @@ -58,6 +58,7 @@ func TestNodeInfo_AddPod(t *testing.T) { OversubscriptionResource: EmptyResource(), Allocatable: buildResource("8000m", "10G"), Capability: buildResource("8000m", "10G"), + ResourceUsage: &NodeUsage{}, State: NodeState{Phase: Ready}, Tasks: map[TaskID]*TaskInfo{ "c1/p1": NewTaskInfo(case01Pod1), @@ -80,6 +81,7 @@ func TestNodeInfo_AddPod(t *testing.T) { OversubscriptionResource: EmptyResource(), Allocatable: buildResource("2000m", "1G"), Capability: buildResource("2000m", "1G"), + ResourceUsage: &NodeUsage{}, State: NodeState{Phase: Ready}, Tasks: map[TaskID]*TaskInfo{}, GPUDevices: make(map[int]*GPUDevice), @@ -138,6 +140,7 @@ func TestNodeInfo_RemovePod(t *testing.T) { Pipelined: EmptyResource(), Allocatable: buildResource("8000m", "10G"), Capability: buildResource("8000m", "10G"), + ResourceUsage: &NodeUsage{}, State: NodeState{Phase: Ready}, Tasks: map[TaskID]*TaskInfo{ "c1/p1": NewTaskInfo(case01Pod1), @@ -198,6 +201,7 @@ func TestNodeInfo_SetNode(t *testing.T) { Pipelined: EmptyResource(), Allocatable: buildResource("10", "10G"), Capability: buildResource("10", "10G"), + ResourceUsage: &NodeUsage{}, State: NodeState{Phase: NotReady, Reason: "OutOfSync"}, Tasks: map[TaskID]*TaskInfo{ "c1/p1": NewTaskInfo(case01Pod1), diff --git a/pkg/scheduler/cache/cache.go b/pkg/scheduler/cache/cache.go index 4604c9d909..4cfd2c736c 100644 --- a/pkg/scheduler/cache/cache.go +++ b/pkg/scheduler/cache/cache.go @@ -633,7 +633,6 @@ func (sc *SchedulerCache) Run(stopCh <-chan struct{}) { interval = time.Duration(defaultMetricsInternal) } go wait.Until(sc.GetMetricsData, interval, stopCh) - } // WaitForCacheSync sync the cache with the api server @@ -1200,8 +1199,8 @@ func (sc *SchedulerCache) GetMetricsData() { sc.Mutex.Lock() for k := range sc.Nodes { nodeUsageMap[k] = &schedulingapi.NodeUsage{ - CpuUsageAvg: make(map[string]float64), - MemUsageAvg: make(map[string]float64), + CPUUsageAvg: make(map[string]float64), + MEMUsageAvg: make(map[string]float64), } } sc.Mutex.Unlock() @@ -1227,11 +1226,11 @@ func (sc *SchedulerCache) GetMetricsData() { switch metric { case "cpu_usage_avg": cpuUsage, _ := strconv.ParseFloat(value[0], 64) - nodeUsageMap[node].CpuUsageAvg[period] = cpuUsage + nodeUsageMap[node].CPUUsageAvg[period] = cpuUsage klog.V(4).Infof("node: %v, CpuUsageAvg: %v, period:%v", node, cpuUsage, period) case "mem_usage_avg": memUsage, _ := strconv.ParseFloat(value[0], 64) - nodeUsageMap[node].MemUsageAvg[period] = memUsage + nodeUsageMap[node].MEMUsageAvg[period] = memUsage klog.V(4).Infof("node: %v, MemUsageAvg: %v, period:%v", node, memUsage, period) } } diff --git a/pkg/scheduler/cache/cache_test.go b/pkg/scheduler/cache/cache_test.go index 08920aa703..936d73d202 100644 --- a/pkg/scheduler/cache/cache_test.go +++ b/pkg/scheduler/cache/cache_test.go @@ -212,7 +212,7 @@ func TestSchedulerCache_Bind_NodeWithInsufficientResources(t *testing.T) { t.Errorf("expected task to remain the same after failed bind: \n %#v\n %#v", taskBeforeBind, taskAfterBind) } - nodeAfterBind := cache.Nodes["n1"] + nodeAfterBind := cache.Nodes["n1"].Clone() if !reflect.DeepEqual(nodeBeforeBind, nodeAfterBind) { t.Errorf("expected node to remain the same after failed bind") } diff --git a/pkg/scheduler/plugins/usage/usage.go b/pkg/scheduler/plugins/usage/usage.go index 1844cb137b..7ed3fb8a2d 100644 --- a/pkg/scheduler/plugins/usage/usage.go +++ b/pkg/scheduler/plugins/usage/usage.go @@ -29,8 +29,8 @@ import ( const ( // PluginName indicates name of volcano scheduler plugin. PluginName = "usage" - cpuUsageAvgPrefix = "CpuUsageAvg." - memUsageAvgPrefix = "MemUsageAvg." + cpuUsageAvgPrefix = "CPUUsageAvg." + memUsageAvgPrefix = "MEMUsageAvg." thresholdSection = "thresholds" cpuUsageAvg5m = "5m" ) @@ -42,8 +42,8 @@ const ( - name: usage arguments: thresholds: - CpuUsageAvg.5m: 80 - MemUsageAvg.5m: 90 + CPUUsageAvg.5m: 80 + MEMUsageAvg.5m: 90 */ type thresholdConfig struct { @@ -53,8 +53,8 @@ type thresholdConfig struct { type usagePlugin struct { pluginArguments framework.Arguments - weight int - threshold thresholdConfig + weight int + threshold thresholdConfig } // New function returns usagePlugin object @@ -87,7 +87,7 @@ func (up *usagePlugin) OnSessionOpen(ssn *framework.Session) { if klog.V(4) { for node := range ssn.Nodes { usage := ssn.Nodes[node].ResourceUsage - klog.V(4).Infof("node:%v, cpu usage:%v, mem usage:%v", node, usage.CpuUsageAvg["5m"], usage.MemUsageAvg["5m"]) + klog.V(4).Infof("node:%v, cpu usage:%v, mem usage:%v", node, usage.CPUUsageAvg["5m"], usage.MEMUsageAvg["5m"]) } } @@ -100,19 +100,19 @@ func (up *usagePlugin) OnSessionOpen(ssn *framework.Session) { for k, v := range args { key, _ := k.(string) var val float64 - switch v.(type) { + switch a := v.(type) { case string: - val, _ = strconv.ParseFloat(v.(string), 64) + val, _ = strconv.ParseFloat(a, 64) case int: - val = float64(v.(int)) + val = float64(a) case float64: - val = v.(float64) + val = a default: - klog.V(4).Infof("The threshold %v is an unknown type", v) + klog.V(4).Infof("The threshold %v is an unknown type", a) } if strings.Contains(key, cpuUsageAvgPrefix) { periodKey := strings.Replace(key, cpuUsageAvgPrefix, "", 1) - up.threshold.cpuUsageAvg[periodKey] = val + up.threshold.cpuUsageAvg[periodKey] = val } if strings.Contains(key, memUsageAvgPrefix) { periodKey := strings.Replace(key, memUsageAvgPrefix, "", 1) @@ -127,16 +127,16 @@ func (up *usagePlugin) OnSessionOpen(ssn *framework.Session) { predicateFn := func(task *api.TaskInfo, node *api.NodeInfo) error { for period, value := range up.threshold.cpuUsageAvg { klog.V(4).Infof("predicateFn cpuUsageAvg:%v", up.threshold.cpuUsageAvg) - if node.ResourceUsage.CpuUsageAvg[period] > value { - msg := fmt.Sprintf("Node %s cpu usage %f exceeds the threshold %f", node.Name, node.ResourceUsage.CpuUsageAvg[period], value) + if node.ResourceUsage.CPUUsageAvg[period] > value { + msg := fmt.Sprintf("Node %s cpu usage %f exceeds the threshold %f", node.Name, node.ResourceUsage.CPUUsageAvg[period], value) return fmt.Errorf("plugin %s predicates failed %s", up.Name(), msg) } } for period, value := range up.threshold.memUsageAvg { klog.V(4).Infof("predicateFn memUsageAvg:%v", up.threshold.memUsageAvg) - if node.ResourceUsage.MemUsageAvg[period] > value { - msg := fmt.Sprintf("Node %s mem usage %f exceeds the threshold %f", node.Name, node.ResourceUsage.MemUsageAvg[period], value) + if node.ResourceUsage.MEMUsageAvg[period] > value { + msg := fmt.Sprintf("Node %s mem usage %f exceeds the threshold %f", node.Name, node.ResourceUsage.MEMUsageAvg[period], value) return fmt.Errorf("plugin %s memory usage predicates failed %s", up.Name(), msg) } } @@ -146,7 +146,7 @@ func (up *usagePlugin) OnSessionOpen(ssn *framework.Session) { nodeOrderFn := func(task *api.TaskInfo, node *api.NodeInfo) (float64, error) { score := 0.0 - cpuUsage, exist := node.ResourceUsage.CpuUsageAvg[cpuUsageAvg5m] + cpuUsage, exist := node.ResourceUsage.CPUUsageAvg[cpuUsageAvg5m] klog.V(4).Infof("Node %s cpu usage is %f.", node.Name, cpuUsage) if !exist { return 0, nil diff --git a/pkg/scheduler/util_test.go b/pkg/scheduler/util_test.go index dd08624801..c8f5504565 100644 --- a/pkg/scheduler/util_test.go +++ b/pkg/scheduler/util_test.go @@ -186,7 +186,7 @@ tiers: var expectedConfigurations []conf.Configuration - _, tiers, configurations, err := unmarshalSchedulerConf(configuration) + _, tiers, configurations, _, err := unmarshalSchedulerConf(configuration) if err != nil { t.Errorf("Failed to load scheduler configuration: %v", err) }