From d03a73f3f280c91fb1fa826d9bbaba5688298459 Mon Sep 17 00:00:00 2001 From: Ke Zhang Date: Mon, 26 Sep 2016 14:31:31 +0800 Subject: [PATCH] Variables should be initialized near where it would be used --- pkg/kubelet/dockertools/docker_manager.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/kubelet/dockertools/docker_manager.go b/pkg/kubelet/dockertools/docker_manager.go index 5fdf05ca2a..ce098d5482 100644 --- a/pkg/kubelet/dockertools/docker_manager.go +++ b/pkg/kubelet/dockertools/docker_manager.go @@ -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)