...
1
2
3
18
19 package kubelet
20
21 import (
22 "context"
23 "fmt"
24 "os/exec"
25 "strings"
26 )
27
28
29
30 func getLoggingCmd(n *nodeLogQuery, services []string) (string, []string, error) {
31 args := []string{
32 "--utc",
33 "--no-pager",
34 "--output=short-precise",
35 }
36 if n.SinceTime != nil {
37 args = append(args, fmt.Sprintf("--since=%s", n.SinceTime.Format(dateLayout)))
38 }
39 if n.UntilTime != nil {
40 args = append(args, fmt.Sprintf("--until=%s", n.UntilTime.Format(dateLayout)))
41 }
42 if n.TailLines != nil {
43 args = append(args, "--pager-end", fmt.Sprintf("--lines=%d", *n.TailLines))
44 }
45 for _, service := range services {
46 if len(service) > 0 {
47 args = append(args, "--unit="+service)
48 }
49 }
50 if len(n.Pattern) > 0 {
51 args = append(args, "--grep="+n.Pattern)
52 }
53
54 if n.Boot != nil {
55 args = append(args, "--boot", fmt.Sprintf("%d", *n.Boot))
56 }
57
58 return "journalctl", args, nil
59 }
60
61
62 func checkForNativeLogger(ctx context.Context, service string) bool {
63
64 cmd := exec.CommandContext(ctx, "journalctl", []string{"--field", "_SYSTEMD_UNIT"}...)
65 output, err := cmd.CombinedOutput()
66 if err != nil {
67
68 return false
69 }
70
71
72
73 return strings.Contains(string(output), service+".service")
74 }
75
View as plain text