-
Notifications
You must be signed in to change notification settings - Fork 107
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
Installing node exporter and filebeat as daemonsets in custom namespaces #1839
Merged
rpudlowski93
merged 9 commits into
hitachienergy:develop
from
rpudlowski93:bug/daemonsets-in-custom-namespaces
Nov 24, 2020
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
b7f685c
Installing daemonsets in custom namespaces
6b27629
Helm Chart name added to uninstall role
47db578
Upgrade process added
fe8174f
Including vars moved on the top of task
c3e9444
Added more strictly condiction
fcbd10c
Obtaining helm releases in different way
9f4c269
Format improved
4680c72
Kubeconfig env moved to playbook level
2ce2b4e
Changelog updated
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
core/src/epicli/data/common/ansible/playbooks/roles/filebeat/defaults/main.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
--- | ||
filebeat_helm_chart_file_name: filebeat-7.9.2.tgz | ||
filebeat_version: "7.9.2" | ||
# Use custom namespace for logging charts such as filebeat in case of k8s as cloud service. | ||
logging_chart_namespace: epi-logging | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
...li/data/common/ansible/playbooks/roles/filebeat/tasks/uninstall-filebeat-as-daemonset.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
--- | ||
|
||
- name: Uninstall Helm release "{{ specification.helm_chart_name }}" | ||
|
||
delegate_to: localhost | ||
become: false | ||
run_once: true | ||
|
||
command: helm uninstall {{ specification.helm_chart_name }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
...mmon/ansible/playbooks/roles/node_exporter/tasks/uninstall-node-exporter-as-daemonset.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
--- | ||
|
||
- name: Uninstall Helm release "{{ specification.helm_chart_name }}" | ||
|
||
delegate_to: localhost | ||
become: false | ||
run_once: true | ||
|
||
command: helm uninstall {{ specification.helm_chart_name }} |
46 changes: 41 additions & 5 deletions
46
core/src/epicli/data/common/ansible/playbooks/roles/upgrade/tasks/filebeat.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,62 @@ | ||
--- | ||
- name: Filebeat | Get information about installed packages as facts | ||
- name: Filebeat as DaemonSet | Prepare fact about helm release | ||
delegate_to: localhost | ||
become: false | ||
run_once: true | ||
block: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❤️ |
||
- name: Get information about helm releases | ||
command: helm list --output json | ||
register: helm_list | ||
|
||
- name: Check if filebeat release exist in default namespace and set fact | ||
set_fact: | ||
filebeat_release_exists: >- | ||
{{ _names | ternary(true, false) }} | ||
vars: | ||
_names: >- | ||
{{ helm_list.stdout | from_json | ||
| map(attribute='name') | ||
| select('==', specification.helm_chart_name) | ||
| list }} | ||
|
||
- name: Reinstall Filebeat as DaemonSet from default namespace to custom namespace for "k8s as cloud service" | ||
when: | ||
- filebeat_release_exists | ||
- k8s_as_cloud_service is defined | ||
- k8s_as_cloud_service | ||
block: | ||
- name: Include uninstall task for Filebeat as DaemonSet in default namespace for "k8s as cloud service" | ||
include_role: | ||
name: filebeat | ||
tasks_from: uninstall-filebeat-as-daemonset.yml | ||
|
||
- name: Include install task for Filebeat as DaemonSet in custom namespace for "k8s as cloud service" | ||
include_role: | ||
name: filebeat | ||
tasks_from: install-filebeat-as-daemonset.yml | ||
|
||
- name: Filebeat as System Service | Get information about installed packages as facts | ||
package_facts: | ||
manager: auto | ||
when: ansible_facts.packages is undefined | ||
|
||
- name: Filebeat | Test if filebeat package is installed | ||
- name: Filebeat as System Service | Test if filebeat package is installed | ||
assert: | ||
that: ansible_facts.packages['filebeat'] is defined | ||
fail_msg: filebeat package not found, nothing to update | ||
quiet: true | ||
|
||
- name: Filebeat | Print versions | ||
- name: Filebeat as System Service | Print versions | ||
debug: | ||
msg: | ||
- "Installed version: {{ ansible_facts.packages['filebeat'][0].version }}" | ||
- "Target version: {{ filebeat_version }}" | ||
|
||
- name: Update Filebeat | ||
- name: Update Filebeat as System Service | ||
when: | ||
- filebeat_version is version(ansible_facts.packages['filebeat'][0].version, '>=') | ||
block: | ||
- name: Filebeat | Backup configuration file (filebeat.yml) | ||
- name: Filebeat as System Service | Backup configuration file (filebeat.yml) | ||
copy: | ||
remote_src: true | ||
src: /etc/filebeat/filebeat.yml | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,4 @@ | ||
--- | ||
- name: Node Exporter | Populate service facts | ||
service_facts: | ||
when: ansible_facts.services is undefined | ||
|
||
- name: Node Exporter | Include defaults from node_exporter role | ||
include_vars: | ||
file: roles/node_exporter/defaults/main.yml | ||
|
@@ -11,32 +7,72 @@ | |
include_vars: | ||
file: roles/node_exporter/vars/main.yml | ||
|
||
- name: Node Exporter | Test if node exporter service is configured | ||
- name: Node Exporter as DaemonSet | Prepare fact about helm release | ||
delegate_to: localhost | ||
become: false | ||
run_once: true | ||
block: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❤️ |
||
- name: Get information about helm releases | ||
command: helm list --output json | ||
register: helm_list | ||
|
||
- name: Check if node exporter release exist in default namespace and set fact | ||
set_fact: | ||
node_exporter_release_exists: >- | ||
{{ _names | ternary(true, false) }} | ||
vars: | ||
_names: >- | ||
{{ helm_list.stdout | from_json | ||
| map(attribute='name') | ||
| select('==', specification.helm_chart_name) | ||
| list }} | ||
|
||
- name: Reinstall Node Exporter as DaemonSet from default namespace to custom namespace for "k8s as cloud service" | ||
when: | ||
- node_exporter_release_exists | ||
- k8s_as_cloud_service is defined | ||
- k8s_as_cloud_service | ||
block: | ||
- name: Include uninstall task for Node Exporter as DaemonSet in default namespace for "k8s as cloud service" | ||
include_role: | ||
name: node_exporter | ||
tasks_from: uninstall-node-exporter-as-daemonset.yml | ||
|
||
- name: Include install task for Node Exporter as DaemonSet in custom namespace for "k8s as cloud service" | ||
include_role: | ||
name: node_exporter | ||
tasks_from: install-node-exporter-as-daemonset.yml | ||
|
||
- name: Node Exporter as System Service | Populate service facts | ||
service_facts: | ||
when: ansible_facts.services is undefined | ||
|
||
- name: Node Exporter as System Service | Test if node exporter service is configured | ||
assert: | ||
that: "'{{ exporter.service.name }}.service' in ansible_facts.services" | ||
fail_msg: "{{ exporter.service.name }} service is not found" | ||
quiet: true | ||
|
||
- name: Node Exporter | Set exporter_file_name fact | ||
- name: Node Exporter as System Service | Set exporter_file_name fact | ||
set_fact: | ||
exporter_file_name: "node_exporter-{{ exporter.version }}.linux-amd64.tar.gz" | ||
|
||
- name: Node Exporter | Collect version | ||
- name: Node Exporter as System Service | Collect version | ||
shell: >- | ||
/opt/node_exporter/node_exporter --version 2>&1 | ||
register: exporter_current_version_out | ||
|
||
- name: Node Exporter | Set exporter_current_version fact | ||
- name: Node Exporter as System Service | Set exporter_current_version fact | ||
set_fact: | ||
exporter_current_version: "{{ exporter_current_version_out.stdout_lines[0] | regex_replace('^.*version ([0-9.]+) .*$', '\\1') }}" | ||
|
||
- name: Node Exporter | Print version | ||
- name: Node Exporter as System Service | Print version | ||
debug: | ||
msg: | ||
- "Installed version: {{ exporter_current_version }}" | ||
- "Target version: {{ exporter.version }}" | ||
|
||
- name: Node Exporter | Upgrade block | ||
- name: Node Exporter as System Service | Upgrade block | ||
when: exporter.version != exporter_current_version | ||
block: | ||
- name: Node Exporter | Download binaries | ||
|
@@ -46,25 +82,25 @@ | |
vars: | ||
file_name: "{{ exporter_file_name }}" | ||
|
||
- name: Node Exporter | Stop exporter | ||
- name: Node Exporter as System Service | Stop exporter | ||
systemd: | ||
name: "{{ exporter.service.name }}.service" | ||
state: stopped | ||
|
||
- name: Node Exporter | Remove /opt/node_exporter directory | ||
- name: Node Exporter as System Service | Remove /opt/node_exporter directory | ||
file: | ||
path: /opt/node_exporter | ||
state: absent | ||
|
||
- name: Node Exporter | Create empty /opt/node_exporter directory | ||
- name: Node Exporter as System Service | Create empty /opt/node_exporter directory | ||
file: | ||
path: /opt/node_exporter | ||
owner: root | ||
group: node_exporter | ||
mode: '0750' | ||
state: directory | ||
|
||
- name: Node Exporter | Unpack binary | ||
- name: Node Exporter as System Service | Unpack binary | ||
unarchive: | ||
remote_src: true | ||
src: "{{ download_directory }}/{{ exporter_file_name }}" | ||
|
@@ -76,15 +112,15 @@ | |
group: node_exporter | ||
check_mode: false | ||
|
||
- name: Node Exporter | Update systemd service configuration | ||
- name: Node Exporter as System Service | Update systemd service configuration | ||
template: | ||
src: roles/node_exporter/templates/prometheus-node-exporter.service.j2 | ||
dest: "/etc/systemd/system/{{ exporter.service.name }}.service" | ||
owner: root | ||
group: root | ||
mode: '0644' | ||
|
||
- name: Node Exporter | Start exporter | ||
- name: Node Exporter as System Service | Start exporter | ||
systemd: | ||
daemon_reload: true | ||
enabled: true | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't it be configurable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We've decided to keep it in defaults for now. After this refactor #1756 it will be easier to properly implement upgrades for this case.