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

daemon/controller.go: fix bugs in updateDaemonSetStatus #26931

Merged
merged 1 commit into from
Jul 9, 2016
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: 16 additions & 14 deletions pkg/controller/daemon/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -567,21 +567,22 @@ func (dsc *DaemonSetsController) manage(ds *extensions.DaemonSet) {
}

func storeDaemonSetStatus(dsClient unversionedextensions.DaemonSetInterface, ds *extensions.DaemonSet, desiredNumberScheduled, currentNumberScheduled, numberMisscheduled int) error {
if int(ds.Status.DesiredNumberScheduled) == desiredNumberScheduled && int(ds.Status.CurrentNumberScheduled) == currentNumberScheduled && int(ds.Status.NumberMisscheduled) == numberMisscheduled {
if int(ds.Status.DesiredNumberScheduled) == desiredNumberScheduled &&
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't it simpler to have a helper that will construct the desired status and do a DeepEqual instead of comparing every field?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i do not feel so. if there are only three explicit fields, direct comparison is simpler and faster.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am fine with what is here and not requiring DeepEqual since that would require reflection.

int(ds.Status.CurrentNumberScheduled) == currentNumberScheduled &&
int(ds.Status.NumberMisscheduled) == numberMisscheduled {
return nil
}

var updateErr, getErr error
for i := 0; i <= StatusUpdateRetries; i++ {
for i := 0; i < StatusUpdateRetries; i++ {
ds.Status.DesiredNumberScheduled = int32(desiredNumberScheduled)
ds.Status.CurrentNumberScheduled = int32(currentNumberScheduled)
ds.Status.NumberMisscheduled = int32(numberMisscheduled)

_, updateErr = dsClient.UpdateStatus(ds)
if updateErr == nil {
// successful update
if _, updateErr = dsClient.UpdateStatus(ds); updateErr == nil {
return nil
}

// Update the set with the latest resource version for the next poll
if ds, getErr = dsClient.Get(ds.Name); getErr != nil {
// If the GET fails we can't trust status.Replicas anymore. This error
Expand All @@ -597,29 +598,30 @@ func (dsc *DaemonSetsController) updateDaemonSetStatus(ds *extensions.DaemonSet)
nodeToDaemonPods, err := dsc.getNodesToDaemonPods(ds)
if err != nil {
glog.Errorf("Error getting node to daemon pod mapping for daemon set %+v: %v", ds, err)
return
}

nodeList, err := dsc.nodeStore.List()
if err != nil {
glog.Errorf("Couldn't get list of nodes when updating daemon set %+v: %v", ds, err)
return
}

var desiredNumberScheduled, currentNumberScheduled, numberMisscheduled int
for _, node := range nodeList.Items {
shouldRun := dsc.nodeShouldRunDaemonPod(&node, ds)

numDaemonPods := len(nodeToDaemonPods[node.Name])

if shouldRun && numDaemonPods > 0 {
currentNumberScheduled++
}
scheduled := len(nodeToDaemonPods[node.Name]) > 0

if shouldRun {
desiredNumberScheduled++
}

if !shouldRun && numDaemonPods > 0 {
numberMisscheduled++
if scheduled {
currentNumberScheduled++
}
} else {
if scheduled {
numberMisscheduled++
}
}
}

Expand Down