blob: 5a8228bc41410945c92da686daad902cc19c9ccf (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
|
---
# set facts
- include_tasks: facts.yaml
- name: Ensure that Prometheus has nodes to run on
fail:
msg: |-
No schedulable nodes found matching node selector for Prometheus - '{{ openshift_prometheus_node_selector }}'
when:
- openshift_schedulable_node_labels | lib_utils_oo_has_no_matching_selector(openshift_prometheus_node_selector)
# namespace
- name: Add prometheus project
oc_project:
state: present
name: "{{ openshift_prometheus_namespace }}"
node_selector: "{{ openshift_prometheus_node_selector | lib_utils_oo_selector_to_string_list() }}"
description: Prometheus
# secrets
- name: Set alert, alertmanager and prometheus secrets
oc_secret:
state: present
name: "{{ item }}-proxy"
namespace: "{{ openshift_prometheus_namespace }}"
contents:
- path: session_secret
data: "{{ 43 | lib_utils_oo_random_word }}="
with_items:
- prometheus
- alerts
- alertmanager
# serviceaccount
- name: create prometheus serviceaccount
oc_serviceaccount:
state: present
name: "{{ openshift_prometheus_service_name }}"
namespace: "{{ openshift_prometheus_namespace }}"
changed_when: no
# TODO remove this when annotations are supported by oc_serviceaccount
- name: annotate serviceaccount
command: >
{{ openshift_client_binary }} annotate --overwrite -n {{ openshift_prometheus_namespace }}
serviceaccount {{ openshift_prometheus_service_name }} {{ item }}
with_items:
"{{ openshift_prometheus_serviceaccount_annotations }}"
# create clusterrolebinding for prometheus serviceaccount
- name: Set cluster-reader permissions for prometheus
oc_adm_policy_user:
state: present
namespace: "{{ openshift_prometheus_namespace }}"
resource_kind: cluster-role
resource_name: cluster-reader
user: "system:serviceaccount:{{ openshift_prometheus_namespace }}:{{ openshift_prometheus_service_name }}"
- name: create services for prometheus
oc_service:
name: "{{ openshift_prometheus_service_name }}"
namespace: "{{ openshift_prometheus_namespace }}"
labels:
name: prometheus
annotations:
oprometheus.io/scrape: 'true'
oprometheus.io/scheme: https
service.alpha.openshift.io/serving-cert-secret-name: prometheus-tls
ports:
- name: prometheus
port: "{{ openshift_prometheus_service_port }}"
targetPort: "{{ openshift_prometheus_service_targetport }}"
protocol: TCP
selector:
app: prometheus
- name: create services for alert buffer
oc_service:
name: "{{ openshift_prometheus_alerts_service_name }}"
namespace: "{{ openshift_prometheus_namespace }}"
labels:
name: prometheus
annotations:
service.alpha.openshift.io/serving-cert-secret-name: alerts-tls
ports:
- name: prometheus
port: "{{ openshift_prometheus_service_port }}"
targetPort: "{{ openshift_prometheus_alerts_service_targetport }}"
protocol: TCP
selector:
app: prometheus
- name: create services for alertmanager
oc_service:
name: "{{ openshift_prometheus_alertmanager_service_name }}"
namespace: "{{ openshift_prometheus_namespace }}"
labels:
name: prometheus
annotations:
service.alpha.openshift.io/serving-cert-secret-name: alertmanager-tls
ports:
- name: prometheus
port: "{{ openshift_prometheus_service_port }}"
targetPort: "{{ openshift_prometheus_alertmanager_service_targetport }}"
protocol: TCP
selector:
app: prometheus
# create prometheus and alerts routes
# TODO: oc_route module should support insecureEdgeTerminationPolicy: Redirect
- name: create prometheus and alerts routes
oc_route:
state: present
name: "{{ item.name }}"
host: "{{ item.host }}"
namespace: "{{ openshift_prometheus_namespace }}"
service_name: "{{ item.name }}"
tls_termination: reencrypt
with_items:
- name: prometheus
host: "{{ openshift_prometheus_hostname }}"
- name: alerts
host: "{{ openshift_prometheus_alerts_hostname }}"
- name: alertmanager
host: "{{ openshift_prometheus_alertmanager_hostname }}"
# Storage
- name: create prometheus pvc
oc_pvc:
namespace: "{{ openshift_prometheus_namespace }}"
name: "{{ openshift_prometheus_pvc_name }}"
access_modes: "{{ openshift_prometheus_pvc_access_modes }}"
volume_capacity: "{{ openshift_prometheus_pvc_size }}"
selector: "{{ openshift_prometheus_pvc_pv_selector }}"
storage_class_name: "{{ openshift_prometheus_sc_name }}"
when: openshift_prometheus_storage_type == 'pvc'
- name: create alertmanager pvc
oc_pvc:
namespace: "{{ openshift_prometheus_namespace }}"
name: "{{ openshift_prometheus_alertmanager_pvc_name }}"
access_modes: "{{ openshift_prometheus_alertmanager_pvc_access_modes }}"
volume_capacity: "{{ openshift_prometheus_alertmanager_pvc_size }}"
selector: "{{ openshift_prometheus_alertmanager_pvc_pv_selector }}"
storage_class_name: "{{ openshift_prometheus_alertmanager_sc_name }}"
when: openshift_prometheus_alertmanager_storage_type == 'pvc'
- name: create alertbuffer pvc
oc_pvc:
namespace: "{{ openshift_prometheus_namespace }}"
name: "{{ openshift_prometheus_alertbuffer_pvc_name }}"
access_modes: "{{ openshift_prometheus_alertbuffer_pvc_access_modes }}"
volume_capacity: "{{ openshift_prometheus_alertbuffer_pvc_size }}"
selector: "{{ openshift_prometheus_alertbuffer_pvc_pv_selector }}"
storage_class_name: "{{ openshift_prometheus_alertbuffer_sc_name }}"
when: openshift_prometheus_alertbuffer_storage_type == 'pvc'
# prometheus configmap
# Copy the additional rules file if it is defined
- name: Copy additional rules file to host
copy:
src: "{{ openshift_prometheus_additional_rules_file }}"
dest: "{{ tempdir }}/prometheus.additional.rules"
when:
- openshift_prometheus_additional_rules_file is defined
- openshift_prometheus_additional_rules_file is not none
- openshift_prometheus_additional_rules_file | trim | length > 0
- stat:
path: "{{ tempdir }}/prometheus.additional.rules"
register: additional_rules_stat
- template:
src: prometheus.yml.j2
dest: "{{ tempdir }}/prometheus.yml"
changed_when: no
- template:
src: prometheus.rules.j2
dest: "{{ tempdir }}/prometheus.rules"
changed_when: no
# In prometheus configmap create "additional.rules" section if file exists
- name: Set prometheus configmap
oc_configmap:
state: present
name: "prometheus"
namespace: "{{ openshift_prometheus_namespace }}"
from_file:
prometheus.rules: "{{ tempdir }}/prometheus.rules"
prometheus.additional.rules: "{{ tempdir }}/prometheus.additional.rules"
prometheus.yml: "{{ tempdir }}/prometheus.yml"
when: additional_rules_stat.stat.exists == True
- name: Set prometheus configmap
oc_configmap:
state: present
name: "prometheus"
namespace: "{{ openshift_prometheus_namespace }}"
from_file:
prometheus.rules: "{{ tempdir }}/prometheus.rules"
prometheus.yml: "{{ tempdir }}/prometheus.yml"
when: additional_rules_stat.stat.exists == False
# alertmanager configmap
- template:
src: alertmanager.yml.j2
dest: "{{ tempdir }}/alertmanager.yml"
changed_when: no
- name: Set alertmanager configmap
oc_configmap:
state: present
name: "alertmanager"
namespace: "{{ openshift_prometheus_namespace }}"
from_file:
alertmanager.yml: "{{ tempdir }}/alertmanager.yml"
# create prometheus stateful set
- name: Set prometheus template
template:
src: prometheus.j2
dest: "{{ tempdir }}/templates/prometheus.yaml"
vars:
namespace: "{{ openshift_prometheus_namespace }}"
# prom_replicas: "{{ openshift_prometheus_replicas }}"
- name: Set prometheus stateful set
oc_obj:
state: present
name: "prometheus"
namespace: "{{ openshift_prometheus_namespace }}"
kind: statefulset
files:
- "{{ tempdir }}/templates/prometheus.yaml"
delete_after: true
|