Merge pull request #56322 from guangxuli/priority_map_performance

Automatic merge from submit-queue (batch tested with PRs 56413, 56322, 56490, 56460, 56487). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

Put process of getting pod controller reference into metadata

**What this PR does / why we need it**:
We should extract our common process/data into metadata just as other map priority functions do, so we could avoid getting same required data repeatedly in every node map process.

**Which issue(s) this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close the issue(s) when PR gets merged)*:
Fixes #
None

**Special notes for your reviewer**:

**Release note**:

```release-note
None
```
This commit is contained in:
Kubernetes Submit Queue 2017-12-15 16:43:50 -08:00 committed by GitHub
commit 40ad5d02f8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 1 deletions

View File

@ -21,6 +21,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/labels"
"k8s.io/kubernetes/plugin/pkg/scheduler/algorithm" "k8s.io/kubernetes/plugin/pkg/scheduler/algorithm"
priorityutil "k8s.io/kubernetes/plugin/pkg/scheduler/algorithm/priorities/util"
"k8s.io/kubernetes/plugin/pkg/scheduler/schedulercache" "k8s.io/kubernetes/plugin/pkg/scheduler/schedulercache"
) )
@ -47,6 +48,7 @@ type priorityMetadata struct {
podTolerations []v1.Toleration podTolerations []v1.Toleration
affinity *v1.Affinity affinity *v1.Affinity
podSelectors []labels.Selector podSelectors []labels.Selector
controllerRef *metav1.OwnerReference
} }
// PriorityMetadata is a MetadataProducer. Node info can be nil. // PriorityMetadata is a MetadataProducer. Node info can be nil.
@ -62,6 +64,7 @@ func (pmf *PriorityMetadataFactory) PriorityMetadata(pod *v1.Pod, nodeNameToInfo
podTolerations: tolerationsPreferNoSchedule, podTolerations: tolerationsPreferNoSchedule,
affinity: pod.Spec.Affinity, affinity: pod.Spec.Affinity,
podSelectors: podSelectors, podSelectors: podSelectors,
controllerRef: priorityutil.GetControllerRef(pod),
} }
} }

View File

@ -20,6 +20,7 @@ import (
"fmt" "fmt"
"k8s.io/api/core/v1" "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
v1helper "k8s.io/kubernetes/pkg/apis/core/v1/helper" v1helper "k8s.io/kubernetes/pkg/apis/core/v1/helper"
priorityutil "k8s.io/kubernetes/plugin/pkg/scheduler/algorithm/priorities/util" priorityutil "k8s.io/kubernetes/plugin/pkg/scheduler/algorithm/priorities/util"
schedulerapi "k8s.io/kubernetes/plugin/pkg/scheduler/api" schedulerapi "k8s.io/kubernetes/plugin/pkg/scheduler/api"
@ -31,8 +32,14 @@ func CalculateNodePreferAvoidPodsPriorityMap(pod *v1.Pod, meta interface{}, node
if node == nil { if node == nil {
return schedulerapi.HostPriority{}, fmt.Errorf("node not found") return schedulerapi.HostPriority{}, fmt.Errorf("node not found")
} }
var controllerRef *metav1.OwnerReference
if priorityMeta, ok := meta.(*priorityMetadata); ok {
controllerRef = priorityMeta.controllerRef
} else {
// We couldn't parse metadata - fallback to the podspec.
controllerRef = priorityutil.GetControllerRef(pod)
}
controllerRef := priorityutil.GetControllerRef(pod)
if controllerRef != nil { if controllerRef != nil {
// Ignore pods that are owned by other controller than ReplicationController // Ignore pods that are owned by other controller than ReplicationController
// or ReplicaSet. // or ReplicaSet.