podlogs: include node name in prefix

This is useful for logs from daemonset pods because for those it is
often relevant which node they ran on because they interact with
resources or other pods on the host.

To keep the log prefix short, it gets limited to a maximum length of
10 characters.
This commit is contained in:
Patrick Ohly 2020-02-17 12:07:10 +01:00
parent 3ed0f1bec1
commit 0ec85320cf

View File

@ -133,7 +133,11 @@ func CopyAllLogs(ctx context.Context, cs clientset.Interface, ns string, to LogO
var prefix string
if to.LogWriter != nil {
out = to.LogWriter
prefix = name + ": "
nodeName := pod.Spec.NodeName
if len(nodeName) > 10 {
nodeName = nodeName[0:4] + ".." + nodeName[len(nodeName)-4:]
}
prefix = name + "@" + nodeName + ": "
} else {
var err error
filename := to.LogPathPrefix + pod.ObjectMeta.Name + "-" + c.Name + ".log"