mirror of
https://github.com/optim-enterprises-bv/kubernetes.git
synced 2025-11-02 03:08:15 +00:00
Merge pull request #31605 from resouer/eclass-1
Automatic merge from submit-queue [Part 1] Implementation of equivalence pod Part 1 of #30844 This PR: - Refactored `predicate.go`, so that `GetResourceRequest` can be used in other places to `GetEquivalencePod`. - Implement a `equivalence_cache.go` to deal with all information we need to calculate an equivalent pod. - Define and register a `RegisterGetEquivalencePodFunction `. Work in next PR: - The update of `equivalence_cache.go` - Unit test - Integration/e2e test I think we can begin from the `equivalence_cache.go`? Thanks. cc @wojtek-t @davidopp If I missed any other necessary part, please point it out.
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user