Update provider and cache

Update equivalent class & remove priority

Use controller ref

Directly clear the cache
This commit is contained in:
Harry Zhang
2016-08-15 14:07:27 +08:00
parent 4dc418c5ee
commit 204dbe7fdd
4 changed files with 182 additions and 0 deletions

View File

@@ -21,6 +21,7 @@ import (
"os"
"strconv"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/cloudprovider/providers/aws"
"k8s.io/kubernetes/pkg/util/sets"
"k8s.io/kubernetes/plugin/pkg/scheduler"
@@ -36,6 +37,7 @@ const (
// GCE instances can have up to 16 PD volumes attached.
DefaultMaxGCEPDVolumes = 16
ClusterAutoscalerProvider = "ClusterAutoscalerProvider"
PetSetKind = "PetSet"
)
// getMaxVols checks the max PD volumes environment variable, otherwise returning a default value
@@ -105,6 +107,8 @@ func init() {
factory.RegisterFitPredicate("MatchNodeSelector", predicates.PodSelectorMatches)
// Optional, cluster-autoscaler friendly priority function - give used nodes higher priority.
factory.RegisterPriorityFunction2("MostRequestedPriority", priorities.MostRequestedPriorityMap, nil, 1)
// Use equivalence class to speed up predicates & priorities
factory.RegisterGetEquivalencePodFunction(GetEquivalencePod)
}
func replace(set sets.String, replaceWhat, replaceWith string) sets.String {
@@ -205,3 +209,39 @@ func defaultPriorities() sets.String {
),
)
}
// GetEquivalencePod returns a EquivalencePod which contains a group of pod attributes which can be reused.
func GetEquivalencePod(pod *api.Pod) interface{} {
equivalencePod := EquivalencePod{}
// For now we only consider pods:
// 1. OwnerReferences is Controller
// 2. OwnerReferences kind is in valid controller kinds
// 3. with same OwnerReferences
// to be equivalent
if len(pod.OwnerReferences) != 0 {
for _, ref := range pod.OwnerReferences {
if *ref.Controller && isValidControllerKind(ref.Kind) {
equivalencePod.ControllerRef = ref
// a pod can only belongs to one controller
break
}
}
}
return &equivalencePod
}
// isValidControllerKind checks if a given controller's kind can be applied to equivalence pod algorithm.
func isValidControllerKind(kind string) bool {
switch kind {
// list of kinds that we cannot handle
case PetSetKind:
return false
default:
return true
}
}
// EquivalencePod is a group of pod attributes which can be reused as equivalence to schedule other pods.
type EquivalencePod struct {
ControllerRef api.OwnerReference
}