fixup: address comments

This commit is contained in:
Wei Huang 2019-07-22 10:33:50 -07:00
parent 2027525abf
commit fe7072a482
No known key found for this signature in database
GPG Key ID: BE5E9752F8B6E005
2 changed files with 13 additions and 13 deletions

View File

@ -382,9 +382,9 @@ func (m *topologyPairsMaps) clone() *topologyPairsMaps {
return copy return copy
} }
func (m *topologyPairsPodSpreadMap) addPod(addedPod, metapod *v1.Pod, node *v1.Node) error { func (m *topologyPairsPodSpreadMap) addPod(addedPod, preemptorPod *v1.Pod, node *v1.Node) error {
constraints := getHardTopologySpreadConstraints(metapod) constraints := getHardTopologySpreadConstraints(preemptorPod)
match, err := podMatchesAllSpreadConstraints(addedPod, metapod.Namespace, constraints) match, err := podMatchesAllSpreadConstraints(addedPod, preemptorPod.Namespace, constraints)
if err != nil { if err != nil {
return err return err
} }

View File

@ -1246,7 +1246,7 @@ func TestGetTPMapMatchingSpreadConstraints(t *testing.T) {
func TestPodSpreadMap_addPod(t *testing.T) { func TestPodSpreadMap_addPod(t *testing.T) {
tests := []struct { tests := []struct {
name string name string
metaPod *v1.Pod // also known as incoming/preemptor pod preemptorPod *v1.Pod
addedPod *v1.Pod addedPod *v1.Pod
existingPods []*v1.Pod existingPods []*v1.Pod
nodeIdx int // denotes which node 'addedPod' belongs to 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", 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()). SpreadConstraint(1, "node", hardSpread, st.MakeLabelSelector().Exists("foo").Obj()).
Obj(), Obj(),
addedPod: st.MakePod().Name("p-a1").Node("node-a").Label("foo", "").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", 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()). SpreadConstraint(1, "node", hardSpread, st.MakeLabelSelector().Exists("foo").Obj()).
Obj(), Obj(),
addedPod: st.MakePod().Name("p-a1").Node("node-a").Label("foo", "").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", 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()). SpreadConstraint(1, "node", hardSpread, st.MakeLabelSelector().Exists("foo").Obj()).
Obj(), Obj(),
addedPod: st.MakePod().Name("p-a1").Namespace("ns1").Node("node-a").Label("foo", "").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", 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()). SpreadConstraint(1, "node", hardSpread, st.MakeLabelSelector().Exists("foo").Obj()).
Obj(), Obj(),
addedPod: st.MakePod().Name("p-b2").Node("node-a").Label("foo", "").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", 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, "zone", hardSpread, st.MakeLabelSelector().Exists("foo").Obj()).
SpreadConstraint(1, "node", hardSpread, st.MakeLabelSelector().Exists("foo").Obj()). SpreadConstraint(1, "node", hardSpread, st.MakeLabelSelector().Exists("foo").Obj()).
Obj(), Obj(),
@ -1409,7 +1409,7 @@ func TestPodSpreadMap_addPod(t *testing.T) {
}, },
{ {
name: "only node a impacts topologyKeyToMinPodsMap on zone and node", 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, "zone", hardSpread, st.MakeLabelSelector().Exists("foo").Obj()).
SpreadConstraint(1, "node", hardSpread, st.MakeLabelSelector().Exists("foo").Obj()). SpreadConstraint(1, "node", hardSpread, st.MakeLabelSelector().Exists("foo").Obj()).
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", 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, "zone", hardSpread, st.MakeLabelSelector().Exists("foo").Obj()).
SpreadConstraint(1, "node", hardSpread, st.MakeLabelSelector().Exists("foo").Obj()). SpreadConstraint(1, "node", hardSpread, st.MakeLabelSelector().Exists("foo").Obj()).
Obj(), Obj(),
@ -1499,9 +1499,9 @@ func TestPodSpreadMap_addPod(t *testing.T) {
} }
nodeInfoMap := schedulernodeinfo.CreateNodeNameToInfoMap(tt.existingPods, tt.nodes) 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) { if !reflect.DeepEqual(podSpreadMap, tt.want) {
t.Errorf("podSpreadMap#addPod() = %v, want %v", podSpreadMap, tt.want) t.Errorf("podSpreadMap#addPod() = %v, want %v", podSpreadMap, tt.want)
} }