add test and fix typo in daemoncontroller

This commit is contained in:
zhengjiajin
2017-05-24 21:59:45 +08:00
parent 58167fcfa1
commit 5468773b83
2 changed files with 25 additions and 2 deletions

View File

@@ -814,7 +814,7 @@ func (dsc *DaemonSetsController) syncDaemonSet(key string) error {
// summary. Returned booleans are:
// * wantToRun:
// Returns true when a user would expect a pod to run on this node and ignores conditions
// such as OutOfDisk or insufficent resource that would cause a daemonset pod not to schedule.
// such as OutOfDisk or insufficient resource that would cause a daemonset pod not to schedule.
// This is primarily used to populate daemonset status.
// * shouldSchedule:
// Returns true when a daemonset should be scheduled to a node if a daemonset pod is not already

View File

@@ -455,7 +455,7 @@ func TestInsufficientCapacityNodeDaemonDoesNotLaunchPod(t *testing.T) {
}
// DaemonSets should not unschedule a daemonset pod from a node with insufficient free resource
func TestInsufficentCapacityNodeDaemonDoesNotUnscheduleRunningPod(t *testing.T) {
func TestInsufficientCapacityNodeDaemonDoesNotUnscheduleRunningPod(t *testing.T) {
podSpec := resourcePodSpec("too-much-mem", "75M", "75m")
podSpec.NodeName = "too-much-mem"
ds := newDaemonSet("foo")
@@ -1302,6 +1302,29 @@ func TestGetNodesToDaemonPods(t *testing.T) {
}
}
func TestAddNode(t *testing.T) {
manager, _, _ := newTestController()
node1 := newNode("node1", nil)
ds := newDaemonSet("ds")
ds.Spec.Template.Spec.NodeSelector = simpleNodeLabel
manager.dsStore.Add(ds)
manager.addNode(node1)
if got, want := manager.queue.Len(), 0; got != want {
t.Fatalf("queue.Len() = %v, want %v", got, want)
}
node2 := newNode("node2", simpleNodeLabel)
manager.addNode(node2)
if got, want := manager.queue.Len(), 1; got != want {
t.Fatalf("queue.Len() = %v, want %v", got, want)
}
key, done := manager.queue.Get()
if key == nil || done {
t.Fatalf("failed to enqueue controller for node %v", node2.Name)
}
}
func TestAddPod(t *testing.T) {
manager, _, _ := newTestController()
ds1 := newDaemonSet("foo1")