Variables should be initialized near where it would be used

This commit is contained in:
Ke Zhang 2016-09-26 14:31:31 +08:00
parent b79c99da1b
commit d03a73f3f2

View File

@ -1935,7 +1935,6 @@ func (dm *DockerManager) computePodContainerChanges(pod *api.Pod, podStatus *kub
// check the status of the containers
for index, container := range pod.Spec.Containers {
expectedHash := kubecontainer.HashContainer(&container)
containerStatus := podStatus.FindContainerStatusByName(container.Name)
if containerStatus == nil || containerStatus.State != kubecontainer.ContainerStateRunning {
@ -1951,7 +1950,6 @@ func (dm *DockerManager) computePodContainerChanges(pod *api.Pod, podStatus *kub
}
containerID := kubecontainer.DockerID(containerStatus.ID.ID)
hash := containerStatus.Hash
glog.V(3).Infof("pod %q container %q exists as %v", format.Pod(pod), container.Name, containerID)
if createPodInfraContainer {
@ -1982,6 +1980,8 @@ func (dm *DockerManager) computePodContainerChanges(pod *api.Pod, podStatus *kub
// At this point, the container is running and pod infra container is good.
// We will look for changes and check healthiness for the container.
expectedHash := kubecontainer.HashContainer(&container)
hash := containerStatus.Hash
containerChanged := hash != 0 && hash != expectedHash
if containerChanged {
message := fmt.Sprintf("pod %q container %q hash changed (%d vs %d), it will be killed and re-created.", format.Pod(pod), container.Name, hash, expectedHash)