apiVersion: batch/v1
kind: Job
metadata:
  name: "sentry-db-init"
  labels:
    app: sentry
spec:
  template:
    metadata:
      name: "sentry-db-init"
      labels:
        app: sentry
        release: "release-name"
    spec:
      restartPolicy: Never
      containers:
      - name: db-init-job
        image: "sentry:9.1.1"
        command: ["sentry","upgrade","--noinput"]
        env:
        - name: SENTRY_SECRET_KEY
          valueFrom:
            secretKeyRef:
              name: sentry
              key: sentry-secret
        - name: SENTRY_DB_USER
          value: "sentry"
        - name: SENTRY_DB_NAME
          value: "sentry"
        - name: SENTRY_DB_PASSWORD
          valueFrom:
            secretKeyRef:
              name: sentry-postgresql
              key: postgres-password
        - name: SENTRY_POSTGRES_HOST
          value: sentry-postgresql
        - name: SENTRY_POSTGRES_PORT
          value: "5432"
        - name: SENTRY_REDIS_PASSWORD
          valueFrom:
            secretKeyRef:
              name: sentry-redis
              key: redis-password
        - name: SENTRY_REDIS_HOST
          value: sentry-redis-master
        - name: SENTRY_REDIS_PORT
          value: "6379"
        - name: SENTRY_EMAIL_HOST
          value: '{{repl ConfigOption "smtp_host"}}'
        - name: SENTRY_EMAIL_PORT
          value: '{{repl ConfigOption "smtp_port"}}'
        - name: SENTRY_EMAIL_USER
          value: '{{repl ConfigOption "smtp_user"}}'
        - name: SENTRY_EMAIL_PASSWORD
          valueFrom:
            secretKeyRef:
              name: sentry
              key: smtp-password
        - name: SENTRY_EMAIL_USE_TLS
          value: "false"
        - name: SENTRY_SERVER_EMAIL
          value: "sentry@sentry.local"
        volumeMounts:
        - mountPath: /etc/sentry
          name: config
          readOnly: true
      volumes:
      - name: config
        configMap:
          name: sentry
