apiVersion: {{ include "statefulsetversion" . }}
kind: StatefulSet
metadata:
  name: prometheus
  namespace: {{ .Release.Namespace }}
  labels:
    app: prometheus
    role: monitoring
spec:
  replicas: 0
  updateStrategy:
    type: RollingUpdate
  selector:
    matchLabels:
      app: prometheus
      role: monitoring
  serviceName: prometheus
  template:
    metadata:
      labels:
        app: prometheus
        role: monitoring
    spec:
      # used to talk to Seed's API server.
      serviceAccountName: prometheus
      containers:
      - name: prometheus
        image: {{ index .Values.global.images "prometheus" }}
        imagePullPolicy: IfNotPresent
        command: ["/bin/sh","-c"]
        args:
          - rm -rf /var/prometheus/data/*; /bin/prometheus
            --config.file=/etc/prometheus/config/prometheus.yaml
            --storage.tsdb.path=/var/prometheus/data
            --storage.tsdb.no-lockfile
            --storage.tsdb.retention.time=2h
            --storage.tsdb.retention.size=1GB
            --web.listen-address=0.0.0.0:{{ .Values.prometheus.port }}
            --web.enable-lifecycle
        # Since v2.0.0-beta.3 prometheus runs as nobody user (fsGroup 65534/runAsUser 0)
        # data volume needs to be mounted with the same permissions,
        # otherwise we will have Permission denied problems
        securityContext:
          runAsUser: 0
        livenessProbe:
          httpGet:
            path: /-/healthy
            port: {{ .Values.prometheus.port }}
            scheme: HTTP
          failureThreshold: 60
          periodSeconds: 5
          successThreshold: 1
          timeoutSeconds: 3
        readinessProbe:
          httpGet:
            path: /-/ready
            port: {{ .Values.prometheus.port }}
            scheme: HTTP
          failureThreshold: 120
          periodSeconds: 5
          successThreshold: 1
          timeoutSeconds: 3
        resources:
          requests:
            cpu: 30m
            memory: 500Mi
        volumeMounts:
        - mountPath: /etc/prometheus/config
          name: config
          readOnly: true
        - mountPath: /etc/prometheus/rules
          name: rules
          readOnly: true
        - mountPath: /var/prometheus/data
          name: prometheus-db
          subPath: prometheus-
      - name: prometheus-config-reloader
        image: {{ index .Values.global.images "configmap-reloader" }}
        imagePullPolicy: IfNotPresent
        args:
        - -webhook-url=http://localhost:{{ .Values.prometheus.port }}/-/reload
        - -volume-dir=/etc/prometheus/config
        - -volume-dir=/etc/prometheus/rules
        resources:
          requests:
            cpu: 5m
            memory: 10Mi
          limits:
            cpu: 10m
            memory: 20Mi
        volumeMounts:
        - mountPath: /etc/prometheus/config
          name: config
          readOnly: true
        - mountPath: /etc/prometheus/rules
          name: rules
          readOnly: true
      terminationGracePeriodSeconds: 300
      volumes:
      - name: config
        configMap:
          defaultMode: 420
          name: prometheus-config
      - name: rules
        configMap:
          defaultMode: 420
          name: prometheus-rules
  volumeClaimTemplates:
  - metadata:
      name: prometheus-db
    spec:
      accessModes:
      - ReadWriteOnce
      resources:
        requests:
          storage: {{ .Values.prometheus.storage }}
