Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preflight check of single node-exporter installation #3011

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
---

- name: Prepare configuration and upgrade/install Node-Exporter's Helm chart
vars:
# Handling "undefined", "null", "empty" and "boolean" values all at once.
disable_helm_chart_bool: "{{ specification.disable_helm_chart | default(false, true) | bool }}"

# Handling "undefined", "null" and "empty" values all at once.
helm_chart_values_bool: "{{ specification.helm_chart_values | default(false) | ternary(true, false) }}"

delegate_to: localhost
become: false
run_once: true
Expand All @@ -26,7 +23,7 @@
repository_url: "{{ custom_repository_url | default('http://localhost/epirepo', true) }}"

- when: helm_chart_values_bool
# IF `helm_chart_values`
# IF `helm_chart_values`
block:
- name: Copy Node-Exporter's Helm chart's custom configuration to file
copy:
Expand All @@ -35,17 +32,17 @@

- name: Install Node-Exporter's Helm chart (with custom values.yaml)
delegate_to: localhost
shell: |
command: |
helm -n {{ monitoring_chart_namespace }} upgrade --install \
-f {{ download_directory }}/{{ node_exporter_helm_chart_name }}_values.yaml \
{{ node_exporter_helm_chart_name }} \
{{ download_directory }}/{{ exporter_chart_file_name }} --create-namespace

- when: not helm_chart_values_bool
# ELSE
# ELSE
block:
- name: Install Node-Exporter's Helm chart (with default values.yaml)
shell: |
command: |
helm -n {{ monitoring_chart_namespace }} upgrade --install \
{{ node_exporter_helm_chart_name }} \
{{ download_directory }}/{{ exporter_chart_file_name }} --create-namespace
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
---

- name: Create node_exporter system group
group:
name: node_exporter
Expand Down Expand Up @@ -43,7 +42,7 @@
src: "{{ download_directory }}/{{ exporter_file_name }}"
dest: "/opt/node_exporter"
creates: "/opt/node_exporter/node_exporter"
extra_opts: [--strip-components=1]
extra_opts: [ --strip-components=1 ]
mode: u=rwx,g=rx,o=rx
owner: root
group: node_exporter
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
---

- name: "Uninstall Helm release {{ node_exporter_helm_chart_name }} from {{ node_exporter_release_ns }} ns"

delegate_to: localhost
become: false
run_once: true

command: "helm uninstall -n {{ node_exporter_release_ns }} {{ node_exporter_helm_chart_name }}"
5 changes: 2 additions & 3 deletions ansible/playbooks/roles/node_exporter/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
---

- name: Include installation tasks for Node Exporter as System Service
include_tasks: install-node-exporter-as-system-service.yml
include_tasks: apply/install-node-exporter-as-system-service.yml

- name: Include installation tasks for Node Exporter as DaemonSet for "k8s as cloud service"
when: k8s_as_cloud_service is defined and k8s_as_cloud_service
include_tasks: install-node-exporter-as-daemonset.yml
include_tasks: apply/install-node-exporter-as-daemonset.yml
23 changes: 23 additions & 0 deletions ansible/playbooks/roles/node_exporter/tasks/preflight/upgrade.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
- name: Check that only one Node Exporter Helm release is installed
run_once: true
block:
- name: Include defaults from node_exporter role
include_vars:
file: roles/node_exporter/defaults/main.yml
name: exporter_defaults

- name: Get information about node-exporter helm releases
become: true
command: "helm list --all-namespaces --output json --filter {{ exporter_defaults.node_exporter_helm_chart_name }}"
register: node_exporter_helm_list
changed_when: false

- name: Assert node-exported installed only in one namespace
assert:
that: node_exporter_helm_list.stdout_lines|length == 1
fail_msg: |
Multiple Helm installations of Node Exporter are not supported or there is nothing to upgrade.
`helm list` output:
{{ node_exporter_helm_list.stdout_lines }}
success_msg: There is only one Node Exporter release.
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
---
- name: Node Exporter | Include defaults from node_exporter role
include_vars:
file: roles/node_exporter/defaults/main.yml
file: defaults/main.yml
name: exporter_defaults

- name: Node Exporter | Include specification vars from node_exporter role
include_vars:
file: roles/node_exporter/vars/main.yml
file: vars/main.yml
name: exporter_vars

# Re-installation in a different namespace was added in Epiphany v1.3
# Everything related to that topic can be removed when versions before 1.3 are unsupported, including preflight checks
- name: Node Exporter as DaemonSet | Prepare fact about helm release and reinstall daemonset if release exists
delegate_to: localhost
become: false
Expand Down Expand Up @@ -86,6 +88,7 @@
- name: Node Exporter as System Service | Collect version
shell: >-
/opt/node_exporter/node_exporter --version 2>&1
changed_when: false
register: exporter_current_version_out

- name: Node Exporter as System Service | Set exporter_current_version fact
Expand Down Expand Up @@ -140,7 +143,7 @@
src: "{{ download_directory }}/{{ exporter_file_name }}"
dest: /opt/node_exporter
creates: /opt/node_exporter/node_exporter
extra_opts: [--strip-components=1]
extra_opts: [ --strip-components=1 ]
mode: u=rwx,go=rx
owner: root
group: node_exporter
Expand Down
8 changes: 8 additions & 0 deletions ansible/playbooks/roles/preflight/tasks/upgrade.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,11 @@
- groups.postgresql is defined
- groups.postgresql | length > 0
- "'postgresql' in group_names" # run only on PostgreSQL hosts

- name: Node Exporter in K8s checks
include_tasks: roles/node_exporter/tasks/preflight/upgrade.yml
when:
- "'node_exporter' in upgrade_components or upgrade_components|length == 0"
- k8s_as_cloud_service is defined and k8s_as_cloud_service
- "'node_exporter' in group_names"
- "'kubernetes_master' in group_names"
6 changes: 3 additions & 3 deletions ansible/playbooks/upgrade.yml
Original file line number Diff line number Diff line change
Expand Up @@ -280,9 +280,9 @@
become: true
become_method: sudo
tasks:
- import_role:
name: upgrade
tasks_from: node-exporter
- include_role:
name: node_exporter
tasks_from: upgrade/main
when: "'node_exporter' in upgrade_components or upgrade_components|length == 0"
environment:
KUBECONFIG: "{{ kubeconfig.local }}"
Expand Down