apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: {{ template "dokuwiki.fullname" . }}
  labels:
    app: {{ template "dokuwiki.name" . }}
    chart: {{ template "dokuwiki.chart" . }}
    release: {{ .Release.Name | quote }}
    heritage: {{ .Release.Service | quote }}
spec:
  template:
    metadata:
      labels:
        app: {{ template "dokuwiki.name" . }}
        chart: {{ template "dokuwiki.chart" . }}
        release: {{ .Release.Name | quote }}
    spec:
      {{- if .Values.image.pullSecrets }}
      imagePullSecrets:
      {{- range .Values.image.pullSecrets }}
        - name: {{ . }}
      {{- end}}
      {{- end }}
      containers:
      - name: {{ template "dokuwiki.fullname" . }}
        image: {{ template "dokuwiki.image" . }}
        imagePullPolicy: {{ .Values.image.pullPolicy | quote }}
        env:
        - name: DOKUWIKI_USERNAME
          value: {{ .Values.dokuwikiUsername | quote }}
        - name: DOKUWIKI_FULL_NAME
          value: {{ .Values.dokuwikiFullName | quote }}
        - name: DOKUWIKI_PASSWORD
          valueFrom:
            secretKeyRef:
              name: {{ template "dokuwiki.fullname" . }}
              key: dokuwiki-password
        - name: DOKUWIKI_EMAIL
          value: {{ .Values.dokuwikiEmail | quote }}
        - name: DOKUWIKI_WIKI_NAME
          value: {{ .Values.dokuwikiWikiName | quote }}
        ports:
        - name: http
          containerPort: 80
        - name: https
          containerPort: 443
        {{- if .Values.livenessProbe.enabled }}
        livenessProbe:
          httpGet:
            path: /doku.php
            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: /doku.php
            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: dokuwiki-data
          mountPath: /bitnami/dokuwiki
        - name: apache-data
          mountPath: /bitnami/apache
      volumes:
      - name: dokuwiki-data
      {{- if .Values.persistence.enabled }}
        persistentVolumeClaim:
          claimName: {{ template "dokuwiki.fullname" . }}-dokuwiki
      {{- else }}
        emptyDir: {}
      {{- end }}
      - name: apache-data
      {{- if .Values.persistence.enabled }}
        persistentVolumeClaim:
          claimName: {{ template "dokuwiki.fullname" . }}-apache
      {{- else }}
        emptyDir: {}
      {{- end }}
