Skip to content

Commit

Permalink
move if statement into function
Browse files Browse the repository at this point in the history
Signed-off-by: Liu Zhenwei <zwliu@thoughtworks.com>
Signed-off-by: liuzhenwei <dui_zhang@163.com>
  • Loading branch information
diannaowa committed Mar 12, 2024
1 parent a36ff34 commit 121eb28
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions pkg/util/inplaceupdate/inplace_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,9 +221,7 @@ func (c *realControl) finishGracePeriod(pod *v1.Pod, opts *UpdateOptions) (time.
return err
}
// record restart count of the pod(containers)
if spec.ContainerImages != nil || spec.UpdateEnvFromMetadata {
recordPodAndContainersRestartCount(clone, &spec, updateState.Revision)
}
recordPodAndContainersRestartCount(clone, &spec, updateState.Revision)
appspub.RemoveInPlaceUpdateGrace(clone)
}
_, err = c.podAdapter.UpdatePod(clone)
Expand Down Expand Up @@ -262,9 +260,7 @@ func (c *realControl) updateNextBatch(pod *v1.Pod, opts *UpdateOptions) (bool, e
return err
}
// record restart count of the pod(containers)
if spec.ContainerImages != nil || spec.UpdateEnvFromMetadata {
recordPodAndContainersRestartCount(clone, &spec, state.Revision)
}
recordPodAndContainersRestartCount(clone, &spec, state.Revision)
updated = true
_, err = c.podAdapter.UpdatePod(clone)
return err
Expand Down Expand Up @@ -344,9 +340,7 @@ func (c *realControl) updatePodInPlace(pod *v1.Pod, spec *UpdateSpec, opts *Upda
return err
}
// record restart count of the pod(containers)
if spec.ContainerImages != nil || spec.UpdateEnvFromMetadata {
recordPodAndContainersRestartCount(clone, spec, inPlaceUpdateState.Revision)
}
recordPodAndContainersRestartCount(clone, spec, inPlaceUpdateState.Revision)
appspub.RemoveInPlaceUpdateGrace(clone)
} else {
inPlaceUpdateSpecJSON, _ := json.Marshal(spec)
Expand Down Expand Up @@ -430,6 +424,9 @@ func hasEqualCondition(pod *v1.Pod, newCondition *v1.PodCondition) bool {

// recordPodAndContainersRestartCount record the count of pod(containers) restarts
func recordPodAndContainersRestartCount(pod *v1.Pod, spec *UpdateSpec, revision string) {
if spec.ContainerImages == nil && !spec.UpdateEnvFromMetadata {
return
}
var currentPodRestartCount int64
containersRestartCount := make(map[string]appspub.InPlaceUpdateContainerRestartCount)
//revision := pod.GetLabels()["controller-revision-hash"]
Expand Down

0 comments on commit 121eb28

Please sign in to comment.