apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: {{ template "fileshare.fullname" . }}
  labels:
    app: {{ template "fileshare.name" . }}
    chart: {{ template "fileshare.chart" . }}
    release: {{ .Release.Name }}
    heritage: {{ .Release.Service }}
spec:
  replicas: {{ .Values.replicaCount }}
  selector:
    matchLabels:
      app: {{ template "fileshare.name" . }}
      release: {{ .Release.Name }}
  template:
    metadata:
      labels:
        app: {{ template "fileshare.name" . }}
        release: {{ .Release.Name }}
    spec:
      initContainers:
        - image: busybox
          name: mount-permissions-fix
          command: ["sh", "-c", "chmod 777 /data"]
          volumeMounts:
            - name: data
              mountPath: /data
      containers:
        - name: {{ .Chart.Name }}
          image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
          imagePullPolicy: {{ .Values.image.pullPolicy }}
          ports:
            - name: http
              containerPort: 80
              protocol: TCP
          readinessProbe:
            failureThreshold: 3
            httpGet:
              path: /
              port: http
            periodSeconds: 10
            successThreshold: 1
            timeoutSeconds: 1
          livenessProbe:
            failureThreshold: 3
            httpGet:
              path: /
              port: http
            periodSeconds: 10
            successThreshold: 1
            timeoutSeconds: 1
            initialDelaySeconds: 10
          volumeMounts:
          - name: config
            mountPath: /etc/nginx/conf.d/
          - name: data
            mountPath: /data
          resources:
{{ toYaml .Values.resources | indent 12 }}
      volumes:
      - name: config
        configMap:
          name: {{ template "fileshare.fullname" . }}
      - name: data
      {{- if .Values.persistence.enabled }}
        persistentVolumeClaim:
          claimName: {{ template "fileshare.fullname" . }}
      {{- else }}
        emptyDir: {}
      {{- end -}}
