476ab4f0c8b14c49ba1894547cb49482e0af3036
[osm/devops.git] / installers / helm / osm / templates / prometheus / prometheus-statefulset.yaml
1 {{- if .Values.prometheus.enabled -}}
2 #######################################################################################
3 # Copyright ETSI Contributors and Others.
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 #    http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
14 # implied.
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
17 #######################################################################################
18 apiVersion: apps/v1
19 kind: StatefulSet
20 metadata:
21   name: prometheus
22   labels:
23     {{- include "osm.labels" . | nindent 4 }}
24 spec:
25   replicas: {{ .Values.prometheus.replicaCount | default .Values.global.replicaCount }}
26   serviceName: prometheus
27   selector:
28     matchLabels:
29       app.kubernetes.io/component: prometheus
30       {{- include "osm.selectorLabels" . | nindent 6 }}
31   template:
32     metadata:
33       {{- with .Values.global.podAnnotations }}
34       annotations:
35         {{- toYaml . | nindent 8 }}
36       {{- end }}
37       labels:
38         app.kubernetes.io/component: prometheus
39         {{- include "osm.selectorLabels" . | nindent 8 }}
40     spec:
41       {{- with .Values.global.imagePullSecrets }}
42       imagePullSecrets:
43         {{- toYaml . | nindent 8 }}
44       {{- end }}
45       serviceAccountName: {{ include "osm.serviceAccountName" . }}
46       initContainers:
47         - name: prometheus-init-config
48           image: busybox
49           command: ["/bin/sh", "-c"]
50 {{- if .Values.global.oldServiceAssurance }}
51           args: ['if [ ! -f "/etc/prometheus/prometheus.yml" ]; then cp /config/prometheus.yml /etc/prometheus; fi']
52 {{- else }}
53           args: ['if [ ! -f "/etc/prometheus/prometheus.yml" ]; then cp /config/prometheus.yml /etc/prometheus; fi; cp /config/osm_metric_rules.yml /config/osm_alert_rules.yml /etc/prometheus']
54 {{- end }}
55           volumeMounts:
56             - name: prom-config
57               mountPath: /etc/prometheus
58             - name: prom-config-base
59               mountPath: /config
60       containers:
61         - name: prometheus
62           securityContext:
63             # readOnlyRootFilesystem: true
64             allowPrivilegeEscalation: false
65             # runAsNonRoot: true
66           image: prom/prometheus:v2.28.1
67           imagePullPolicy: {{ .Values.global.image.pullPolicy }}
68           args:
69             - --config.file=/etc/prometheus/prometheus.yml
70             - --web.enable-lifecycle
71           ports:
72             - containerPort: 9090
73               protocol: TCP
74           volumeMounts:
75             - name: prom-config
76               mountPath: /etc/prometheus
77             - name: prom-db
78               mountPath: /prometheus
79           resources:
80             limits:
81               memory: 1024Mi
82             requests:
83               memory: 128Mi
84         - name: prometheus-config-sidecar
85           securityContext:
86             # readOnlyRootFilesystem: true
87             allowPrivilegeEscalation: false
88             # runAsNonRoot: true
89           image: {{ include "osm.prometheus.image" . }}
90           imagePullPolicy: {{ .Values.global.image.pullPolicy }}
91           volumeMounts:
92             - name: prom-config
93               mountPath: /etc/prometheus
94             - name: prom-config-base
95               mountPath: /etc/prometheus_base
96           resources:
97             limits:
98               memory: 1024Mi
99             requests:
100               memory: 128Mi
101           envFrom:
102             - configMapRef:
103                 name: {{ include "osm.fullname" . }}-prometheus-configmap
104       {{- with .Values.global.nodeSelector }}
105       nodeSelector:
106         {{- toYaml . | nindent 8 }}
107       {{- end }}
108       {{- with .Values.global.affinity }}
109       affinity:
110         {{- toYaml . | nindent 8 }}
111       {{- end }}
112       {{- with .Values.global.tolerations }}
113       tolerations:
114         {{- toYaml . | nindent 8 }}
115       {{- end }}
116       volumes:
117         - name: prom-db
118           emptyDir: {}
119         - name: prom-config
120           emptyDir: {}
121         - name: prom-config-base
122           projected:
123             sources:
124               - configMap:
125                  name: {{ include "osm.fullname" . }}-prometheus-prom-configmap
126                  items:
127                    - key: prometheus.yml
128                      path: prometheus.yml
129 {{- if not .Values.global.oldServiceAssurance }}
130               - configMap:
131                  name: {{ include "osm.fullname" . }}-prometheus-recordingrules-configmap
132                  items:
133                    - key: osm_metric_rules.yml
134                      path: osm_metric_rules.yml
135               - configMap:
136                  name: {{ include "osm.fullname" . }}-prometheus-alertingrules-configmap
137                  items:
138                    - key: osm_alert_rules.yml
139                      path: osm_alert_rules.yml
140 {{- end }}
141 {{- end }}