Skip to content

Commit 1f86f4a

Browse files
feat(archives): support for archives file format
BREAKING CHANGE: the parameter `pkg` is now a dictionary. References to `prometheus.pkg` should be changed to `prometheus.pkg.name`.
1 parent ea84c92 commit 1f86f4a

23 files changed

+236
-17
lines changed

docs/README.rst

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,21 @@ This installs the prometheus package,
4848
manages the prometheus configuration file and then
4949
starts the associated prometheus service.
5050

51+
``prometheus.archive``
52+
^^^^^^^^^^^^^^^^^^^^
53+
54+
This state will install the prometheus from archive file only.
55+
5156
``prometheus.package``
5257
^^^^^^^^^^^^^^^^^^^^
5358

5459
This state will install the prometheus package only.
5560

61+
``prometheus.package.repo``
62+
^^^^^^^^^^^^^^^^^^^^^^^^^
63+
64+
This state will install the prometheus package only.
65+
5666
``prometheus.config``
5767
^^^^^^^^^^^^^^^^^^^
5868

@@ -92,6 +102,16 @@ dependency on ``prometheus.service.clean`` via include list.
92102
This state will remove the prometheus package and has a depency on
93103
``prometheus.config.clean`` via include list.
94104

105+
``prometheus.package.archive.clean``
106+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
107+
108+
This state will uninstall the prometheus archive-extracted directory only.
109+
110+
``prometheus.package.repo.clean``
111+
^^^^^^^^^^^^^^^^^^^^^^^^^
112+
113+
This state will uninstall the prometheus upstream package repository only.
114+
95115
``prometheus.exporters``
96116
^^^^^^^^^^^^^^^^^^^^^^^^
97117

pillar.example

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,14 @@
22
# vim: ft=yaml
33
---
44
prometheus:
5-
pkg: prometheus
5+
pkg:
6+
name: prometheus
7+
archive:
8+
source: https://github.com/prometheus/prometheus/releases/download/v2.10.0/prometheus-2.10.0.linux-amd64.tar.gz
9+
source_hash: f4233783826f18606b79e5cef0686e4a9c2030146a3c7ce134f0add09f5adcb7
10+
enforce_toplevel: False
611
config_file: /etc/prometheus/prometheus.yml
12+
environ_file: /etc/default/prometheus.sh
713
service:
814
name: prometheus
915
args:
@@ -33,6 +39,8 @@ prometheus:
3339
# - 'example_alt.tmpl.jinja'
3440

3541
# Pillar-based config
42+
environ:
43+
- 'export PATH=${PATH}:/opt/prometheus-2.10.0.linux-amd64'
3644
config:
3745
# my global config
3846
global:

prometheus/archive/clean.sls

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# -*- coding: utf-8 -*-
2+
# vim: ft=sls
3+
4+
{#- Get the `tplroot` from `tpldir` #}
5+
{%- set tplroot = tpldir.split('/')[0] %}
6+
{%- from tplroot ~ "/map.jinja" import prometheus with context %}
7+
8+
prometheus-cli-package-archive-clean-file-absent:
9+
file.absent:
10+
- names:
11+
- {{ prometheus.base_dir }}

prometheus/archive/init.sls

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#.-*- coding: utf-8 -*-
2+
# vim: ft=sls
3+
4+
include:
5+
- .install

prometheus/archive/install.sls

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# -*- coding: utf-8 -*-
2+
# vim: ft=sls
3+
4+
{#- Get the `tplroot` from `tpldir` #}
5+
{%- set tplroot = tpldir.split('/')[0] %}
6+
{%- from tplroot ~ "/map.jinja" import prometheus with context %}
7+
{%- from tplroot ~ "/jinja/macros.jinja" import format_kwargs with context %}
8+
9+
prometheus-package-archive-install-file-directory:
10+
file.directory:
11+
- name: {{ prometheus.pkg.archive.name }}
12+
- makedirs: True
13+
- require_in:
14+
- archive: prometheus-package-archive-install-archive-extracted
15+
16+
prometheus-package-archive-install-archive-extracted:
17+
archive.extracted:
18+
{{- format_kwargs(prometheus.pkg.archive) }}
19+
- retry:
20+
attempts: 3
21+
until: True
22+
interval: 60
23+
splay: 10

prometheus/clean.sls

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@
44
include:
55
- .service.clean
66
- .config.clean
7+
- .archive.clean
78
- .package.clean

prometheus/config/clean.sls

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ include:
1111
1212
prometheus-config-clean-file-absent:
1313
file.absent:
14-
- name: {{ prometheus.config_file }}
14+
- names:
15+
- {{ prometheus.config_file }}
16+
- {{ prometheus.environ_file }}
1517
- require:
1618
- sls: {{ sls_service_clean }}
1719

prometheus/config/environ.sls

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# -*- coding: utf-8 -*-
2+
# vim: ft=sls
3+
4+
{#- Get the `tplroot` from `tpldir` #}
5+
{%- set tplroot = tpldir.split('/')[0] %}
6+
{%- from tplroot ~ "/map.jinja" import prometheus with context %}
7+
{%- set sls_archive_install = tplroot ~ '.archive.install' %}
8+
{%- from tplroot ~ "/libtofs.jinja" import files_switch with context %}
9+
10+
include:
11+
- {{ sls_archive_install }}
12+
13+
prometheus-config-file-file-managed-environ_file:
14+
file.managed:
15+
- name: {{ prometheus.environ_file }}
16+
- source: {{ files_switch(['prometheus.sh.jinja'],
17+
lookup='prometheus-config-file-file-managed-environ_file'
18+
)
19+
}}
20+
- mode: 644
21+
- user: root
22+
- group: {{ prometheus.rootgroup }}
23+
- makedirs: True
24+
- template: jinja
25+
- context:
26+
prometheus: {{ prometheus|json }}
27+
- require:
28+
- sls: {{ sls_archive_install }}

prometheus/config/file.sls

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,24 @@
33

44
{#- Get the `tplroot` from `tpldir` #}
55
{%- set tplroot = tpldir.split('/')[0] %}
6-
{%- set sls_package_install = tplroot ~ '.package.install' %}
76
{%- from tplroot ~ "/map.jinja" import prometheus with context %}
87
{%- from tplroot ~ "/libtofs.jinja" import files_switch with context %}
98
9+
{%- if 'config' in prometheus and prometheus.config %}
10+
{%- if prometheus.pkg.use_upstream_archive %}
11+
{%- set sls_package_install = tplroot ~ '.archive.install' %}
12+
{%- else %}
13+
{%- set sls_package_install = tplroot ~ '.package.install' %}
14+
{%- endif %}
15+
1016
include:
1117
- {{ sls_package_install }}
1218
13-
prometheus-config-file-file-managed:
19+
prometheus-config-file-file-managed-config_file:
1420
file.managed:
1521
- name: {{ prometheus.config_file }}
1622
- source: {{ files_switch(['prometheus.yml.jinja'],
17-
lookup='prometheus-config-file-file-managed'
23+
lookup='prometheus-config-file-file-managed-config_file'
1824
)
1925
}}
2026
- mode: 644
@@ -26,3 +32,5 @@ prometheus-config-file-file-managed:
2632
config: {{ prometheus.config|json }}
2733
- require:
2834
- sls: {{ sls_package_install }}
35+
36+
{%- endif %}

prometheus/config/init.sls

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44
include:
55
- .args
66
- .file
7+
- .environ

0 commit comments

Comments
 (0)