Skip to content

Commit

Permalink
Merge pull request kubernetes-retired#609 from k82cn/conformance_plugin
Browse files Browse the repository at this point in the history
Added conformance plugin.
  • Loading branch information
k8s-ci-robot authored Mar 1, 2019
2 parents 81193d0 + a01a472 commit 7a3b340
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 11 deletions.
16 changes: 9 additions & 7 deletions pkg/scheduler/actions/reclaim/reclaim.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,15 +174,17 @@ func (alloc *reclaimAction) Execute(ssn *framework.Session) {
glog.V(3).Infof("Reclaimed <%v> for task <%s/%s> requested <%v>.",
reclaimed, task.Namespace, task.Name, task.Resreq)

if err := ssn.Pipeline(task, n.Name); err != nil {
glog.Errorf("Failed to pipline Task <%s/%s> on Node <%s>",
task.Namespace, task.Name, n.Name)
}
if task.Resreq.LessEqual(reclaimed) {
if err := ssn.Pipeline(task, n.Name); err != nil {
glog.Errorf("Failed to pipline Task <%s/%s> on Node <%s>",
task.Namespace, task.Name, n.Name)
}

// Ignore error of pipeline, will be corrected in next scheduling loop.
assigned = true
// Ignore error of pipeline, will be corrected in next scheduling loop.
assigned = true

break
break
}
}

if assigned {
Expand Down
60 changes: 60 additions & 0 deletions pkg/scheduler/plugins/conformance/conformance.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
Copyright 2018 The Kubernetes 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 conformance

import (
"github.com/kubernetes-sigs/kube-batch/pkg/scheduler/api"
"github.com/kubernetes-sigs/kube-batch/pkg/scheduler/framework"
"k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/kubernetes/pkg/apis/scheduling"
)

type conformancePlugin struct {
}

func New() framework.Plugin {
return &conformancePlugin{}
}

func (pp *conformancePlugin) Name() string {
return "conformance"
}

func (pp *conformancePlugin) OnSessionOpen(ssn *framework.Session) {
evictableFn := func(evictor *api.TaskInfo, evictees []*api.TaskInfo) []*api.TaskInfo {
var victims []*api.TaskInfo

for _, evictee := range evictees {
className := evictee.Pod.Spec.PriorityClassName
// Skip critical pod.
if className == scheduling.SystemClusterCritical ||
className == scheduling.SystemNodeCritical ||
evictee.Namespace == v1.NamespaceSystem {
continue
}

victims = append(victims, evictee)
}

return victims
}

ssn.AddPreemptableFn(pp.Name(), evictableFn)
ssn.AddReclaimableFn(pp.Name(), evictableFn)
}

func (pp *conformancePlugin) OnSessionClose(ssn *framework.Session) {}
8 changes: 4 additions & 4 deletions pkg/scheduler/plugins/prioritize/prioritize.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,28 +183,28 @@ func (pp *prioritizePlugin) OnSessionOpen(ssn *framework.Session) {

host, err := priorities.LeastRequestedPriorityMap(task.Pod, nil, nodeInfo)
if err != nil {
glog.V(3).Infof("Least Requested Priority Failed because of Error: %v", err)
glog.Warningf("Least Requested Priority Failed because of Error: %v", err)
return 0, err
}
score = score + host.Score

host, err = priorities.CalculateNodeAffinityPriorityMap(task.Pod, nil, nodeInfo)
if err != nil {
glog.V(3).Infof("Calculate Node Affinity Priority Failed because of Error: %v", err)
glog.Warningf("Calculate Node Affinity Priority Failed because of Error: %v", err)
return 0, err
}
score = score + host.Score

mapFn := priorities.NewInterPodAffinityPriority(cn, nl, pl, v1.DefaultHardPodAffinitySymmetricWeight)
interPodAffinityScore, err = mapFn(task.Pod, nodeMap, nodeSlice)
if err != nil {
glog.V(3).Infof("Calculate Inter Pod Affinity Priority Failed because of Error: %v", err)
glog.Warningf("Calculate Inter Pod Affinity Priority Failed because of Error: %v", err)
return 0, err
}
hostScore := getInterPodAffinityScore(node.Name, interPodAffinityScore)
score = score + hostScore

glog.V(3).Infof("Total Score for that node is: %f", score)
glog.V(4).Infof("Total Score for that node is: %d", score)
return score, nil
}
ssn.AddPriorityFn(pp.Name(), priorityFn)
Expand Down

0 comments on commit 7a3b340

Please sign in to comment.