mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-28 14:07:14 +00:00
Remove unneeded factories
This commit is contained in:
parent
d6e84cc2e9
commit
e8e8e2d086
@ -999,19 +999,11 @@ func (checker *PodAffinityChecker) NodeMatchPodAffinityAntiAffinity(pod *api.Pod
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
type TolerationMatch struct {
|
func PodToleratesNodeTaints(pod *api.Pod, meta interface{}, nodeInfo *schedulercache.NodeInfo) (bool, error) {
|
||||||
info NodeInfo
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewTolerationMatchPredicate(info NodeInfo) algorithm.FitPredicate {
|
|
||||||
tolerationMatch := &TolerationMatch{
|
|
||||||
info: info,
|
|
||||||
}
|
|
||||||
return tolerationMatch.PodToleratesNodeTaints
|
|
||||||
}
|
|
||||||
|
|
||||||
func (t *TolerationMatch) PodToleratesNodeTaints(pod *api.Pod, meta interface{}, nodeInfo *schedulercache.NodeInfo) (bool, error) {
|
|
||||||
node := nodeInfo.Node()
|
node := nodeInfo.Node()
|
||||||
|
if node == nil {
|
||||||
|
return false, fmt.Errorf("node not found")
|
||||||
|
}
|
||||||
|
|
||||||
taints, err := api.GetTaintsFromNodeAnnotations(node.Annotations)
|
taints, err := api.GetTaintsFromNodeAnnotations(node.Annotations)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -2724,10 +2724,9 @@ func TestPodToleratesTaints(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range podTolerateTaintsTests {
|
for _, test := range podTolerateTaintsTests {
|
||||||
tolerationMatch := TolerationMatch{FakeNodeInfo(test.node)}
|
|
||||||
nodeInfo := schedulercache.NewNodeInfo()
|
nodeInfo := schedulercache.NewNodeInfo()
|
||||||
nodeInfo.SetNode(&test.node)
|
nodeInfo.SetNode(&test.node)
|
||||||
fits, err := tolerationMatch.PodToleratesNodeTaints(test.pod, PredicateMetadata(test.pod), nodeInfo)
|
fits, err := PodToleratesNodeTaints(test.pod, PredicateMetadata(test.pod), nodeInfo)
|
||||||
if fits == false && !reflect.DeepEqual(err, ErrTaintsTolerationsNotMatch) {
|
if fits == false && !reflect.DeepEqual(err, ErrTaintsTolerationsNotMatch) {
|
||||||
t.Errorf("%s, unexpected error: %v", test.test, err)
|
t.Errorf("%s, unexpected error: %v", test.test, err)
|
||||||
}
|
}
|
||||||
|
@ -25,23 +25,12 @@ import (
|
|||||||
"k8s.io/kubernetes/plugin/pkg/scheduler/schedulercache"
|
"k8s.io/kubernetes/plugin/pkg/scheduler/schedulercache"
|
||||||
)
|
)
|
||||||
|
|
||||||
type NodeAffinity struct {
|
|
||||||
nodeLister algorithm.NodeLister
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewNodeAffinityPriority(nodeLister algorithm.NodeLister) algorithm.PriorityFunction {
|
|
||||||
nodeAffinity := &NodeAffinity{
|
|
||||||
nodeLister: nodeLister,
|
|
||||||
}
|
|
||||||
return nodeAffinity.CalculateNodeAffinityPriority
|
|
||||||
}
|
|
||||||
|
|
||||||
// CalculateNodeAffinityPriority prioritizes nodes according to node affinity scheduling preferences
|
// CalculateNodeAffinityPriority prioritizes nodes according to node affinity scheduling preferences
|
||||||
// indicated in PreferredDuringSchedulingIgnoredDuringExecution. Each time a node match a preferredSchedulingTerm,
|
// indicated in PreferredDuringSchedulingIgnoredDuringExecution. Each time a node match a preferredSchedulingTerm,
|
||||||
// it will a get an add of preferredSchedulingTerm.Weight. Thus, the more preferredSchedulingTerms
|
// it will a get an add of preferredSchedulingTerm.Weight. Thus, the more preferredSchedulingTerms
|
||||||
// the node satisfies and the more the preferredSchedulingTerm that is satisfied weights, the higher
|
// the node satisfies and the more the preferredSchedulingTerm that is satisfied weights, the higher
|
||||||
// score the node gets.
|
// score the node gets.
|
||||||
func (s *NodeAffinity) CalculateNodeAffinityPriority(pod *api.Pod, nodeNameToInfo map[string]*schedulercache.NodeInfo, nodeLister algorithm.NodeLister) (schedulerapi.HostPriorityList, error) {
|
func CalculateNodeAffinityPriority(pod *api.Pod, nodeNameToInfo map[string]*schedulercache.NodeInfo, nodeLister algorithm.NodeLister) (schedulerapi.HostPriorityList, error) {
|
||||||
var maxCount int
|
var maxCount int
|
||||||
counts := map[string]int{}
|
counts := map[string]int{}
|
||||||
|
|
||||||
|
@ -156,8 +156,7 @@ func TestNodeAffinityPriority(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
nodeAffinity := NodeAffinity{nodeLister: algorithm.FakeNodeLister(api.NodeList{Items: test.nodes})}
|
list, err := CalculateNodeAffinityPriority(test.pod, schedulercache.CreateNodeNameToInfoMap(nil), algorithm.FakeNodeLister(api.NodeList{Items: test.nodes}))
|
||||||
list, err := nodeAffinity.CalculateNodeAffinityPriority(test.pod, schedulercache.CreateNodeNameToInfoMap(nil), algorithm.FakeNodeLister(api.NodeList{Items: test.nodes}))
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("unexpected error: %v", err)
|
t.Errorf("unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -24,19 +24,6 @@ import (
|
|||||||
"k8s.io/kubernetes/plugin/pkg/scheduler/schedulercache"
|
"k8s.io/kubernetes/plugin/pkg/scheduler/schedulercache"
|
||||||
)
|
)
|
||||||
|
|
||||||
// NodeTaints hold the node lister
|
|
||||||
type TaintToleration struct {
|
|
||||||
nodeLister algorithm.NodeLister
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewTaintTolerationPriority
|
|
||||||
func NewTaintTolerationPriority(nodeLister algorithm.NodeLister) algorithm.PriorityFunction {
|
|
||||||
taintToleration := &TaintToleration{
|
|
||||||
nodeLister: nodeLister,
|
|
||||||
}
|
|
||||||
return taintToleration.ComputeTaintTolerationPriority
|
|
||||||
}
|
|
||||||
|
|
||||||
// CountIntolerableTaintsPreferNoSchedule gives the count of intolerable taints of a pod with effect PreferNoSchedule
|
// CountIntolerableTaintsPreferNoSchedule gives the count of intolerable taints of a pod with effect PreferNoSchedule
|
||||||
func countIntolerableTaintsPreferNoSchedule(taints []api.Taint, tolerations []api.Toleration) (intolerableTaints int) {
|
func countIntolerableTaintsPreferNoSchedule(taints []api.Taint, tolerations []api.Toleration) (intolerableTaints int) {
|
||||||
for _, taint := range taints {
|
for _, taint := range taints {
|
||||||
@ -63,7 +50,7 @@ func getAllTolerationPreferNoSchedule(tolerations []api.Toleration) (tolerationL
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ComputeTaintTolerationPriority prepares the priority list for all the nodes based on the number of intolerable taints on the node
|
// ComputeTaintTolerationPriority prepares the priority list for all the nodes based on the number of intolerable taints on the node
|
||||||
func (s *TaintToleration) ComputeTaintTolerationPriority(pod *api.Pod, nodeNameToInfo map[string]*schedulercache.NodeInfo, nodeLister algorithm.NodeLister) (schedulerapi.HostPriorityList, error) {
|
func ComputeTaintTolerationPriority(pod *api.Pod, nodeNameToInfo map[string]*schedulercache.NodeInfo, nodeLister algorithm.NodeLister) (schedulerapi.HostPriorityList, error) {
|
||||||
// counts hold the count of intolerable taints of a pod for a given node
|
// counts hold the count of intolerable taints of a pod for a given node
|
||||||
counts := make(map[string]int)
|
counts := make(map[string]int)
|
||||||
|
|
||||||
|
@ -212,8 +212,7 @@ func TestTaintAndToleration(t *testing.T) {
|
|||||||
}
|
}
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
nodeNameToInfo := schedulercache.CreateNodeNameToInfoMap([]*api.Pod{{}})
|
nodeNameToInfo := schedulercache.CreateNodeNameToInfoMap([]*api.Pod{{}})
|
||||||
taintToleration := TaintToleration{nodeLister: algorithm.FakeNodeLister(api.NodeList{Items: test.nodes})}
|
list, err := ComputeTaintTolerationPriority(
|
||||||
list, err := taintToleration.ComputeTaintTolerationPriority(
|
|
||||||
test.pod,
|
test.pod,
|
||||||
nodeNameToInfo,
|
nodeNameToInfo,
|
||||||
algorithm.FakeNodeLister(api.NodeList{Items: test.nodes}))
|
algorithm.FakeNodeLister(api.NodeList{Items: test.nodes}))
|
||||||
|
@ -147,12 +147,7 @@ func defaultPredicates() sets.String {
|
|||||||
factory.RegisterFitPredicate("GeneralPredicates", predicates.GeneralPredicates),
|
factory.RegisterFitPredicate("GeneralPredicates", predicates.GeneralPredicates),
|
||||||
|
|
||||||
// Fit is determined based on whether a pod can tolerate all of the node's taints
|
// Fit is determined based on whether a pod can tolerate all of the node's taints
|
||||||
factory.RegisterFitPredicateFactory(
|
factory.RegisterFitPredicate("PodToleratesNodeTaints", predicates.PodToleratesNodeTaints),
|
||||||
"PodToleratesNodeTaints",
|
|
||||||
func(args factory.PluginFactoryArgs) algorithm.FitPredicate {
|
|
||||||
return predicates.NewTolerationMatchPredicate(args.NodeInfo)
|
|
||||||
},
|
|
||||||
),
|
|
||||||
|
|
||||||
// Fit is determined by node memory pressure condition.
|
// Fit is determined by node memory pressure condition.
|
||||||
factory.RegisterFitPredicate("CheckNodeMemoryPressure", predicates.CheckNodeMemoryPressurePredicate),
|
factory.RegisterFitPredicate("CheckNodeMemoryPressure", predicates.CheckNodeMemoryPressurePredicate),
|
||||||
@ -175,23 +170,7 @@ func defaultPriorities() sets.String {
|
|||||||
Weight: 1,
|
Weight: 1,
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
factory.RegisterPriorityConfigFactory(
|
factory.RegisterPriorityFunction("NodeAffinityPriority", priorities.CalculateNodeAffinityPriority, 1),
|
||||||
"NodeAffinityPriority",
|
factory.RegisterPriorityFunction("TaintTolerationPriority", priorities.ComputeTaintTolerationPriority, 1),
|
||||||
factory.PriorityConfigFactory{
|
|
||||||
Function: func(args factory.PluginFactoryArgs) algorithm.PriorityFunction {
|
|
||||||
return priorities.NewNodeAffinityPriority(args.NodeLister)
|
|
||||||
},
|
|
||||||
Weight: 1,
|
|
||||||
},
|
|
||||||
),
|
|
||||||
factory.RegisterPriorityConfigFactory(
|
|
||||||
"TaintTolerationPriority",
|
|
||||||
factory.PriorityConfigFactory{
|
|
||||||
Function: func(args factory.PluginFactoryArgs) algorithm.PriorityFunction {
|
|
||||||
return priorities.NewTaintTolerationPriority(args.NodeLister)
|
|
||||||
},
|
|
||||||
Weight: 1,
|
|
||||||
},
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user