From 3841690dbf100f89875a6cac0fed7eb79eea62fa Mon Sep 17 00:00:00 2001 From: Julien Balestra Date: Tue, 17 Jan 2017 10:29:50 +0100 Subject: [PATCH 1/4] Kubelet-rkt: Add useful informations for Ops on the Kubelet Host Create a Systemd SyslogIdentifier inside the [Service] Create a Systemd Description inside the [Unit] --- pkg/kubelet/rkt/rkt.go | 15 +++++++++++++++ pkg/kubelet/rkt/rkt_test.go | 28 ++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/pkg/kubelet/rkt/rkt.go b/pkg/kubelet/rkt/rkt.go index 8742055da0b..726d5364075 100644 --- a/pkg/kubelet/rkt/rkt.go +++ b/pkg/kubelet/rkt/rkt.go @@ -1108,6 +1108,18 @@ func (r *Runtime) getSelinuxContext(opt *v1.SELinuxOptions) (string, error) { return strings.Join(ctx, ":"), nil } +// From the generateName or the podName return a basename for improve the logging with the Journal +// journalctl -t podBaseName +func constructSyslogIdentifier(generateName string, podName string) string { + if (len(generateName) > 1 && generateName[len(generateName) - 1] == '-') { + return generateName[0:len(generateName) - 1] + } else if (len(generateName) > 0) { + return generateName + } else { + return podName + } +} + // preparePod will: // // 1. Invoke 'rkt prepare' to prepare the pod, and get the rkt pod uuid. @@ -1174,6 +1186,9 @@ func (r *Runtime) preparePod(pod *v1.Pod, podIP string, pullSecrets []v1.Secret, // This enables graceful stop. newUnitOption("Service", "KillMode", "mixed"), newUnitOption("Service", "TimeoutStopSec", fmt.Sprintf("%ds", getPodTerminationGracePeriodInSecond(pod))), + // Ops helpers + newUnitOption("Unit", "Description", pod.Name), + newUnitOption("Service", "SyslogIdentifier", constructSyslogIdentifier(pod.GenerateName, pod.Name)), // Track pod info for garbage collection newUnitOption(unitKubernetesSection, unitPodUID, string(pod.UID)), newUnitOption(unitKubernetesSection, unitPodName, pod.Name), diff --git a/pkg/kubelet/rkt/rkt_test.go b/pkg/kubelet/rkt/rkt_test.go index e3e8231286d..0d6dfa722c8 100644 --- a/pkg/kubelet/rkt/rkt_test.go +++ b/pkg/kubelet/rkt/rkt_test.go @@ -1952,3 +1952,31 @@ func TestPreparePodArgs(t *testing.T) { assert.Equal(t, testCase.cmd, cmd, fmt.Sprintf("Test case #%d", i)) } } + +func TestConstructSyslogIdentifier(t *testing.T) { + testCases := []struct { + podName string + podGenerateName string + identifier string + }{ + { + "prometheus-node-exporter-rv90m", + "prometheus-node-exporter-", + "prometheus-node-exporter", + }, + { + "simplepod", + "", + "simplepod", + }, + { + "p", + "", + "p", + }, + } + for i, testCase := range testCases { + identifier := constructSyslogIdentifier(testCase.podGenerateName, testCase.podName) + assert.Equal(t, testCase.identifier, identifier, fmt.Sprintf("Test case #%d", i)) + } +} \ No newline at end of file From ff8fbd4c8b8449ce330b399e1e564c4cd8d6d39c Mon Sep 17 00:00:00 2001 From: Julien Balestra Date: Mon, 20 Feb 2017 18:16:41 +0100 Subject: [PATCH 2/4] Fix a typo --- pkg/kubelet/rkt/rkt.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/kubelet/rkt/rkt.go b/pkg/kubelet/rkt/rkt.go index 726d5364075..6420245037c 100644 --- a/pkg/kubelet/rkt/rkt.go +++ b/pkg/kubelet/rkt/rkt.go @@ -1108,7 +1108,7 @@ func (r *Runtime) getSelinuxContext(opt *v1.SELinuxOptions) (string, error) { return strings.Join(ctx, ":"), nil } -// From the generateName or the podName return a basename for improve the logging with the Journal +// From the generateName or the podName return a basename for improving the logging with the Journal // journalctl -t podBaseName func constructSyslogIdentifier(generateName string, podName string) string { if (len(generateName) > 1 && generateName[len(generateName) - 1] == '-') { From 89e1382dd9c58ebdfad40972bcfe1330da835e2f Mon Sep 17 00:00:00 2001 From: Julien Balestra Date: Mon, 20 Feb 2017 18:24:41 +0100 Subject: [PATCH 3/4] Remove else if else --- pkg/kubelet/rkt/rkt.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pkg/kubelet/rkt/rkt.go b/pkg/kubelet/rkt/rkt.go index 6420245037c..182000445ac 100644 --- a/pkg/kubelet/rkt/rkt.go +++ b/pkg/kubelet/rkt/rkt.go @@ -1113,11 +1113,11 @@ func (r *Runtime) getSelinuxContext(opt *v1.SELinuxOptions) (string, error) { func constructSyslogIdentifier(generateName string, podName string) string { if (len(generateName) > 1 && generateName[len(generateName) - 1] == '-') { return generateName[0:len(generateName) - 1] - } else if (len(generateName) > 0) { - return generateName - } else { - return podName } + if (len(generateName) > 0) { + return generateName + } + return podName } // preparePod will: From 7de2d51f90ff6e08436d69c7aa560aecfb304d6f Mon Sep 17 00:00:00 2001 From: JulienBalestra Date: Tue, 21 Feb 2017 23:06:13 +0100 Subject: [PATCH 4/4] gofmt rkt.go, rkt_test.go --- pkg/kubelet/rkt/rkt.go | 6 +++--- pkg/kubelet/rkt/rkt_test.go | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/pkg/kubelet/rkt/rkt.go b/pkg/kubelet/rkt/rkt.go index 182000445ac..d3ea9a7607b 100644 --- a/pkg/kubelet/rkt/rkt.go +++ b/pkg/kubelet/rkt/rkt.go @@ -1111,10 +1111,10 @@ func (r *Runtime) getSelinuxContext(opt *v1.SELinuxOptions) (string, error) { // From the generateName or the podName return a basename for improving the logging with the Journal // journalctl -t podBaseName func constructSyslogIdentifier(generateName string, podName string) string { - if (len(generateName) > 1 && generateName[len(generateName) - 1] == '-') { - return generateName[0:len(generateName) - 1] + if len(generateName) > 1 && generateName[len(generateName)-1] == '-' { + return generateName[0 : len(generateName)-1] } - if (len(generateName) > 0) { + if len(generateName) > 0 { return generateName } return podName diff --git a/pkg/kubelet/rkt/rkt_test.go b/pkg/kubelet/rkt/rkt_test.go index 0d6dfa722c8..536f3853c71 100644 --- a/pkg/kubelet/rkt/rkt_test.go +++ b/pkg/kubelet/rkt/rkt_test.go @@ -1955,9 +1955,9 @@ func TestPreparePodArgs(t *testing.T) { func TestConstructSyslogIdentifier(t *testing.T) { testCases := []struct { - podName string - podGenerateName string - identifier string + podName string + podGenerateName string + identifier string }{ { "prometheus-node-exporter-rv90m", @@ -1979,4 +1979,4 @@ func TestConstructSyslogIdentifier(t *testing.T) { identifier := constructSyslogIdentifier(testCase.podGenerateName, testCase.podName) assert.Equal(t, testCase.identifier, identifier, fmt.Sprintf("Test case #%d", i)) } -} \ No newline at end of file +}