From b40e575076c3350ff8f2aae739f7b26ee95ac9e2 Mon Sep 17 00:00:00 2001 From: NickrenREN Date: Mon, 9 Jan 2017 20:28:37 +0800 Subject: [PATCH] optimize killPod() and syncPod() functions make sure that one of the two arguments must be non-nil: runningPod, status ,just like the function note says and judge the return value in syncPod() function before setting podKilled --- pkg/kubelet/kubelet.go | 5 +++-- pkg/kubelet/kubelet_pods.go | 2 ++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/pkg/kubelet/kubelet.go b/pkg/kubelet/kubelet.go index 5059613b708..df847e99f95 100644 --- a/pkg/kubelet/kubelet.go +++ b/pkg/kubelet/kubelet.go @@ -1463,8 +1463,9 @@ func (kl *Kubelet) syncPod(o syncPodOptions) error { // exists or the pod is running for the first time podKilled := false if !pcm.Exists(pod) && !firstSync { - kl.killPod(pod, nil, podStatus, nil) - podKilled = true + if err := kl.killPod(pod, nil, podStatus, nil); err == nil { + podKilled = true + } } // Create and Update pod's Cgroups // Don't create cgroups for run once pod if it was killed above diff --git a/pkg/kubelet/kubelet_pods.go b/pkg/kubelet/kubelet_pods.go index 556d7a47e94..bf74e410594 100644 --- a/pkg/kubelet/kubelet_pods.go +++ b/pkg/kubelet/kubelet_pods.go @@ -645,6 +645,8 @@ func (kl *Kubelet) killPod(pod *v1.Pod, runningPod *kubecontainer.Pod, status *k p = *runningPod } else if status != nil { p = kubecontainer.ConvertPodStatusToRunningPod(kl.GetRuntime().Type(), status) + } else { + return fmt.Errorf("one of the two arguments must be non-nil: runningPod, status") } // cache the pod cgroup Name for reducing the cpu resource limits of the pod cgroup once the pod is killed