Merge pull request #97715 from changshuchao/files_tmptag

Made some optimizations, including modifying variable names, omitting…
This commit is contained in:
Kubernetes Prow Robot 2021-01-21 22:55:26 -08:00 committed by GitHub
commit cea1098997
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 6 additions and 6 deletions

View File

@ -26,7 +26,7 @@ import (
const ( const (
defaultPerm = 0755 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 // 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. // Expects the parent directory to exist.
func WriteTmpFile(fs utilfs.Filesystem, path string, data []byte) (tmpPath string, retErr error) { func WriteTmpFile(fs utilfs.Filesystem, path string, data []byte) (tmpPath string, retErr error) {
dir := filepath.Dir(path) dir := filepath.Dir(path)
prefix := tmptag + filepath.Base(path) prefix := tmpTag + filepath.Base(path)
// create the tmp file // create the tmp file
tmpFile, err := fs.TempFile(dir, prefix) 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 // write the temp directory in parent dir and return path to the tmp directory
dir := filepath.Dir(path) dir := filepath.Dir(path)
prefix := tmptag + filepath.Base(path) prefix := tmpTag + filepath.Base(path)
// create the tmp dir // create the tmp dir
var err error var err error

View File

@ -884,8 +884,8 @@ func (m *kubeGenericRuntimeManager) doBackOff(pod *v1.Pod, container *v1.Contain
// backOff requires a unique key to identify the container. // backOff requires a unique key to identify the container.
key := getStableKey(pod, container) key := getStableKey(pod, container)
if backOff.IsInBackOffSince(key, ts) { if backOff.IsInBackOffSince(key, ts) {
if ref, err := kubecontainer.GenerateContainerRef(pod, container); err == nil { if containerRef, err := kubecontainer.GenerateContainerRef(pod, container); err == nil {
m.recorder.Eventf(ref, v1.EventTypeWarning, events.BackOffStartContainer, "Back-off restarting failed container") 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)) 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()) klog.V(3).Infof("%s", err.Error())

View File

@ -155,7 +155,7 @@ func parseCRILog(log []byte, msg *logMessage) error {
} }
// Keep this forward compatible. // Keep this forward compatible.
tags := bytes.Split(log[:idx], tagDelimiter) 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. // Trim the tailing new line if this is a partial line.
if partial && len(log) > 0 && log[len(log)-1] == '\n' { if partial && len(log) > 0 && log[len(log)-1] == '\n' {
log = log[:len(log)-1] log = log[:len(log)-1]