blob: 6f37db701ed3fcfd73677d5401341b752f4299d5 [file] [log] [blame]
Lorenz Brunf2b7ab62022-05-04 19:06:00 +02001From 6b4af308e9b420c146983ddb031fd80be0a15ec9 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 Brunf2b7ab62022-05-04 19:06:00 +02004Subject: [PATCH 3/5] 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 Brunf2b7ab62022-05-04 19:06:00 +020015index 01e9c49c6f1..895fa86fb7e 100644
Lorenz Brun7b822272021-02-03 17:03:41 +010016--- a/pkg/kubelet/kubelet.go
17+++ b/pkg/kubelet/kubelet.go
Lorenz Brunf2b7ab62022-05-04 19:06:00 +020018@@ -1326,13 +1326,6 @@ func (kl *Kubelet) initializeModules() error {
Lorenz Brun7b822272021-02-03 17:03:41 +010019 return err
20 }
21
22- // 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-
29 // Start the image manager.
30 kl.imageManager.Start()
31
32diff --git a/pkg/kubelet/kuberuntime/kuberuntime_container.go b/pkg/kubelet/kuberuntime/kuberuntime_container.go
Lorenz Brunf2b7ab62022-05-04 19:06:00 +020033index 680eab7a56e..52210adb35d 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 Brunf2b7ab62022-05-04 19:06:00 +020036@@ -255,25 +255,6 @@ func (m *kubeGenericRuntimeManager) startContainer(podSandboxID string, 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))
39
40- // 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 Brunf2b7ab62022-05-04 19:06:00 +020062@@ -970,23 +951,6 @@ func (m *kubeGenericRuntimeManager) removeContainerLog(containerID string) error
Lorenz Brun7b822272021-02-03 17:03:41 +010063 return err
64 }
65
Lorenz Brunf2b7ab62022-05-04 19:06:00 +020066- resp, err := m.runtimeService.ContainerStatus(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 }
85
86diff --git a/pkg/kubelet/kuberuntime/kuberuntime_gc.go b/pkg/kubelet/kuberuntime/kuberuntime_gc.go
Lorenz Brunf2b7ab62022-05-04 19:06:00 +020087index a72691bfcfc..a09dec91fbb 100644
Lorenz Brun7b822272021-02-03 17:03:41 +010088--- a/pkg/kubelet/kuberuntime/kuberuntime_gc.go
89+++ b/pkg/kubelet/kuberuntime/kuberuntime_gc.go
90@@ -18,7 +18,6 @@ package kuberuntime
91
92 import (
93 "fmt"
94- "os"
95 "path/filepath"
96 "sort"
97 "time"
Lorenz Brunf2b7ab62022-05-04 19:06:00 +020098@@ -347,51 +346,6 @@ func (cgc *containerGC) evictPodLogsDirectories(allSourcesReady bool) error {
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 Brunf2b7ab62022-05-04 19:06:00 +0200109- resp, err := cgc.manager.runtimeService.ContainerStatus(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 }
149
150diff --git a/pkg/kubelet/runonce.go b/pkg/kubelet/runonce.go
Lorenz Brunf2b7ab62022-05-04 19:06:00 +0200151index 00f3022af5a..99d1c8b6a8d 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"
160
Lorenz Brund13c1c62022-03-30 19:58:58 +0200161 v1 "k8s.io/api/core/v1"
162@@ -49,13 +48,6 @@ func (kl *Kubelet) RunOnce(updates <-chan kubetypes.PodUpdate) ([]RunPodResult,
Lorenz Brun7b822272021-02-03 17:03:41 +0100163 return nil, err
164 }
165
166- // 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 Brunf2b7ab62022-05-04 19:06:00 +0200177index cdbc2b6d8ae..3535a81822f 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"
189@@ -122,22 +120,6 @@ var _ = SIGDescribe("ContainerLogPath [NodeConformance]", func() {
Lorenz Brun7b822272021-02-03 17:03:41 +0100190 err := createAndWaitPod(makeLogPod(logPodName, logString))
191 framework.ExpectNoError(err, "Failed waiting for pod: %s to enter success state", logPodName)
192 })
193- ginkgo.It("should print log to correct log path", func() {
194-
195- logDir := kubelet.ContainerLogsDir
196-
197- // get containerID from created Pod
198- createdLogPod, err := podClient.Get(context.TODO(), logPodName, metav1.GetOptions{})
199- 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())
206- err = createAndWaitPod(makeLogCheckPod(logCheckPodName, logString, expectedlogFile))
207- framework.ExpectNoError(err, "Failed waiting for pod: %s to enter success state", logCheckPodName)
208- })
209
210 ginkgo.It("should print log to correct cri log path", func() {
211
212--
2132.25.1
214