From 5401551d122cf6f54a2a8e56beaca2a9bcc075a3 Mon Sep 17 00:00:00 2001 From: Elana Hashman Date: Thu, 11 Nov 2021 11:13:46 -0800 Subject: [PATCH] Append node e2e logs to file where possible Functionality added in systemd 240: https://github.com/systemd/systemd/blob/1977d1477f635057a87c0a5a59fc5d4e0b8ed6ec/NEWS#L3919-L3921 --- test/e2e_node/services/kubelet.go | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/test/e2e_node/services/kubelet.go b/test/e2e_node/services/kubelet.go index 76e2096bb46..a06e7001f7a 100644 --- a/test/e2e_node/services/kubelet.go +++ b/test/e2e_node/services/kubelet.go @@ -23,6 +23,8 @@ import ( "os" "os/exec" "path/filepath" + "regexp" + "strconv" "strings" "time" @@ -213,6 +215,21 @@ func (e *E2EServices) startKubelet() (*server, error) { // Since kubelet will typically be run as a service it also makes more // sense to test it that way isSystemd = true + + // If we are running on systemd >=240, we can append to the + // same log file on restarts + logLocation := "StandardError=file:" + if version, verr := exec.Command("systemd-run", "--version").Output(); verr == nil { + // sample output from $ systemd-run --version + // systemd 245 (245.4-4ubuntu3.13) + re := regexp.MustCompile(`systemd (\d+)`) + if match := re.FindSubmatch(version); len(match) > 1 { + num, _ := strconv.Atoi(string(match[1])) + if num >= 240 { + logLocation = "StandardError=append:" + } + } + } // We can ignore errors, to have GetTimestampFromWorkspaceDir() fallback // to the current time. cwd, _ := os.Getwd() @@ -222,7 +239,7 @@ func (e *E2EServices) startKubelet() (*server, error) { cmdArgs = append(cmdArgs, systemdRun, "-p", "Delegate=true", - "-p", "StandardError=file:"+framework.TestContext.ReportDir+"/kubelet.log", + "-p", logLocation+framework.TestContext.ReportDir+"/kubelet.log", "--unit="+unitName, "--slice=runtime.slice", "--remain-after-exit",