mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-07 20:21:20 +00:00
Changing the scheduler package to use *api.Pod instead of api.Pod to
avoid unnecessary shallow copies. The change rippled through a lot of code.
This commit is contained in:
@@ -115,19 +115,19 @@ func TestCreateFromEmptyConfig(t *testing.T) {
|
||||
factory.CreateFromConfig(policy)
|
||||
}
|
||||
|
||||
func PredicateOne(pod api.Pod, existingPods []api.Pod, node string) (bool, error) {
|
||||
func PredicateOne(pod *api.Pod, existingPods []*api.Pod, node string) (bool, error) {
|
||||
return true, nil
|
||||
}
|
||||
|
||||
func PredicateTwo(pod api.Pod, existingPods []api.Pod, node string) (bool, error) {
|
||||
func PredicateTwo(pod *api.Pod, existingPods []*api.Pod, node string) (bool, error) {
|
||||
return true, nil
|
||||
}
|
||||
|
||||
func PriorityOne(pod api.Pod, podLister algorithm.PodLister, minionLister algorithm.MinionLister) (algorithm.HostPriorityList, error) {
|
||||
func PriorityOne(pod *api.Pod, podLister algorithm.PodLister, minionLister algorithm.MinionLister) (algorithm.HostPriorityList, error) {
|
||||
return []algorithm.HostPriority{}, nil
|
||||
}
|
||||
|
||||
func PriorityTwo(pod api.Pod, podLister algorithm.PodLister, minionLister algorithm.MinionLister) (algorithm.HostPriorityList, error) {
|
||||
func PriorityTwo(pod *api.Pod, podLister algorithm.PodLister, minionLister algorithm.MinionLister) (algorithm.HostPriorityList, error) {
|
||||
return []algorithm.HostPriority{}, nil
|
||||
}
|
||||
|
||||
|
@@ -123,7 +123,7 @@ func (s *SimpleModeler) ForgetPodByKey(key string) {
|
||||
}
|
||||
|
||||
// Extract names for readable logging.
|
||||
func podNames(pods []api.Pod) []string {
|
||||
func podNames(pods []*api.Pod) []string {
|
||||
out := make([]string, len(pods))
|
||||
for i := range pods {
|
||||
out[i] = fmt.Sprintf("'%v/%v (%v)'", pods[i].Namespace, pods[i].Name, pods[i].UID)
|
||||
@@ -131,7 +131,7 @@ func podNames(pods []api.Pod) []string {
|
||||
return out
|
||||
}
|
||||
|
||||
func (s *SimpleModeler) listPods(selector labels.Selector) (pods []api.Pod, err error) {
|
||||
func (s *SimpleModeler) listPods(selector labels.Selector) (pods []*api.Pod, err error) {
|
||||
assumed, err := s.assumedPods.List(selector)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -140,20 +140,20 @@ func (s *SimpleModeler) listPods(selector labels.Selector) (pods []api.Pod, err
|
||||
// Goal here is to stop making assumptions about a pod once it shows
|
||||
// up in one of these other lists.
|
||||
for _, pod := range assumed {
|
||||
qExist, err := s.queuedPods.Exists(&pod)
|
||||
qExist, err := s.queuedPods.Exists(pod)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if qExist {
|
||||
s.assumedPods.Store.Delete(&pod)
|
||||
s.assumedPods.Store.Delete(pod)
|
||||
continue
|
||||
}
|
||||
sExist, err := s.scheduledPods.Exists(&pod)
|
||||
sExist, err := s.scheduledPods.Exists(pod)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if sExist {
|
||||
s.assumedPods.Store.Delete(&pod)
|
||||
s.assumedPods.Store.Delete(pod)
|
||||
continue
|
||||
}
|
||||
}
|
||||
@@ -190,6 +190,6 @@ type simpleModelerPods struct {
|
||||
}
|
||||
|
||||
// List returns pods known and assumed to exist.
|
||||
func (s simpleModelerPods) List(selector labels.Selector) (pods []api.Pod, err error) {
|
||||
func (s simpleModelerPods) List(selector labels.Selector) (pods []*api.Pod, err error) {
|
||||
return s.simpleModeler.listPods(selector)
|
||||
}
|
||||
|
@@ -30,15 +30,15 @@ type nn struct {
|
||||
|
||||
type names []nn
|
||||
|
||||
func (ids names) list() []api.Pod {
|
||||
out := make([]api.Pod, len(ids))
|
||||
for i, id := range ids {
|
||||
out[i] = api.Pod{
|
||||
func (ids names) list() []*api.Pod {
|
||||
out := make([]*api.Pod, 0, len(ids))
|
||||
for _, id := range ids {
|
||||
out = append(out, &api.Pod{
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
Namespace: id.namespace,
|
||||
Name: id.name,
|
||||
},
|
||||
}
|
||||
})
|
||||
}
|
||||
return out
|
||||
}
|
||||
@@ -54,9 +54,9 @@ func (ids names) has(pod *api.Pod) bool {
|
||||
|
||||
func TestModeler(t *testing.T) {
|
||||
table := []struct {
|
||||
queuedPods []api.Pod
|
||||
scheduledPods []api.Pod
|
||||
assumedPods []api.Pod
|
||||
queuedPods []*api.Pod
|
||||
scheduledPods []*api.Pod
|
||||
assumedPods []*api.Pod
|
||||
expectPods names
|
||||
}{
|
||||
{
|
||||
@@ -79,16 +79,16 @@ func TestModeler(t *testing.T) {
|
||||
|
||||
for _, item := range table {
|
||||
q := &cache.StoreToPodLister{cache.NewStore(cache.MetaNamespaceKeyFunc)}
|
||||
for i := range item.queuedPods {
|
||||
q.Store.Add(&item.queuedPods[i])
|
||||
for _, pod := range item.queuedPods {
|
||||
q.Store.Add(pod)
|
||||
}
|
||||
s := &cache.StoreToPodLister{cache.NewStore(cache.MetaNamespaceKeyFunc)}
|
||||
for i := range item.scheduledPods {
|
||||
s.Store.Add(&item.scheduledPods[i])
|
||||
for _, pod := range item.scheduledPods {
|
||||
s.Store.Add(pod)
|
||||
}
|
||||
m := NewSimpleModeler(q, s)
|
||||
for i := range item.assumedPods {
|
||||
m.AssumePod(&item.assumedPods[i])
|
||||
for _, pod := range item.assumedPods {
|
||||
m.AssumePod(pod)
|
||||
}
|
||||
|
||||
list, err := m.PodLister().List(labels.Everything())
|
||||
@@ -98,14 +98,14 @@ func TestModeler(t *testing.T) {
|
||||
|
||||
found := 0
|
||||
for _, pod := range list {
|
||||
if item.expectPods.has(&pod) {
|
||||
if item.expectPods.has(pod) {
|
||||
found++
|
||||
} else {
|
||||
t.Errorf("found unexpected pod %#v", pod)
|
||||
}
|
||||
}
|
||||
if e, a := item.expectPods, found; len(e) != a {
|
||||
t.Errorf("Expected pods:\n%+v\nFound pods:\n%v\n", e, list)
|
||||
t.Errorf("Expected pods:\n%+v\nFound pods:\n%s\n", podNames(e.list()), podNames(list))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -112,7 +112,7 @@ func (s *Scheduler) scheduleOne() {
|
||||
defer func() {
|
||||
metrics.E2eSchedulingLatency.Observe(metrics.SinceInMicroseconds(start))
|
||||
}()
|
||||
dest, err := s.config.Algorithm.Schedule(*pod, s.config.MinionLister)
|
||||
dest, err := s.config.Algorithm.Schedule(pod, s.config.MinionLister)
|
||||
metrics.SchedulingAlgorithmLatency.Observe(metrics.SinceInMicroseconds(start))
|
||||
if err != nil {
|
||||
glog.V(1).Infof("Failed to schedule: %v", pod)
|
||||
|
@@ -59,7 +59,7 @@ type mockScheduler struct {
|
||||
err error
|
||||
}
|
||||
|
||||
func (es mockScheduler) Schedule(pod api.Pod, ml scheduler.MinionLister) (string, error) {
|
||||
func (es mockScheduler) Schedule(pod *api.Pod, ml scheduler.MinionLister) (string, error) {
|
||||
return es.machine, es.err
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user