Merge pull request #111207 from lucming/code-cleanup2

Reduce indentation in daemonset controller code
This commit is contained in:
Kubernetes Prow Robot 2022-12-09 15:41:41 -08:00 committed by GitHub
commit 5fe12aae11
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1104,28 +1104,30 @@ func (dsc *DaemonSetsController) updateDaemonSetStatus(ctx context.Context, ds *
if shouldRun { if shouldRun {
desiredNumberScheduled++ desiredNumberScheduled++
if scheduled { if !scheduled {
currentNumberScheduled++ continue
// Sort the daemon pods by creation time, so that the oldest is first. }
daemonPods, _ := nodeToDaemonPods[node.Name]
sort.Sort(podByCreationTimestampAndPhase(daemonPods)) currentNumberScheduled++
pod := daemonPods[0] // Sort the daemon pods by creation time, so that the oldest is first.
if podutil.IsPodReady(pod) { daemonPods, _ := nodeToDaemonPods[node.Name]
numberReady++ sort.Sort(podByCreationTimestampAndPhase(daemonPods))
if podutil.IsPodAvailable(pod, ds.Spec.MinReadySeconds, metav1.Time{Time: now}) { pod := daemonPods[0]
numberAvailable++ if podutil.IsPodReady(pod) {
} numberReady++
} if podutil.IsPodAvailable(pod, ds.Spec.MinReadySeconds, metav1.Time{Time: now}) {
// If the returned error is not nil we have a parse error. numberAvailable++
// The controller handles this via the hash.
generation, err := util.GetTemplateGeneration(ds)
if err != nil {
generation = nil
}
if util.IsPodUpdated(pod, hash, generation) {
updatedNumberScheduled++
} }
} }
// If the returned error is not nil we have a parse error.
// The controller handles this via the hash.
generation, err := util.GetTemplateGeneration(ds)
if err != nil {
generation = nil
}
if util.IsPodUpdated(pod, hash, generation) {
updatedNumberScheduled++
}
} else { } else {
if scheduled { if scheduled {
numberMisscheduled++ numberMisscheduled++
@ -1325,14 +1327,17 @@ func getUnscheduledPodsWithoutNode(runningNodesList []*v1.Node, nodeToDaemonPods
for _, node := range runningNodesList { for _, node := range runningNodesList {
isNodeRunning[node.Name] = true isNodeRunning[node.Name] = true
} }
for n, pods := range nodeToDaemonPods { for n, pods := range nodeToDaemonPods {
if !isNodeRunning[n] { if isNodeRunning[n] {
for _, pod := range pods { continue
if len(pod.Spec.NodeName) == 0 { }
results = append(results, pod.Name) for _, pod := range pods {
} if len(pod.Spec.NodeName) == 0 {
results = append(results, pod.Name)
} }
} }
} }
return results return results
} }