apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: {{ template "odoo.fullname" . }}
  labels:
    app: {{ template "odoo.name" . }}
    chart: {{ template "odoo.chart" . }}
    release: {{ .Release.Name | quote }}
    heritage: {{ .Release.Service | quote }}
spec:
  template:
    metadata:
      labels:
        app: {{ template "odoo.name" . }}
        chart: {{ template "odoo.chart" . }}
        release: {{ .Release.Name | quote }}
    spec:
      {{- if .Values.image.pullSecrets }}
      imagePullSecrets:
      {{- range .Values.image.pullSecrets }}
        - name: {{ . }}
      {{- end}}
      {{- end }}
      containers:
      - name: {{ template "odoo.fullname" . }}
        image: {{ template "odoo.image" . }}
        imagePullPolicy: {{ .Values.image.pullPolicy | quote }}
        env:
        - name: POSTGRESQL_HOST
          value: {{ template "odoo.postgresql.fullname" . }}
        - name: POSTGRESQL_PORT_NUMBER
          value: "5432"
        - name: POSTGRESQL_PASSWORD
          valueFrom:
            secretKeyRef:
              name: {{ template "odoo.postgresql.fullname" . }}
              key: postgres-password
        - name: ODOO_EMAIL
          value: {{ .Values.odooEmail | quote }}
        - name: ODOO_PASSWORD
          valueFrom:
            secretKeyRef:
              name: {{ template "odoo.fullname" . }}
              key: odoo-password
        {{- if .Values.smtpHost }}
        - name: SMTP_HOST
          value: {{ .Values.smtpHost | quote }}
        {{- end }}
        {{- if .Values.smtpPort }}
        - name: SMTP_PORT
          value: {{ .Values.smtpPort | quote }}
        {{- end }}
        {{- if .Values.smtpUser }}
        - name: SMTP_USER
          value: {{ .Values.smtpUser | quote }}
        {{- end }}
        {{- if .Values.smtpPassword }}
        - name: SMTP_PASSWORD
          valueFrom:
            secretKeyRef:
              name: {{ template "odoo.fullname" . }}
              key: smtp-password
        {{- end }}
        {{- if .Values.smtpProtocol }}
        - name: SMTP_PROTOCOL
          value: {{ .Values.smtpProtocol | quote }}
        {{- end }}
        ports:
        - name: http
          containerPort: 8069
        {{- if .Values.livenessProbe.enabled }}
        livenessProbe:
          httpGet:
            path: /
            port: http
          initialDelaySeconds: {{ .Values.livenessProbe.initialDelaySeconds }}
          periodSeconds: {{ .Values.livenessProbe.periodSeconds }}
          timeoutSeconds: {{ .Values.livenessProbe.timeoutSeconds }}
          successThreshold: {{ .Values.livenessProbe.successThreshold }}
          failureThreshold: {{ .Values.livenessProbe.failureThreshold }}
        {{- end }}
        {{- if .Values.readinessProbe.enabled }}
        readinessProbe:
          httpGet:
            path: /
            port: http
          initialDelaySeconds: {{ .Values.readinessProbe.initialDelaySeconds }}
          periodSeconds: {{ .Values.readinessProbe.periodSeconds }}
          timeoutSeconds: {{ .Values.readinessProbe.timeoutSeconds }}
          successThreshold: {{ .Values.readinessProbe.successThreshold }}
          failureThreshold: {{ .Values.readinessProbe.failureThreshold }}
        {{- end }}
        resources:
{{ toYaml .Values.resources | indent 10 }}
        volumeMounts:
        - name: odoo-data
          mountPath: /bitnami/odoo
      volumes:
      - name: odoo-data
      {{- if .Values.persistence.enabled }}
        persistentVolumeClaim:
          claimName: {{ template "odoo.fullname" . }}
      {{- else }}
        emptyDir: {}
      {{- end }}
