From 430ada006d5e9f30563a96f4f308718563fee6be Mon Sep 17 00:00:00 2001 From: Claudiu Belu Date: Fri, 29 Jul 2022 20:53:21 +0300 Subject: [PATCH] Fixes kubelet log compression on Windows Currently, when kubelet will try to compress the logs to a .gz file, it will attempt to rename the archive before closing its file handles, which results in an error on Windows. This addresses the issue mentioned above. --- pkg/kubelet/logs/container_log_manager.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pkg/kubelet/logs/container_log_manager.go b/pkg/kubelet/logs/container_log_manager.go index 6d440737f3c..a5247607ea3 100644 --- a/pkg/kubelet/logs/container_log_manager.go +++ b/pkg/kubelet/logs/container_log_manager.go @@ -393,11 +393,15 @@ func (c *containerLogManager) compressLog(log string) error { if _, err := io.Copy(w, r); err != nil { return fmt.Errorf("failed to compress %q to %q: %v", log, tmpLog, err) } + // The archive needs to be closed before renaming, otherwise an error will occur on Windows. + w.Close() + f.Close() compressedLog := log + compressSuffix if err := c.osInterface.Rename(tmpLog, compressedLog); err != nil { return fmt.Errorf("failed to rename %q to %q: %v", tmpLog, compressedLog, err) } // Remove old log file. + r.Close() if err := c.osInterface.Remove(log); err != nil { return fmt.Errorf("failed to remove log %q after compress: %v", log, err) }