Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enqueue DaemonSet only it has new or updated nodes in it. Addressing #17441 #17442

Merged
merged 1 commit into from
Dec 1, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
30 changes: 26 additions & 4 deletions pkg/controller/daemon/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,19 @@ func (dsc *DaemonSetsController) deletePod(obj interface{}) {

func (dsc *DaemonSetsController) addNode(obj interface{}) {
// TODO: it'd be nice to pass a hint with these enqueues, so that each ds would only examine the added node (unless it has other work to do, too).
dsc.enqueueAllDaemonSets()
dsList, err := dsc.dsStore.List()
if err != nil {
glog.V(4).Infof("Error enqueueing daemon sets: %v", err)
return
}
node := obj.(*api.Node)
for i := range dsList.Items {
ds := &dsList.Items[i]
shouldEnqueue := nodeShouldRunDaemonPod(node, ds)
if shouldEnqueue {
dsc.enqueueDaemonSet(ds)
}
}
}

func (dsc *DaemonSetsController) updateNode(old, cur interface{}) {
Expand All @@ -317,8 +329,19 @@ func (dsc *DaemonSetsController) updateNode(old, cur interface{}) {
// A periodic relist will send update events for all known pods.
return
}
dsList, err := dsc.dsStore.List()
if err != nil {
glog.V(4).Infof("Error enqueueing daemon sets: %v", err)
return
}
for i := range dsList.Items {
ds := &dsList.Items[i]
shouldEnqueue := (nodeShouldRunDaemonPod(oldNode, ds) != nodeShouldRunDaemonPod(curNode, ds))
if shouldEnqueue {
dsc.enqueueDaemonSet(ds)
}
}
// TODO: it'd be nice to pass a hint with these enqueues, so that each ds would only examine the added node (unless it has other work to do, too).
dsc.enqueueAllDaemonSets()
}

// getNodesToDaemonSetPods returns a map from nodes to daemon pods (corresponding to ds) running on the nodes.
Expand Down Expand Up @@ -355,6 +378,7 @@ func (dsc *DaemonSetsController) manage(ds *extensions.DaemonSet) {
var nodesNeedingDaemonPods, podsToDelete []string
for _, node := range nodeList.Items {
shouldRun := nodeShouldRunDaemonPod(&node, ds)

daemonPods, isRunning := nodeToDaemonPods[node.Name]

if shouldRun && !isRunning {
Expand Down Expand Up @@ -513,7 +537,6 @@ func nodeShouldRunDaemonPod(node *api.Node, ds *extensions.DaemonSet) bool {
shouldRun := nodeSelector.Matches(labels.Set(node.Labels))
// If the daemon set specifies a node name, check that it matches with node.Name.
shouldRun = shouldRun && (ds.Spec.Template.Spec.NodeName == "" || ds.Spec.Template.Spec.NodeName == node.Name)

// If the node is not ready, don't run on it.
// TODO(mikedanese): remove this once daemonpods forgive nodes
shouldRun = shouldRun && api.IsNodeReady(node)
Expand All @@ -522,7 +545,6 @@ func nodeShouldRunDaemonPod(node *api.Node, ds *extensions.DaemonSet) bool {
// TODO(mikedanese): remove this once we have the right node admitance levels.
// See https://github.com/kubernetes/kubernetes/issues/17297#issuecomment-156857375.
shouldRun = shouldRun && !node.Spec.Unschedulable

return shouldRun
}

Expand Down