From b9b2e42ad2e6c517b07bb11eefad8fc992df1d16 Mon Sep 17 00:00:00 2001 From: Georg Pfuetzenreuter Date: Wed, 15 Feb 2023 01:57:08 +0100 Subject: [PATCH] feat(suse): support packaged installations - add all components available in the default openSUSE Leap (OSS) repository to osfamilymap - introduce global manage_user_group toggle to prevent the formula from changing users and groups managed by system packages Signed-off-by: Georg Pfuetzenreuter --- prometheus/config/file.sls | 8 +++ prometheus/config/storage.sls | 2 + prometheus/config/users.sls | 2 + prometheus/defaults.yaml | 2 + .../textfile_collectors/init.sls | 2 + prometheus/osfamilymap.yaml | 61 ++++++++++++++++++- prometheus/service/args/install.sls | 2 + test/salt/pillar/repo.sls | 8 ++- 8 files changed, 85 insertions(+), 2 deletions(-) diff --git a/prometheus/config/file.sls b/prometheus/config/file.sls index ccd3abd..0a5b405 100644 --- a/prometheus/config/file.sls +++ b/prometheus/config/file.sls @@ -40,15 +40,19 @@ prometheus-config-file-{{ name }}-file-managed: - template: jinja {%- if grains.os != 'Windows' %} - mode: 644 + {%- if p.manage_user_group %} - user: {{ name }} - group: {{ name }} {%- endif %} + {%- endif %} - context: config: {{ p.pkg.component[name]['config']|json }} - require: - file: prometheus-config-file-etc-file-directory + {%- if p.manage_user_group %} - user: prometheus-config-users-install-{{ name }}-user-present - group: prometheus-config-users-install-{{ name }}-group-present + {%- endif %} - watch_in: - service: prometheus-service-running-{{ name }} @@ -71,15 +75,19 @@ prometheus-config-file-{{ ef }}-file-managed: - template: jinja {%- if grains.os != 'Windows' %} - mode: 644 + {%- if p.manage_user_group %} - user: {{ component }} - group: {{ component }} {%- endif %} + {%- endif %} - context: config: {{ p.extra_files[ef]['config'] }} - require: - file: prometheus-config-file-etc-file-directory + {%- if p.manage_user_group %} - user: prometheus-config-users-install-{{ component }}-user-present - group: prometheus-config-users-install-{{ component }}-group-present + {%- endif %} - watch_in: - service: prometheus-service-running-{{ component }} diff --git a/prometheus/config/storage.sls b/prometheus/config/storage.sls index 2674106..39c1f3d 100644 --- a/prometheus/config/storage.sls +++ b/prometheus/config/storage.sls @@ -24,9 +24,11 @@ prometheus-service-args-{{ name }}-data-dir: - makedirs: True - watch_in: - service: prometheus-service-running-{{ name }} + {%- if p.manage_user_group %} - require: - user: prometheus-config-users-install-{{ name }}-user-present - group: prometheus-config-users-install-{{ name }}-group-present + {%- endif %} {%- endif %} {% endif %} diff --git a/prometheus/config/users.sls b/prometheus/config/users.sls index 2938adb..291c04f 100644 --- a/prometheus/config/users.sls +++ b/prometheus/config/users.sls @@ -4,6 +4,7 @@ {%- set tplroot = tpldir.split('/')[0] %} {%- from tplroot ~ "/map.jinja" import prometheus as p with context %} + {%- if p.manage_user_group or p.pkg.use_upstream_archive %} {%- for name in p.wanted.component %} prometheus-config-users-install-{{ name }}-group-present: @@ -29,3 +30,4 @@ prometheus-config-users-install-{{ name }}-user-present: {%- endif %} {%- endfor %} + {%- endif %} diff --git a/prometheus/defaults.yaml b/prometheus/defaults.yaml index 1f2a70a..645822d 100644 --- a/prometheus/defaults.yaml +++ b/prometheus/defaults.yaml @@ -23,6 +23,8 @@ prometheus: tmp: /tmp/prometheus var: /var/lib/prometheus + manage_user_group: true + pkg: uri: https://github.com/prometheus use_upstream_repo: false diff --git a/prometheus/exporters/node_exporter/textfile_collectors/init.sls b/prometheus/exporters/node_exporter/textfile_collectors/init.sls index 4ea4f71..dc21ad1 100644 --- a/prometheus/exporters/node_exporter/textfile_collectors/init.sls +++ b/prometheus/exporters/node_exporter/textfile_collectors/init.sls @@ -22,9 +22,11 @@ prometheus-exporters-{{ name }}-collector-textfile-dir: - group: {{ name }} {%- endif %} - makedirs: True + {%- if p.manage_user_group %} - require: - user: prometheus-config-users-install-{{ name }}-user-present - group: prometheus-config-users-install-{{ name }}-group-present + {%- endif %} {%- endif %} {%- for k, v in p.get('exporters', {}).get(name, {}).get('textfile_collectors', {}).items() %} diff --git a/prometheus/osfamilymap.yaml b/prometheus/osfamilymap.yaml index 9525d2a..7873c93 100644 --- a/prometheus/osfamilymap.yaml +++ b/prometheus/osfamilymap.yaml @@ -219,7 +219,66 @@ RedHat: sslcacert: /etc/pki/tls/certs/ca-bundle.crt metadata_expire: 300 -Suse: {} +Suse: + manage_user_group: false + pkg: + use_upstream_repo: false + use_upstream_package: false + use_upstream_archive: false + component: + alertmanager: + name: golang-github-prometheus-alertmanager + service: + name: prometheus-alertmanager + environ_file: /etc/sysconfig/prometheus-alertmanager + args: + config.file: /etc/prometheus/alertmanager.yml + config_file: /etc/prometheus/alertmanager.yml + prometheus: + name: golang-github-prometheus-prometheus + service: + name: prometheus + environ_file: /etc/sysconfig/prometheus + environ: + environ_arg_name: ARGS + config_file: /etc/prometheus/prometheus.yml + blackbox_exporter: + name: prometheus-blackbox_exporter + config_file: /etc/prometheus/blackbox.yml + service: + name: prometheus-blackbox_exporter + hacluster_exporter: + name: prometheus-ha_cluster_exporter + environ_file: /etc/sysconfig/prometheus-ha_cluster_exporter + environ: + environ_arg_name: ARGS + service: + name: prometheus-ha_cluster_exporter + node_exporter: + name: golang-github-prometheus-node_exporter + service: + name: prometheus-node_exporter + environ_file: /etc/sysconfig/prometheus-node_exporter + environ: + environ_arg_name: ARGS + postgres_exporter: + name: prometheus-postgres_exporter + service: + name: prometheus-postgres_exporter + environ_file: /etc/sysconfig/prometheus-postgres_exporter + environ: + environ_arg_name: POSTGRES_EXPORTER_PARAMS + saptune_exporter: + name: prometheus-saptune_exporter + service: + name: prometheus-saptune_exporter + webhook_snmp: + name: prometheus-webhook-snmp + service: + name: prometheus-webhook-snmp + environ_file: /etc/default/prometheus-webhook-snmp + environ: + environ_arg_name: PROMETHEUS_WEBHOOK_SNMP_OPTIONS Gentoo: pkg: diff --git a/prometheus/service/args/install.sls b/prometheus/service/args/install.sls index 71e364e..af6d3ba 100644 --- a/prometheus/service/args/install.sls +++ b/prometheus/service/args/install.sls @@ -30,9 +30,11 @@ prometheus-service-args-{{ name }}-data-dir: - makedirs: True - watch_in: - service: prometheus-service-running-{{ name }} + {%- if p.manage_user_group %} - require: - user: prometheus-config-users-install-{{ name }}-user-present - group: prometheus-config-users-install-{{ name }}-group-present + {%- endif %} {%- endif %} {%- if grains.os_family == 'FreeBSD' %} diff --git a/test/salt/pillar/repo.sls b/test/salt/pillar/repo.sls index e2cdd27..71b2776 100644 --- a/test/salt/pillar/repo.sls +++ b/test/salt/pillar/repo.sls @@ -13,6 +13,12 @@ prometheus: - alertmanager - node_exporter - blackbox_exporter + {%- if grains.os == 'SUSE' %} + - hacluster_exporter + - postgres_exporter + - saptune_exporter + - webhook_snmp + {%- endif %} exporters: node_exporter: @@ -31,7 +37,7 @@ prometheus: pkg: # yamllint disable-line rule:braces rule:commas - use_upstream_repo: {{ false if grains.os_family|lower in ('debian',) else true }} + use_upstream_repo: {{ false if grains.os_family|lower in ('debian','suse',) else true }} use_upstream_archive: false clientlibs: