Add kubelet root dir as a parameter 70/1570/23
authorBalazs Szekeres <balazs.szekeres@nokia.com>
Wed, 11 Sep 2019 19:27:32 +0000 (21:27 +0200)
committerBalazs Szekeres <balazs.szekeres@nokia.com>
Fri, 27 Sep 2019 13:30:30 +0000 (15:30 +0200)
Added kubelet root directory as a parameter
Kubernetes dumps JAVA heap dump to kubelet root dir which is not too nice,
  since the disk can be flooded by a faulty component.
CaaS logging customization moved from utils rpm to instantiate rpm

Change-Id: I2bf3f20c1502e03939132cc19da6e9b529424186
Signed-off-by: Balazs Szekeres <balazs.szekeres@nokia.com>
SPECS/instantiate.spec
SPECS/utils.spec
ansible/playbooks/pre_config_all.yaml
ansible/roles/log/tasks/main.yml [new file with mode: 0644]
ansible/roles/log/templates/kubelet-plugins [moved from utils/log/kubelet-plugins with 53% similarity]
cm_config/caas.yaml

index 65d86cc..0d32658 100644 (file)
@@ -56,6 +56,8 @@ rsync -av ansible/roles/docker_image_push %{buildroot}/%{_roles_path}/
 rsync -av ansible/roles/manifests %{buildroot}/%{_roles_path}/
 rsync -av ansible/roles/nodeconf %{buildroot}/%{_roles_path}/
 rsync -av ansible/roles/pre_config_all %{buildroot}/%{_roles_path}/
+rsync -av ansible/roles/log %{buildroot}/%{_roles_path}/
+
 
 mkdir -p %{buildroot}%/%{_bootstrapping_path}/
 
index 5e6a606..f1cac00 100644 (file)
@@ -16,7 +16,6 @@
 %define RPM_NAME caas-%{COMPONENT}
 %define RPM_MAJOR_VERSION 1.0.0
 %define RPM_MINOR_VERSION 7
-%define KUBELET_PLUGINS_LOGDIR /var/log/kubelet-plugins/
 
 Name:           %{RPM_NAME}
 Version:        %{RPM_MAJOR_VERSION}
@@ -40,10 +39,6 @@ This rpm contains the supplementary utils for caas subsystem.
 
 %install
 mkdir -p %{buildroot}/%{_caas_libexec_path}/
-# --------------------------- LOG
-mkdir -p %{buildroot}/etc/logrotate.d/
-install -m 0640 utils/log/kubelet-plugins %{buildroot}/etc/logrotate.d/
-sed -i -e 's|{{ kubelet_plugings_log_dir }}|%{KUBELET_PLUGINS_LOGDIR}|g' %{buildroot}/etc/logrotate.d/kubelet-plugins
 # --------------------------- DEPLOY
 install -m 0700 utils/deploy/merge_image.sh %{buildroot}/%{_caas_libexec_path}/
 mkdir -p %{buildroot}/etc/systemd/system/
@@ -52,34 +47,16 @@ mkdir -p %{buildroot}/etc/profile.d/
 
 %files
 %{_caas_libexec_path}/merge_image.sh
-/etc/logrotate.d/kubelet-plugins
 %exclude %{_caas_libexec_path}/*pyc
 %exclude %{_caas_libexec_path}/*pyo
 
 %preun
 
 %post
-# --------------------------- LOG
-mkdir -p %{KUBELET_PLUGINS_LOGDIR}/
-grep "#CaaS CUSTOM BEGIN" /etc/logrotate.d/syslog > /dev/null;
-if [ $? -eq 0 ]; then
-  sed -i -e '/#CaaS CUSTOM BEGIN/,/#CaaS CUSTOM END/d' /etc/logrotate.d/syslog
-fi
-sed -i -e '/.*missingok/i #CaaS CUSTOM BEGIN\n    hourly\n    size 50\n#CaaS CUSTOM END' /etc/logrotate.d/syslog
 # --------------------------- DEPLOY
 find /usr/lib/debug/usr/ -xtype l -exec rm -f {} \;
-# --------------------------- COMMON
 
 %postun
-# If not upgrade, revert all CaaS related cusotmization
-if [ $1 == 0 ]; then
-
-# --------------------------- LOG
-  sed -i -e '/#CaaS CUSTOM BEGIN/,/#CaaS CUSTOM END/d' /etc/logrotate.d/syslog
-/usr/bin/systemctl daemon-reload
-# --------------------------- DEPLOY
-# --------------------------- COMMON
-fi
 
 
 %clean
index de21880..0436d73 100644 (file)
@@ -19,4 +19,5 @@
   become: true
   become_user: "{{ users.admin_user_name }}"
   roles:
+    - log
     - pre_config_all
diff --git a/ansible/roles/log/tasks/main.yml b/ansible/roles/log/tasks/main.yml
new file mode 100644 (file)
index 0000000..cb3d84f
--- /dev/null
@@ -0,0 +1,52 @@
+---
+# Copyright 2019 Nokia
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+- name: create logrotate directory
+  file:
+    path: "/etc/logrotate.d/"
+    state: directory
+  become: true
+  become_user: "root"
+
+- name: create the kubelet plugins log directory
+  file:
+    path: "{{ caas.kubelet_plugins_log_dir }}"
+    state: directory
+  become: true
+  become_user: "root"
+
+- name: template kubelet-plugins to logrotate directory
+  template:
+    src: kubelet-plugins
+    dest: /etc/logrotate.d/kubelet-plugins
+    mode: 0640
+  become: true
+  become_user: "root"
+
+- name: Ansible insert a line before example
+  blockinfile:
+    dest: /etc/logrotate.d/syslog
+    marker: "# CaaS CUSTOM {mark}"
+    block: |
+          hourly
+          size 50
+    insertbefore: .*missingok
+  become: true
+  become_user: "root"
+
+- name: daemon reload
+  command: /usr/bin/systemctl daemon-reload
+  become: true
+  become_user: "root"
similarity index 53%
rename from utils/log/kubelet-plugins
rename to ansible/roles/log/templates/kubelet-plugins
index 38729f8..5206ec9 100644 (file)
@@ -1,4 +1,4 @@
-{{ kubelet_plugings_log_dir }}/*.log {
+"{{ caas.kubelet_plugins_log_dir }}"/*.log {
     rotate 20
     maxage 30
     missingok
@@ -6,17 +6,17 @@
   }
 
 # TODO: clean up config when logrotate 3.10 is available https://superuser.com/questions/1059033/logrotate-wildcard-fails-on-missing-files-with-missingok-and-olddir
-# TODO: check /var/lib/kubelet/plugins/**/*.log with newer version of logrotate
-/var/lib/kubelet/plugins/*log /var/lib/kubelet/plugins/*/*log /var/lib/kubelet/plugins/*/*/*log /var/lib/kubelet/plugins/*/*/*/*log {
+# TODO: check "{{ caas.kubelet_root_directory }}"/plugins/**/*.log with newer version of logrotate
+"{{ caas.kubelet_root_directory }}"/plugins/*log "{{ caas.kubelet_root_directory }}"/plugins/*/*log "{{ caas.kubelet_root_directory }}"/plugins/*/*/*log "{{ caas.kubelet_root_directory }}"/plugins/*/*/*/*log {
     size 100M
     missingok
     copytruncate
     sharedscripts
     postrotate
-      rotated_logs="$(find /var/lib/kubelet/plugins -name '*.log.[1-20]')"
+      rotated_logs="$(find "{{ caas.kubelet_root_directory }}"/plugins -name '*.log.[1-20]')"
       for file in $rotated_logs; do
         log_file_name="$(basename $file | sed -r 's/.[0-9]+$//')"
-        mv $file {{ kubelet_plugings_log_dir }}/$log_file_name
+        mv $file "{{ caas.kubelet_plugins_log_dir }}"/$log_file_name
       done
     endscript
   }
index 98bf332..b2a47ba 100644 (file)
@@ -16,6 +16,8 @@
 salt: malaise68Adroitness44Gradate45Probe41Settle46Newsweek93restrict8Thirsty35abused9Pluperfect
 max_login_time: 30
 max_parallel_session: 15
+kubelet_root_directory: "/home/kubelet"
+kubelet_plugins_log_dir: "/var/log/kubelet-plugins/"
 ansible_success: 'Ansible deploy END success'
 docker_directory: /var/lib/docker
 cert_directory: /etc/docker