# helm_charts_web-deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ template "sentry.fullname" . }}-web
  labels:
    app: {{ template "sentry.fullname" . }}
    chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}"
    release: "{{ .Release.Name }}"
    heritage: "{{ .Release.Service }}"
spec:
  selector:
    matchLabels:
        app: {{ template "sentry.fullname" . }}
        release: "{{ .Release.Name }}"
        role: web
  replicas: {{ .Values.web.replicacount }}
  template:
    metadata:
      annotations:
        metrics-enabled: {{ .Values.metrics.enabled | quote }}
        checksum/configYml: {{ .Values.config.configYml | sha256sum }}
        checksum/sentryConfPy: {{ .Values.config.sentryConfPy | sha256sum }}
        checksum/secrets.yaml: {{ include (print $.Template.BasePath "/secrets.yaml") . | sha256sum }}
      {{- if .Values.web.podAnnotations }}
{{ toYaml .Values.web.podAnnotations | indent 8 }}
      {{- end }}
      labels:
        app: {{ template "sentry.fullname" . }}
        release: "{{ .Release.Name }}"
        role: web
        {{- if .Values.web.podLabels }}
{{ toYaml .Values.web.podLabels | indent 8 }}
        {{- end }}
    spec:
      serviceAccountName: {{ template "sentry.serviceAccountName" . }}
      {{- if .Values.web.affinity }}
      affinity:
{{ toYaml .Values.web.affinity | indent 8 }}
      {{- end }}
      {{- if .Values.web.nodeSelector }}
      nodeSelector:
{{ toYaml .Values.web.nodeSelector | indent 8 }}
      {{- end }}
      {{- if .Values.web.tolerations }}
      tolerations:
{{ toYaml .Values.web.tolerations | indent 8 }}
      {{- end }}
      {{- if .Values.web.schedulerName }}
      schedulerName: "{{ .Values.web.schedulerName }}"
      {{- end }}
      {{- if .Values.image.imagePullSecrets }}
      imagePullSecrets:
{{ toYaml .Values.image.imagePullSecrets | indent 8 }}
      {{- end }}
      containers:
      - name: {{ .Chart.Name }}-web
        image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
        imagePullPolicy: {{ .Values.image.pullPolicy }}
        ports:
        - containerPort: {{ .Values.service.internalPort }}
        env:
        - name: SENTRY_SECRET_KEY
          valueFrom:
            secretKeyRef:
              name: {{ template "sentry.fullname" . }}
              key: sentry-secret
        - name: SENTRY_DB_USER
          value: {{ default "sentry" .Values.postgresql.postgresqlUsername | quote }}
        - name: SENTRY_DB_NAME
          value: {{ default "sentry" .Values.postgresql.postgresqlDatabase | quote }}
        - name: SENTRY_DB_PASSWORD
          valueFrom:
            secretKeyRef:
            {{- if .Values.postgresql.existingSecret }}
              name: {{ .Values.postgresql.existingSecret }}
            {{- else }}
              name: {{ template "sentry.postgresql.secret" . }}
            {{- end }}
              key: {{ template "sentry.postgresql.secretKey" . }}
        - name: SENTRY_POSTGRES_HOST
          value: {{ template "sentry.postgresql.host" . }}
        - name: SENTRY_POSTGRES_PORT
          value: {{ template "sentry.postgresql.port" . }}
        {{- if or (.Values.redis.enabled) (.Values.redis.password) (.Values.redis.existingSecret)  }}
        - name: SENTRY_REDIS_PASSWORD
          valueFrom:
            secretKeyRef:
            {{- if .Values.redis.existingSecret }}
              name: {{ .Values.redis.existingSecret }}
            {{- else }}
              name: {{ template "sentry.redis.secret" . }}
            {{- end }}
              key: {{ template "sentry.redis.secretKey" . }}
        {{- end }}
        - name: SENTRY_REDIS_HOST
          value: {{ template "sentry.redis.host" . }}
        - name: SENTRY_REDIS_PORT
          value: {{ template "sentry.redis.port" . }}
        - name: SENTRY_EMAIL_HOST
          value: {{ default "" .Values.email.host | quote }}
        - name: SENTRY_EMAIL_PORT
          value: {{ default "" .Values.email.port | quote }}
        - name: SENTRY_EMAIL_USER
          value: {{ default "" .Values.email.user | quote }}
        - name: SENTRY_EMAIL_PASSWORD
          valueFrom:
            secretKeyRef:
            {{- if .Values.email.existingSecret }}
              name: {{ .Values.email.existingSecret }}
            {{- else }}
              name: {{ template "sentry.fullname" . }}
            {{- end }}
              key: smtp-password
        - name: SENTRY_EMAIL_USE_TLS
          value: {{ .Values.email.use_tls | quote }}
        - name: SENTRY_SERVER_EMAIL
          value: {{ .Values.email.from_address | quote }}
        {{ if eq .Values.filestore.backend "gcs" }}
        - name: GOOGLE_APPLICATION_CREDENTIALS
          value: /var/run/secrets/google/{{ .Values.filestore.gcs.credentialsFile }}
        {{ end }}
        {{- if eq .Values.filestore.backend "s3" }}
        - name: AWS_ACCESS_KEY_ID
          valueFrom:
            secretKeyRef:
            {{- if .Values.filestore.s3.existingSecret }}
              name: {{ .Values.filestore.s3.existingSecret }}
            {{- else }}
              name: {{ template "sentry.fullname" . }}
            {{- end }}
              key: AWS_ACCESS_KEY_ID
        - name: AWS_SECRET_ACCESS_KEY
          valueFrom:
            secretKeyRef:
            {{- if .Values.filestore.s3.existingSecret }}
              name: {{ .Values.filestore.s3.existingSecret }}
            {{- else }}
              name: {{ template "sentry.fullname" . }}
            {{- end }}
              key: AWS_SECRET_ACCESS_KEY
        {{- end }}
{{- if .Values.web.env }}
{{ toYaml .Values.web.env | indent 8 }}
{{- end }}
        volumeMounts:
        - mountPath: /etc/sentry
          name: config
          readOnly: true
        - mountPath: {{ .Values.filestore.filesystem.path }}
          name: sentry-data
        {{- if eq .Values.filestore.backend "gcs" }}
        - name: sentry-google-cloud-key
          mountPath: /var/run/secrets/google
        {{ end }}
        livenessProbe:
          failureThreshold: {{ .Values.web.livenessProbe.failureThreshold }}
          httpGet:
            path: /_health/
            port: {{ .Values.service.internalPort }}
            scheme: HTTP
          initialDelaySeconds: {{ .Values.web.livenessProbe.initialDelaySeconds }}
          periodSeconds: {{ .Values.web.livenessProbe.periodSeconds }}
          successThreshold: {{ .Values.web.livenessProbe.successThreshold }}
          timeoutSeconds: {{ .Values.web.livenessProbe.timeoutSeconds }}
        readinessProbe:
          failureThreshold: {{ .Values.web.readinessProbe.failureThreshold }}
          httpGet:
            path: /_health/
            port: {{ .Values.service.internalPort }}
            scheme: HTTP
          initialDelaySeconds: {{ .Values.web.readinessProbe.initialDelaySeconds }}
          periodSeconds: {{ .Values.web.readinessProbe.periodSeconds }}
          successThreshold: {{ .Values.web.readinessProbe.successThreshold }}
          timeoutSeconds: {{ .Values.web.readinessProbe.timeoutSeconds }}
        resources:
{{ toYaml .Values.web.resources | indent 12 }}
      volumes:
      - name: config
        configMap:
          name: {{ template "sentry.fullname" . }}
      - name: sentry-data
      {{- if and (eq .Values.filestore.backend "filesystem") .Values.filestore.filesystem.persistence.enabled }}
        persistentVolumeClaim:
          claimName: {{ .Values.filestore.filesystem.persistence.existingClaim | default (include "sentry.fullname" .) }}
      {{- else }}
        emptyDir: {}
      {{ end }}
      {{- if eq .Values.filestore.backend "gcs" }}
      - name: sentry-google-cloud-key
        secret:
          secretName: {{ .Values.filestore.gcs.secretName }}
      {{ end }}
      {{- if .Values.web.priorityClassName }}
      priorityClassName: "{{ .Values.web.priorityClassName }}"
      {{- end }}