legacy.go 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /*
  2. Copyright 2016 The Kubernetes Authors.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package kuberuntime
  14. import (
  15. "fmt"
  16. "path"
  17. kubecontainer "k8s.io/kubernetes/pkg/kubelet/container"
  18. )
  19. // This file implements the functions that are needed for backward
  20. // compatibility. Therefore, it imports various kubernetes packages
  21. // directly.
  22. const (
  23. // legacyContainerLogsDir is the legacy location of container logs. It is the same with
  24. // kubelet.containerLogsDir.
  25. legacyContainerLogsDir = "/var/log/containers"
  26. // legacyLogSuffix is the legacy log suffix.
  27. legacyLogSuffix = "log"
  28. ext4MaxFileNameLen = 255
  29. )
  30. // legacyLogSymlink composes the legacy container log path. It is only used for legacy cluster
  31. // logging support.
  32. func legacyLogSymlink(containerID string, containerName, podName, podNamespace string) string {
  33. return logSymlink(legacyContainerLogsDir, kubecontainer.BuildPodFullName(podName, podNamespace),
  34. containerName, containerID)
  35. }
  36. func logSymlink(containerLogsDir, podFullName, containerName, dockerID string) string {
  37. suffix := fmt.Sprintf(".%s", legacyLogSuffix)
  38. logPath := fmt.Sprintf("%s_%s-%s", podFullName, containerName, dockerID)
  39. // Length of a filename cannot exceed 255 characters in ext4 on Linux.
  40. if len(logPath) > ext4MaxFileNameLen-len(suffix) {
  41. logPath = logPath[:ext4MaxFileNameLen-len(suffix)]
  42. }
  43. return path.Join(containerLogsDir, logPath+suffix)
  44. }