From 42eb85e4fb2afcd331df3d51151d68ad398bdeed Mon Sep 17 00:00:00 2001 From: changshuchao Date: Wed, 25 Nov 2020 19:06:45 +0800 Subject: [PATCH] Made some optimizations, including modifying variable names, omitting unnecessary parentheses, and conflicting variable names and package names. Signed-off-by: changshuchao --- pkg/kubelet/kubeletconfig/util/files/files.go | 6 +++--- pkg/kubelet/kuberuntime/kuberuntime_manager.go | 4 ++-- pkg/kubelet/kuberuntime/logs/logs.go | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/pkg/kubelet/kubeletconfig/util/files/files.go b/pkg/kubelet/kubeletconfig/util/files/files.go index fc42151a729..6dfbe3840cd 100644 --- a/pkg/kubelet/kubeletconfig/util/files/files.go +++ b/pkg/kubelet/kubeletconfig/util/files/files.go @@ -26,7 +26,7 @@ import ( const ( defaultPerm = 0755 - tmptag = "tmp_" // additional prefix to prevent accidental collisions + tmpTag = "tmp_" // additional prefix to prevent accidental collisions ) // FileExists returns true if a regular file exists at `path`, false if `path` does not exist, otherwise an error @@ -70,7 +70,7 @@ func EnsureFile(fs utilfs.Filesystem, path string) error { // Expects the parent directory to exist. func WriteTmpFile(fs utilfs.Filesystem, path string, data []byte) (tmpPath string, retErr error) { dir := filepath.Dir(path) - prefix := tmptag + filepath.Base(path) + prefix := tmpTag + filepath.Base(path) // create the tmp file tmpFile, err := fs.TempFile(dir, prefix) @@ -174,7 +174,7 @@ func WriteTempDir(fs utilfs.Filesystem, path string, files map[string]string) (t // write the temp directory in parent dir and return path to the tmp directory dir := filepath.Dir(path) - prefix := tmptag + filepath.Base(path) + prefix := tmpTag + filepath.Base(path) // create the tmp dir var err error diff --git a/pkg/kubelet/kuberuntime/kuberuntime_manager.go b/pkg/kubelet/kuberuntime/kuberuntime_manager.go index 7bc8e7799e6..6cd9faa9b99 100644 --- a/pkg/kubelet/kuberuntime/kuberuntime_manager.go +++ b/pkg/kubelet/kuberuntime/kuberuntime_manager.go @@ -884,8 +884,8 @@ func (m *kubeGenericRuntimeManager) doBackOff(pod *v1.Pod, container *v1.Contain // backOff requires a unique key to identify the container. key := getStableKey(pod, container) if backOff.IsInBackOffSince(key, ts) { - if ref, err := kubecontainer.GenerateContainerRef(pod, container); err == nil { - m.recorder.Eventf(ref, v1.EventTypeWarning, events.BackOffStartContainer, "Back-off restarting failed container") + if containerRef, err := kubecontainer.GenerateContainerRef(pod, container); err == nil { + m.recorder.Eventf(containerRef, v1.EventTypeWarning, events.BackOffStartContainer, "Back-off restarting failed container") } err := fmt.Errorf("back-off %s restarting failed container=%s pod=%s", backOff.Get(key), container.Name, format.Pod(pod)) klog.V(3).Infof("%s", err.Error()) diff --git a/pkg/kubelet/kuberuntime/logs/logs.go b/pkg/kubelet/kuberuntime/logs/logs.go index 97b39f39416..63413bdc69e 100644 --- a/pkg/kubelet/kuberuntime/logs/logs.go +++ b/pkg/kubelet/kuberuntime/logs/logs.go @@ -155,7 +155,7 @@ func parseCRILog(log []byte, msg *logMessage) error { } // Keep this forward compatible. tags := bytes.Split(log[:idx], tagDelimiter) - partial := (runtimeapi.LogTag(tags[0]) == runtimeapi.LogTagPartial) + partial := runtimeapi.LogTag(tags[0]) == runtimeapi.LogTagPartial // Trim the tailing new line if this is a partial line. if partial && len(log) > 0 && log[len(log)-1] == '\n' { log = log[:len(log)-1]