apiVersion: apps/v1
kind: Deployment
metadata:
  name: alertstore
  labels:
    app: alertstore
spec:
  replicas: 1
  strategy:
    type: Recreate
  selector:
    matchLabels:
      app: alertstore
  template:
    metadata:
      labels:
        app: alertstore
    spec:
      containers:
        - name: alertstore
          image: alertstore:latest
          imagePullPolicy: IfNotPresent
          args:
            - --config
            - /app/config.yaml
          ports:
            - name: http
              containerPort: 8080
          env:
            - name: DB_DSN
              valueFrom:
                secretKeyRef:
                  name: alertstore-secret
                  key: DB_DSN
            - name: LARK_APP_SECRET
              valueFrom:
                secretKeyRef:
                  name: alertstore-secret
                  key: LARK_APP_SECRET
            - name: ALERTSTORE_WEBHOOK_TOKEN
              valueFrom:
                secretKeyRef:
                  name: alertstore-secret
                  key: ALERTSTORE_WEBHOOK_TOKEN
            - name: CLINIC_TOKEN
              valueFrom:
                secretKeyRef:
                  name: alertstore-secret
                  key: CLINIC_TOKEN
            - name: EVENT_KEY
              valueFrom:
                secretKeyRef:
                  name: alertstore-secret
                  key: EVENT_KEY
            # Optional: with no token the Jira mirror stays off and the pod
            # still starts, so this can land before the value exists.
            - name: JIRA_TOKEN
              valueFrom:
                secretKeyRef:
                  name: alertstore-secret
                  key: JIRA_TOKEN
                  optional: true
          volumeMounts:
            - name: config
              mountPath: /app/config.yaml
              subPath: config.yaml
            - name: web-runtime-config
              mountPath: /app/web/runtime-config.js
              subPath: runtime-config.js
          startupProbe:
            httpGet:
              path: /healthz
              port: http
            periodSeconds: 5
            failureThreshold: 120
          livenessProbe:
            httpGet:
              path: /healthz
              port: http
            initialDelaySeconds: 10
            periodSeconds: 10
          readinessProbe:
            httpGet:
              path: /healthz
              port: http
            initialDelaySeconds: 5
            periodSeconds: 10
      volumes:
        - name: config
          configMap:
            name: alertstore-config
        - name: web-runtime-config
          configMap:
            name: alertstore-web-runtime-config
