apiVersion: apps/v1beta2
kind: Deployment
metadata:
  name: {{ template "phpmyadmin.fullname" . }}
  labels:
    app: {{ template "phpmyadmin.name" . }}
    chart: {{ template "phpmyadmin.chart" . }}
    release: {{ .Release.Name }}
    heritage: {{ .Release.Service }}
spec:
  replicas: 1
  selector:
    matchLabels:
      app: {{ template "phpmyadmin.name" . }}
      chart: {{ template "phpmyadmin.chart" . }}
      release: {{ .Release.Name }}
  template:
    metadata:
      labels:
        app: {{ template "phpmyadmin.name" . }}
        chart: {{ template "phpmyadmin.chart" . }}
        release: {{ .Release.Name }}
    spec:
      {{- if .Values.image.pullSecrets }}
      imagePullSecrets:
      {{- range .Values.image.pullSecrets }}
        - name: {{ . }}
      {{- end}}
      {{- end }}
      containers:
        - name: {{ .Chart.Name }}
          image: "{{ template "phpmyadmin.image" . }}"
          imagePullPolicy: {{ .Values.image.pullPolicy }}
          env:
            - name: DATABASE_PORT_NUMBER
              value: "{{ .Values.db.port }}"
            {{- if .Values.db.chartName }}
            - name: DATABASE_HOST
              value: "{{ template "phpmyadmin.dbfullname" . }}"
            {{- else }} 
            - name: DATABASE_HOST
              value: "{{ .Values.db.host }}"
            {{- end }}
            {{- if and (not .Values.db.chartName) (not .Values.db.host)}}
            - name: PHPMYADMIN_ALLOW_NO_PASSWORD
              value: "true"
            - name: PHPMYADMIN_ALLOW_ARBITRARY_SERVER
              value: "true"
            {{- else }}
            - name: PHPMYADMIN_ALLOW_NO_PASSWORD
              value: "false"
            {{- end }}
          ports:
            - name: http
              containerPort: 80
              protocol: TCP
            - name: https
              containerPort: 443
              protocol: TCP
          {{- if .Values.probesEnabled }}
          livenessProbe:
            httpGet:
              path: /
              port: http
          readinessProbe:
            httpGet:
              path: /
              port: http
          {{- end }}
          resources:
{{ toYaml .Values.resources | indent 12 }}
