From fe7072a48262e9b20b5aeaeb098bc0b1f2b2aabd Mon Sep 17 00:00:00 2001 From: Wei Huang Date: Mon, 22 Jul 2019 10:33:50 -0700 Subject: [PATCH] fixup: address comments --- .../algorithm/predicates/metadata.go | 6 +++--- .../algorithm/predicates/metadata_test.go | 20 +++++++++---------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/pkg/scheduler/algorithm/predicates/metadata.go b/pkg/scheduler/algorithm/predicates/metadata.go index 620399399ec..20225e389bd 100644 --- a/pkg/scheduler/algorithm/predicates/metadata.go +++ b/pkg/scheduler/algorithm/predicates/metadata.go @@ -382,9 +382,9 @@ func (m *topologyPairsMaps) clone() *topologyPairsMaps { return copy } -func (m *topologyPairsPodSpreadMap) addPod(addedPod, metapod *v1.Pod, node *v1.Node) error { - constraints := getHardTopologySpreadConstraints(metapod) - match, err := podMatchesAllSpreadConstraints(addedPod, metapod.Namespace, constraints) +func (m *topologyPairsPodSpreadMap) addPod(addedPod, preemptorPod *v1.Pod, node *v1.Node) error { + constraints := getHardTopologySpreadConstraints(preemptorPod) + match, err := podMatchesAllSpreadConstraints(addedPod, preemptorPod.Namespace, constraints) if err != nil { return err } diff --git a/pkg/scheduler/algorithm/predicates/metadata_test.go b/pkg/scheduler/algorithm/predicates/metadata_test.go index 494af85ee33..d60073f4fd6 100644 --- a/pkg/scheduler/algorithm/predicates/metadata_test.go +++ b/pkg/scheduler/algorithm/predicates/metadata_test.go @@ -1246,7 +1246,7 @@ func TestGetTPMapMatchingSpreadConstraints(t *testing.T) { func TestPodSpreadMap_addPod(t *testing.T) { tests := []struct { name string - metaPod *v1.Pod // also known as incoming/preemptor pod + preemptorPod *v1.Pod addedPod *v1.Pod existingPods []*v1.Pod nodeIdx int // denotes which node 'addedPod' belongs to @@ -1257,7 +1257,7 @@ func TestPodSpreadMap_addPod(t *testing.T) { }{ { name: "node a and b both impact current min match", - metaPod: st.MakePod().Name("p").Label("foo", ""). + preemptorPod: st.MakePod().Name("p").Label("foo", ""). SpreadConstraint(1, "node", hardSpread, st.MakeLabelSelector().Exists("foo").Obj()). Obj(), addedPod: st.MakePod().Name("p-a1").Node("node-a").Label("foo", "").Obj(), @@ -1287,7 +1287,7 @@ func TestPodSpreadMap_addPod(t *testing.T) { }, { name: "only node a impacts current min match", - metaPod: st.MakePod().Name("p").Label("foo", ""). + preemptorPod: st.MakePod().Name("p").Label("foo", ""). SpreadConstraint(1, "node", hardSpread, st.MakeLabelSelector().Exists("foo").Obj()). Obj(), addedPod: st.MakePod().Name("p-a1").Node("node-a").Label("foo", "").Obj(), @@ -1318,7 +1318,7 @@ func TestPodSpreadMap_addPod(t *testing.T) { }, { name: "add a pod with mis-matched namespace doesn't change topologyKeyToMinPodsMap", - metaPod: st.MakePod().Name("p").Label("foo", ""). + preemptorPod: st.MakePod().Name("p").Label("foo", ""). SpreadConstraint(1, "node", hardSpread, st.MakeLabelSelector().Exists("foo").Obj()). Obj(), addedPod: st.MakePod().Name("p-a1").Namespace("ns1").Node("node-a").Label("foo", "").Obj(), @@ -1348,7 +1348,7 @@ func TestPodSpreadMap_addPod(t *testing.T) { }, { name: "add pod on non-critical node won't trigger re-calculation", - metaPod: st.MakePod().Name("p").Label("foo", ""). + preemptorPod: st.MakePod().Name("p").Label("foo", ""). SpreadConstraint(1, "node", hardSpread, st.MakeLabelSelector().Exists("foo").Obj()). Obj(), addedPod: st.MakePod().Name("p-b2").Node("node-a").Label("foo", "").Obj(), @@ -1379,7 +1379,7 @@ func TestPodSpreadMap_addPod(t *testing.T) { }, { name: "node a and b both impact topologyKeyToMinPodsMap on zone and node", - metaPod: st.MakePod().Name("p").Label("foo", ""). + preemptorPod: st.MakePod().Name("p").Label("foo", ""). SpreadConstraint(1, "zone", hardSpread, st.MakeLabelSelector().Exists("foo").Obj()). SpreadConstraint(1, "node", hardSpread, st.MakeLabelSelector().Exists("foo").Obj()). Obj(), @@ -1409,7 +1409,7 @@ func TestPodSpreadMap_addPod(t *testing.T) { }, { name: "only node a impacts topologyKeyToMinPodsMap on zone and node", - metaPod: st.MakePod().Name("p").Label("foo", ""). + preemptorPod: st.MakePod().Name("p").Label("foo", ""). SpreadConstraint(1, "zone", hardSpread, st.MakeLabelSelector().Exists("foo").Obj()). SpreadConstraint(1, "node", hardSpread, st.MakeLabelSelector().Exists("foo").Obj()). Obj(), @@ -1442,7 +1442,7 @@ func TestPodSpreadMap_addPod(t *testing.T) { }, { name: "node a impacts topologyKeyToMinPodsMap on node, node x impacts topologyKeyToMinPodsMap on zone", - metaPod: st.MakePod().Name("p").Label("foo", ""). + preemptorPod: st.MakePod().Name("p").Label("foo", ""). SpreadConstraint(1, "zone", hardSpread, st.MakeLabelSelector().Exists("foo").Obj()). SpreadConstraint(1, "node", hardSpread, st.MakeLabelSelector().Exists("foo").Obj()). Obj(), @@ -1499,9 +1499,9 @@ func TestPodSpreadMap_addPod(t *testing.T) { } nodeInfoMap := schedulernodeinfo.CreateNodeNameToInfoMap(tt.existingPods, tt.nodes) - podSpreadMap, _ := getTPMapMatchingSpreadConstraints(tt.metaPod, nodeInfoMap) + podSpreadMap, _ := getTPMapMatchingSpreadConstraints(tt.preemptorPod, nodeInfoMap) - podSpreadMap.addPod(tt.addedPod, tt.metaPod, tt.nodes[tt.nodeIdx]) + podSpreadMap.addPod(tt.addedPod, tt.preemptorPod, tt.nodes[tt.nodeIdx]) if !reflect.DeepEqual(podSpreadMap, tt.want) { t.Errorf("podSpreadMap#addPod() = %v, want %v", podSpreadMap, tt.want) }