mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 11:50:44 +00:00
Merge pull request #29526 from vishh/logfilelen
Automatic merge from submit-queue Restrict log sym link to 256 characters This fix can potentially cause conflicts in log file names. The current model of exporting log data is fundamentally broken. This PR does not attempt to fix all of the issues.
This commit is contained in:
commit
61524b9e15
@ -45,6 +45,7 @@ const (
|
||||
PodInfraContainerName = leaky.PodInfraContainerName
|
||||
DockerPrefix = "docker://"
|
||||
LogSuffix = "log"
|
||||
ext4MaxFileNameLen = 255
|
||||
)
|
||||
|
||||
const (
|
||||
@ -300,7 +301,13 @@ func ParseDockerName(name string) (dockerName *KubeletContainerName, hash uint64
|
||||
}
|
||||
|
||||
func LogSymlink(containerLogsDir, podFullName, containerName, dockerId string) string {
|
||||
return path.Join(containerLogsDir, fmt.Sprintf("%s_%s-%s.%s", podFullName, containerName, dockerId, LogSuffix))
|
||||
suffix := fmt.Sprintf(".%s", LogSuffix)
|
||||
logPath := fmt.Sprintf("%s_%s-%s", podFullName, containerName, dockerId)
|
||||
// Length of a filename cannot exceed 255 characters in ext4 on Linux.
|
||||
if len(logPath) > ext4MaxFileNameLen-len(suffix) {
|
||||
logPath = logPath[:ext4MaxFileNameLen-len(suffix)]
|
||||
}
|
||||
return path.Join(containerLogsDir, logPath+suffix)
|
||||
}
|
||||
|
||||
// Get a *dockerapi.Client, either using the endpoint passed in, or using
|
||||
|
@ -20,6 +20,8 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"hash/adler32"
|
||||
"math/rand"
|
||||
"path"
|
||||
"reflect"
|
||||
"sort"
|
||||
"strconv"
|
||||
@ -801,3 +803,24 @@ func TestMilliCPUToQuota(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const letterBytes = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||
|
||||
func randStringBytes(n int) string {
|
||||
b := make([]byte, n)
|
||||
for i := range b {
|
||||
b[i] = letterBytes[rand.Intn(len(letterBytes))]
|
||||
}
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func TestLogSymLink(t *testing.T) {
|
||||
as := assert.New(t)
|
||||
containerLogsDir := "/foo/bar"
|
||||
podFullName := randStringBytes(128)
|
||||
containerName := randStringBytes(70)
|
||||
dockerId := randStringBytes(80)
|
||||
// The file name cannot exceed 255 characters. Since .log suffix is required, the prefix cannot exceed 251 characters.
|
||||
expectedPath := path.Join(containerLogsDir, fmt.Sprintf("%s_%s-%s", podFullName, containerName, dockerId)[:251]+".log")
|
||||
as.Equal(expectedPath, LogSymlink(containerLogsDir, podFullName, containerName, dockerId))
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user