blob: 5c164ca9871331e9d973c50a6b1d321f5c02b488 [file] [log] [blame]
Lorenz Brun732a8842024-08-26 23:25:37 +02001From 4d98a0637eee66923b854ef75653f74aeb37240b Mon Sep 17 00:00:00 2001
Lorenz Brund13c1c62022-03-30 19:58:58 +02002From: Lorenz Brun <lorenz@monogon.tech>
3Date: Wed, 16 Mar 2022 18:10:09 +0100
Lorenz Brun6211e4d2023-11-14 19:09:40 +01004Subject: [PATCH] Drop legacy log path
Lorenz Brun7b822272021-02-03 17:03:41 +01005
6---
Lorenz Brunf2b7ab62022-05-04 19:06:00 +02007 pkg/kubelet/kubelet.go | 7 ---
8 .../kuberuntime/kuberuntime_container.go | 36 ---------------
9 pkg/kubelet/kuberuntime/kuberuntime_gc.go | 46 -------------------
Lorenz Brun7b822272021-02-03 17:03:41 +010010 pkg/kubelet/runonce.go | 8 ----
Lorenz Brunf2b7ab62022-05-04 19:06:00 +020011 test/e2e_node/log_path_test.go | 18 --------
12 5 files changed, 115 deletions(-)
Lorenz Brun7b822272021-02-03 17:03:41 +010013
14diff --git a/pkg/kubelet/kubelet.go b/pkg/kubelet/kubelet.go
Lorenz Brun732a8842024-08-26 23:25:37 +020015index 5d848de88fb..0495eaed7d1 100644
Lorenz Brun7b822272021-02-03 17:03:41 +010016--- a/pkg/kubelet/kubelet.go
17+++ b/pkg/kubelet/kubelet.go
Lorenz Brun732a8842024-08-26 23:25:37 +020018@@ -1506,13 +1506,6 @@ func (kl *Kubelet) initializeModules() error {
Lorenz Brun7b822272021-02-03 17:03:41 +010019 return err
20 }
Lorenz Brun732a8842024-08-26 23:25:37 +020021
Lorenz Brun7b822272021-02-03 17:03:41 +010022- // If the container logs directory does not exist, create it.
23- if _, err := os.Stat(ContainerLogsDir); err != nil {
24- if err := kl.os.MkdirAll(ContainerLogsDir, 0755); err != nil {
25- return fmt.Errorf("failed to create directory %q: %v", ContainerLogsDir, err)
26- }
27- }
28-
Lorenz Brun732a8842024-08-26 23:25:37 +020029 if sysruntime.GOOS == "windows" {
30 // On Windows we should not allow other users to read the logs directory
31 // to avoid allowing non-root containers from reading the logs of other containers.
Lorenz Brun7b822272021-02-03 17:03:41 +010032diff --git a/pkg/kubelet/kuberuntime/kuberuntime_container.go b/pkg/kubelet/kuberuntime/kuberuntime_container.go
Lorenz Brun732a8842024-08-26 23:25:37 +020033index b049540d0d3..7b1baa29c14 100644
Lorenz Brun7b822272021-02-03 17:03:41 +010034--- a/pkg/kubelet/kuberuntime/kuberuntime_container.go
35+++ b/pkg/kubelet/kuberuntime/kuberuntime_container.go
Lorenz Brun732a8842024-08-26 23:25:37 +020036@@ -285,25 +285,6 @@ func (m *kubeGenericRuntimeManager) startContainer(ctx context.Context, podSandb
Lorenz Brun7b822272021-02-03 17:03:41 +010037 }
38 m.recordContainerEvent(pod, container, containerID, v1.EventTypeNormal, events.StartedContainer, fmt.Sprintf("Started container %s", container.Name))
Lorenz Brun732a8842024-08-26 23:25:37 +020039
Lorenz Brun7b822272021-02-03 17:03:41 +010040- // Symlink container logs to the legacy container log location for cluster logging
41- // support.
42- // TODO(random-liu): Remove this after cluster logging supports CRI container log path.
43- containerMeta := containerConfig.GetMetadata()
44- sandboxMeta := podSandboxConfig.GetMetadata()
45- legacySymlink := legacyLogSymlink(containerID, containerMeta.Name, sandboxMeta.Name,
46- sandboxMeta.Namespace)
47- containerLog := filepath.Join(podSandboxConfig.LogDirectory, containerConfig.LogPath)
48- // only create legacy symlink if containerLog path exists (or the error is not IsNotExist).
49- // Because if containerLog path does not exist, only dangling legacySymlink is created.
50- // This dangling legacySymlink is later removed by container gc, so it does not make sense
51- // to create it in the first place. it happens when journald logging driver is used with docker.
52- if _, err := m.osInterface.Stat(containerLog); !os.IsNotExist(err) {
53- if err := m.osInterface.Symlink(containerLog, legacySymlink); err != nil {
Lorenz Brund13c1c62022-03-30 19:58:58 +020054- klog.ErrorS(err, "Failed to create legacy symbolic link", "path", legacySymlink,
55- "containerID", containerID, "containerLogPath", containerLog)
Lorenz Brun7b822272021-02-03 17:03:41 +010056- }
57- }
58-
59 // Step 4: execute the post start hook.
60 if container.Lifecycle != nil && container.Lifecycle.PostStart != nil {
61 kubeContainerID := kubecontainer.ContainerID{
Lorenz Brun732a8842024-08-26 23:25:37 +020062@@ -1317,23 +1298,6 @@ func (m *kubeGenericRuntimeManager) removeContainerLog(ctx context.Context, cont
Lorenz Brun7b822272021-02-03 17:03:41 +010063 return err
64 }
Lorenz Brun732a8842024-08-26 23:25:37 +020065
Lorenz Brun6211e4d2023-11-14 19:09:40 +010066- resp, err := m.runtimeService.ContainerStatus(ctx, containerID, false)
Lorenz Brun7b822272021-02-03 17:03:41 +010067- if err != nil {
68- return fmt.Errorf("failed to get container status %q: %v", containerID, err)
69- }
Lorenz Brunf2b7ab62022-05-04 19:06:00 +020070- status := resp.GetStatus()
71- if status == nil {
72- return remote.ErrContainerStatusNil
73- }
Lorenz Brun7b822272021-02-03 17:03:41 +010074- // Remove the legacy container log symlink.
75- // TODO(random-liu): Remove this after cluster logging supports CRI container log path.
76- labeledInfo := getContainerInfoFromLabels(status.Labels)
77- legacySymlink := legacyLogSymlink(containerID, labeledInfo.ContainerName, labeledInfo.PodName,
78- labeledInfo.PodNamespace)
79- if err := m.osInterface.Remove(legacySymlink); err != nil && !os.IsNotExist(err) {
80- return fmt.Errorf("failed to remove container %q log legacy symbolic link %q: %v",
81- containerID, legacySymlink, err)
82- }
83 return nil
84 }
Lorenz Brun732a8842024-08-26 23:25:37 +020085
Lorenz Brun7b822272021-02-03 17:03:41 +010086diff --git a/pkg/kubelet/kuberuntime/kuberuntime_gc.go b/pkg/kubelet/kuberuntime/kuberuntime_gc.go
Lorenz Brun732a8842024-08-26 23:25:37 +020087index 6189b1f07ca..3cd3daa5a6c 100644
Lorenz Brun7b822272021-02-03 17:03:41 +010088--- a/pkg/kubelet/kuberuntime/kuberuntime_gc.go
89+++ b/pkg/kubelet/kuberuntime/kuberuntime_gc.go
Lorenz Brun6211e4d2023-11-14 19:09:40 +010090@@ -19,7 +19,6 @@ package kuberuntime
Lorenz Brun7b822272021-02-03 17:03:41 +010091 import (
Lorenz Brun6211e4d2023-11-14 19:09:40 +010092 "context"
Lorenz Brun7b822272021-02-03 17:03:41 +010093 "fmt"
94- "os"
95 "path/filepath"
96 "sort"
97 "time"
Lorenz Brun732a8842024-08-26 23:25:37 +020098@@ -347,51 +346,6 @@ func (cgc *containerGC) evictPodLogsDirectories(ctx context.Context, allSourcesR
Lorenz Brun7b822272021-02-03 17:03:41 +010099 }
100 }
101 }
102-
103- // Remove dead container log symlinks.
104- // TODO(random-liu): Remove this after cluster logging supports CRI container log path.
105- logSymlinks, _ := osInterface.Glob(filepath.Join(legacyContainerLogsDir, fmt.Sprintf("*.%s", legacyLogSuffix)))
106- for _, logSymlink := range logSymlinks {
107- if _, err := osInterface.Stat(logSymlink); os.IsNotExist(err) {
108- if containerID, err := getContainerIDFromLegacyLogSymlink(logSymlink); err == nil {
Lorenz Brun6211e4d2023-11-14 19:09:40 +0100109- resp, err := cgc.manager.runtimeService.ContainerStatus(ctx, containerID, false)
Lorenz Brun7b822272021-02-03 17:03:41 +0100110- if err != nil {
111- // TODO: we should handle container not found (i.e. container was deleted) case differently
112- // once https://github.com/kubernetes/kubernetes/issues/63336 is resolved
Lorenz Brund13c1c62022-03-30 19:58:58 +0200113- klog.InfoS("Error getting ContainerStatus for containerID", "containerID", containerID, "err", err)
Lorenz Brunf2b7ab62022-05-04 19:06:00 +0200114- } else {
115- status := resp.GetStatus()
116- if status == nil {
117- klog.V(4).InfoS("Container status is nil")
118- continue
119- }
120- if status.State != runtimeapi.ContainerState_CONTAINER_EXITED {
121- // Here is how container log rotation works (see containerLogManager#rotateLatestLog):
122- //
123- // 1. rename current log to rotated log file whose filename contains current timestamp (fmt.Sprintf("%s.%s", log, timestamp))
124- // 2. reopen the container log
125- // 3. if #2 fails, rename rotated log file back to container log
126- //
127- // There is small but indeterministic amount of time during which log file doesn't exist (between steps #1 and #2, between #1 and #3).
128- // Hence the symlink may be deemed unhealthy during that period.
129- // See https://github.com/kubernetes/kubernetes/issues/52172
130- //
131- // We only remove unhealthy symlink for dead containers
132- klog.V(5).InfoS("Container is still running, not removing symlink", "containerID", containerID, "path", logSymlink)
133- continue
134- }
Lorenz Brun7b822272021-02-03 17:03:41 +0100135- }
136- } else {
Lorenz Brund13c1c62022-03-30 19:58:58 +0200137- klog.V(4).InfoS("Unable to obtain container ID", "err", err)
Lorenz Brun7b822272021-02-03 17:03:41 +0100138- }
139- err := osInterface.Remove(logSymlink)
140- if err != nil {
Lorenz Brund13c1c62022-03-30 19:58:58 +0200141- klog.ErrorS(err, "Failed to remove container log dead symlink", "path", logSymlink)
Lorenz Brun7b822272021-02-03 17:03:41 +0100142- } else {
Lorenz Brund13c1c62022-03-30 19:58:58 +0200143- klog.V(4).InfoS("Removed symlink", "path", logSymlink)
Lorenz Brun7b822272021-02-03 17:03:41 +0100144- }
145- }
146- }
147 return nil
148 }
Lorenz Brun732a8842024-08-26 23:25:37 +0200149
Lorenz Brun7b822272021-02-03 17:03:41 +0100150diff --git a/pkg/kubelet/runonce.go b/pkg/kubelet/runonce.go
Lorenz Brun732a8842024-08-26 23:25:37 +0200151index 448df444869..d5ecd47337f 100644
Lorenz Brun7b822272021-02-03 17:03:41 +0100152--- a/pkg/kubelet/runonce.go
153+++ b/pkg/kubelet/runonce.go
Lorenz Brund13c1c62022-03-30 19:58:58 +0200154@@ -19,7 +19,6 @@ package kubelet
Lorenz Brun7b822272021-02-03 17:03:41 +0100155 import (
Lorenz Brund13c1c62022-03-30 19:58:58 +0200156 "context"
Lorenz Brun7b822272021-02-03 17:03:41 +0100157 "fmt"
158- "os"
159 "time"
Lorenz Brun732a8842024-08-26 23:25:37 +0200160
Lorenz Brund13c1c62022-03-30 19:58:58 +0200161 v1 "k8s.io/api/core/v1"
Lorenz Brun6211e4d2023-11-14 19:09:40 +0100162@@ -50,13 +49,6 @@ func (kl *Kubelet) RunOnce(updates <-chan kubetypes.PodUpdate) ([]RunPodResult,
Lorenz Brun7b822272021-02-03 17:03:41 +0100163 return nil, err
164 }
Lorenz Brun732a8842024-08-26 23:25:37 +0200165
Lorenz Brun7b822272021-02-03 17:03:41 +0100166- // If the container logs directory does not exist, create it.
167- if _, err := os.Stat(ContainerLogsDir); err != nil {
168- if err := kl.os.MkdirAll(ContainerLogsDir, 0755); err != nil {
Lorenz Brund13c1c62022-03-30 19:58:58 +0200169- klog.ErrorS(err, "Failed to create directory", "path", ContainerLogsDir)
Lorenz Brun7b822272021-02-03 17:03:41 +0100170- }
171- }
172-
173 select {
174 case u := <-updates:
Lorenz Brund13c1c62022-03-30 19:58:58 +0200175 klog.InfoS("Processing manifest with pods", "numPods", len(u.Pods))
Lorenz Brun7b822272021-02-03 17:03:41 +0100176diff --git a/test/e2e_node/log_path_test.go b/test/e2e_node/log_path_test.go
Lorenz Brun732a8842024-08-26 23:25:37 +0200177index a1589e6d91e..179206eb1dd 100644
Lorenz Brun7b822272021-02-03 17:03:41 +0100178--- a/test/e2e_node/log_path_test.go
179+++ b/test/e2e_node/log_path_test.go
Lorenz Brund13c1c62022-03-30 19:58:58 +0200180@@ -22,8 +22,6 @@ import (
Lorenz Brun7b822272021-02-03 17:03:41 +0100181 v1 "k8s.io/api/core/v1"
182 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
183 "k8s.io/apimachinery/pkg/util/uuid"
184- "k8s.io/kubernetes/pkg/kubelet"
185- kubecontainer "k8s.io/kubernetes/pkg/kubelet/container"
186 "k8s.io/kubernetes/test/e2e/framework"
187 e2epod "k8s.io/kubernetes/test/e2e/framework/pod"
Lorenz Brunf2b7ab62022-05-04 19:06:00 +0200188 admissionapi "k8s.io/pod-security-admission/api"
Lorenz Brun732a8842024-08-26 23:25:37 +0200189@@ -122,22 +120,6 @@ var _ = SIGDescribe("ContainerLogPath", framework.WithNodeConformance(), func()
Lorenz Brun6211e4d2023-11-14 19:09:40 +0100190 err := createAndWaitPod(ctx, makeLogPod(logPodName, logString))
Lorenz Brun7b822272021-02-03 17:03:41 +0100191 framework.ExpectNoError(err, "Failed waiting for pod: %s to enter success state", logPodName)
192 })
Lorenz Brun6211e4d2023-11-14 19:09:40 +0100193- ginkgo.It("should print log to correct log path", func(ctx context.Context) {
Lorenz Brun7b822272021-02-03 17:03:41 +0100194-
195- logDir := kubelet.ContainerLogsDir
196-
197- // get containerID from created Pod
Lorenz Brun6211e4d2023-11-14 19:09:40 +0100198- createdLogPod, err := podClient.Get(ctx, logPodName, metav1.GetOptions{})
Lorenz Brun7b822272021-02-03 17:03:41 +0100199- logContainerID := kubecontainer.ParseContainerID(createdLogPod.Status.ContainerStatuses[0].ContainerID)
200- framework.ExpectNoError(err, "Failed to get pod: %s", logPodName)
201-
202- // build log file path
203- expectedlogFile := logDir + "/" + logPodName + "_" + f.Namespace.Name + "_" + logContainerName + "-" + logContainerID.ID + ".log"
204-
205- logCheckPodName := "log-check-" + string(uuid.NewUUID())
Lorenz Brun6211e4d2023-11-14 19:09:40 +0100206- err = createAndWaitPod(ctx, makeLogCheckPod(logCheckPodName, logString, expectedlogFile))
Lorenz Brun7b822272021-02-03 17:03:41 +0100207- framework.ExpectNoError(err, "Failed waiting for pod: %s to enter success state", logCheckPodName)
208- })
Lorenz Brun732a8842024-08-26 23:25:37 +0200209
Lorenz Brun6211e4d2023-11-14 19:09:40 +0100210 ginkgo.It("should print log to correct cri log path", func(ctx context.Context) {
Lorenz Brun732a8842024-08-26 23:25:37 +0200211
212--
2132.44.1
Lorenz Brun7b822272021-02-03 17:03:41 +0100214