Manage Kubernetes logs

The patch brings service metadata in order to configure:
* rsyslog: dump hypercube logs to a dedicated log file,
* log_collector: log parsing of this file,
* logrotate: ensure logrotation.

Depends-On: I7de304aa11512bc83802fe097af9f4375075fd52
Depends-On: Id2168fa5194a1afc4048faeaf9301504cd5b5782

Change-Id: I791fcb6dfaed77ac15a95741215d7396e8faa1bf
diff --git a/kubernetes/_common.sls b/kubernetes/_common.sls
index 347048f..f9a6902 100644
--- a/kubernetes/_common.sls
+++ b/kubernetes/_common.sls
@@ -18,7 +18,7 @@
     - if_missing: /usr/local/src/flannel/flannel-0.5.5/
 {%- endif %}
 
-{%- if common.hyperkube %}
+{%- if common.hyperkube is defined %}
 /tmp/hyperkube:
   file.directory:
     - user: root
@@ -115,4 +115,17 @@
     - file: /etc/kubernetes/kubelet.kubeconfig
     - file: manifest_dir_create
 
+{%- if common.logrotate is defined %}
+/etc/logrotate.d/kubernetes:
+  file.managed:
+    - source: salt://kubernetes/files/logrotate
+    - template: jinja
+    - user: root
+    - group: root
+    - mode: 644
+    - makedirs: true
+    - defaults:
+      logfile: {{ common.logrotate }}
+
+{% endif %}
 {% endif %}
diff --git a/kubernetes/files/logrotate b/kubernetes/files/logrotate
new file mode 100644
index 0000000..59520de
--- /dev/null
+++ b/kubernetes/files/logrotate
@@ -0,0 +1,13 @@
+{{ logfile }} {
+  rotate 5
+  daily
+  nocreate
+  missingok
+  delaycompress
+  compress
+  minsize 10M
+  maxsize 50M
+  postrotate
+    invoke-rc.d rsyslog rotate > /dev/null
+  endscript
+}
diff --git a/metadata/service/logging.yml b/metadata/service/logging.yml
new file mode 100644
index 0000000..aebb0fc
--- /dev/null
+++ b/metadata/service/logging.yml
@@ -0,0 +1,38 @@
+parameters:
+  _param:
+    kubernetes_syslog_pattern: "%syslogtag:1:32%%msg:::sp-if-no-1st-sp%%msg%\\n"
+  kubernetes:
+    common:
+      logrotate: /var/log/kubernetes.log
+  heka:
+    log_collector:
+      input:
+        kubernetes:
+          engine: logstreamer
+          log_directory: "/var/log"
+          file_match: 'kubernetes\.log\.?(?P<Seq>\d*)$'
+          differentiator: ['kubernetes']
+          priority: ["^Seq"]
+          decoder: "kubernetes_decoder"
+          splitter: "TokenSplitter"
+      decoder:
+        kubernetes:
+          engine: sandbox
+          adjust_timezone: true
+          config:
+            syslog_pattern: ${_param:kubernetes_syslog_pattern}
+  rsyslog:
+    client:
+      output:
+        file:
+          /var/log/kubernetes.log:
+            sync: false
+            filter: "if $programname startswith 'kube' then"
+            stop_processing: true
+            template: ${_param:kubernetes_syslog_pattern}
+            skip_log_collector: true
+            owner: syslog
+            group: adm
+            createmode: "0640"
+            enabled: true
+