Add infra_chart_reconfig_fluentd playbook 86/1086/6
authorFerenc Tóth <ferenc.2.toth@nokia.com>
Fri, 28 Jun 2019 08:37:13 +0000 (10:37 +0200)
committerFerenc Tóth <ferenc.2.toth@nokia.com>
Thu, 18 Jul 2019 00:27:38 +0000 (02:27 +0200)
This playbook reconfigures the fluentd component of the `caas-infra`
chart according to the `log_forwarding` rules in CM.
Typically this playbook is called by CM activator whenever the
`cloud.caas` content has been changed over REST API or by hostcli.

Signed-off-by: Ferenc Tóth <ferenc.2.toth@nokia.com>
Change-Id: I1b6dacc8ce1cab32443b8bd4bea70c67e99508c9

SPECS/infra-charts.spec
ansible/playbooks/infra_chart_reconfig_fluentd.yaml [new file with mode: 0644]
ansible/roles/infra_chart_reconfig/defaults/main.yaml [new file with mode: 0644]
ansible/roles/infra_chart_reconfig/tasks/main.yaml [new file with mode: 0644]

index cba2a0a..9cfc423 100644 (file)
@@ -15,7 +15,7 @@
 %define COMPONENT infra-charts
 %define RPM_NAME caas-%{COMPONENT}
 %define RPM_MAJOR_VERSION 1.0.0
-%define RPM_MINOR_VERSION 13
+%define RPM_MINOR_VERSION 14
 
 Name:           %{RPM_NAME}
 Version:        %{RPM_MAJOR_VERSION}
@@ -26,7 +26,7 @@ BuildArch:      x86_64
 Vendor:         %{_platform_vendor}
 Source0:        %{name}-%{version}.tar.gz
 
-Requires: rsync
+Requires: rsync, jq
 
 %description
 This rpm contains the necessary helm charts to deploy the caas subsystem.
@@ -39,10 +39,12 @@ This rpm contains the necessary helm charts to deploy the caas subsystem.
 %install
 mkdir -p %{buildroot}/%{_playbooks_path}/
 rsync -av ansible/playbooks/install_caas_infra.yaml %{buildroot}/%{_playbooks_path}/
+rsync -av ansible/playbooks/infra_chart_reconfig_fluentd.yaml %{buildroot}/%{_playbooks_path}/
 
 mkdir -p %{buildroot}/%{_roles_path}/
 rsync -av ansible/roles/install_caas_infra %{buildroot}/%{_roles_path}/
 rsync -av ansible/roles/pre_install_caas_infra %{buildroot}/%{_roles_path}/
+rsync -av ansible/roles/infra_chart_reconfig %{buildroot}/%{_roles_path}/
 
 mkdir -p %{buildroot}/%{_caas_chart_path}/
 rsync -av infra-charts/* %{buildroot}/%{_caas_chart_path}/
diff --git a/ansible/playbooks/infra_chart_reconfig_fluentd.yaml b/ansible/playbooks/infra_chart_reconfig_fluentd.yaml
new file mode 100644 (file)
index 0000000..a3dea05
--- /dev/null
@@ -0,0 +1,33 @@
+---
+# 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.
+
+# nokia.cmframework.requires: install_caas_infra.yaml
+- hosts: caas_master
+  run_once: true
+  strategy: free
+  become: true
+  become_user: "{{ users.admin_user_name }}"
+  vars:
+  - infra_chart_name: "caas-infra"
+  - infra_chart_components: [fluentd]
+  pre_tasks:
+  - name: check infra chart status
+    shell: "helm status {{ infra_chart_name }} -o json | jq .info.status.code"
+    register: helm_infra_chart_status
+    ignore_errors: yes
+  roles:
+  - role: infra_chart_reconfig
+    when:
+    - helm_infra_chart_status.stdout == "1"
diff --git a/ansible/roles/infra_chart_reconfig/defaults/main.yaml b/ansible/roles/infra_chart_reconfig/defaults/main.yaml
new file mode 100644 (file)
index 0000000..3afb374
--- /dev/null
@@ -0,0 +1,16 @@
+---
+# 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.
+
+infra_chart_filenames: "{{ infra_chart_components | map('regex_replace', '^(.*)$', caas.caas_chart_path+'/values_\\1.yaml') | list }}"
diff --git a/ansible/roles/infra_chart_reconfig/tasks/main.yaml b/ansible/roles/infra_chart_reconfig/tasks/main.yaml
new file mode 100644 (file)
index 0000000..4332de1
--- /dev/null
@@ -0,0 +1,29 @@
+---
+# 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: collect image names from the deployed {{ infra_chart_name }} chart
+  shell: "helm get manifest {{ infra_chart_name }} | grep ' image: {{ caas.registry_url }}' | sed 's/^\ *image:\ //' | sort -u"
+  register: helm_get_manifest_images
+- set_fact:
+    container_image_names: "{{ helm_get_manifest_images.stdout_lines }}"
+
+- name: template component specific values file
+  template:
+    src: "{{ item }}.j2"
+    dest: "{{ item }}"
+  with_items: "{{ infra_chart_filenames }}"
+
+- name: helm upgrade
+  shell: "HELM_HOST={{ caas.tiller_ip }}:{{ caas.tiller_port }} helm upgrade {{ infra_chart_name }} default/{{ infra_chart_name }} -f {{ infra_chart_filenames | join(',') }} --wait --timeout {{ caas.helm_operation_timeout }}"