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.
This commit is contained in:
Claudiu Belu 2022-07-29 20:53:21 +03:00
parent 95303390ac
commit 430ada006d

View File

@ -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)
}