apiVersion: apps/v1beta2
kind: Deployment
metadata:
  name: {{ template "tomcat.fullname" . }}
  labels:
    app: {{ template "tomcat.name" . }}
    chart: {{ template "tomcat.chart" . }}
    release: {{ .Release.Name }}
    heritage: {{ .Release.Service }}
spec:
  replicas: {{ .Values.replicaCount }}
  selector:
    matchLabels:
      app: {{ template "tomcat.name" . }}
      release: {{ .Release.Name }}
  template:
    metadata:
      labels:
        app: {{ template "tomcat.name" . }}
        release: {{ .Release.Name }}
    spec:
      volumes:
        - name: app-volume
          emptyDir: {}
      initContainers:
        - name: war
          image: {{ .Values.image.webarchive.repository }}:{{ .Values.image.webarchive.tag }}
          imagePullPolicy: {{ .Values.image.pullPolicy }}
          command:
            - "sh"
            - "-c"
            - "cp /*.war /app"
          volumeMounts:
            - name: app-volume
              mountPath: /app
      containers:
        - name: {{ .Chart.Name }}
          image: {{ .Values.image.tomcat.repository }}:{{ .Values.image.tomcat.tag }}
          imagePullPolicy: {{ .Values.image.pullPolicy }}
          volumeMounts:
            - name: app-volume
              mountPath: {{ .Values.deploy.directory }}
          ports:
            - containerPort: {{ .Values.service.internalPort }}
              hostPort: 8009
          livenessProbe:
            httpGet:
              path: {{ .Values.livenessProbe.path }}
              port: {{ .Values.service.internalPort }}
            initialDelaySeconds: {{ .Values.livenessProbe.initialDelaySeconds }}
            periodSeconds: {{ .Values.livenessProbe.periodSeconds }}
          readinessProbe:
            httpGet:
              path: {{ .Values.readinessProbe.path }}
              port: {{ .Values.service.internalPort }}
            initialDelaySeconds: {{ .Values.readinessProbe.initialDelaySeconds }}
            periodSeconds: {{ .Values.readinessProbe.periodSeconds }}
            failureThreshold: {{ .Values.readinessProbe.failureThreshold }}
          resources:
{{ toYaml .Values.resources | indent 12 }}
    {{- if .Values.image.pullSecrets }}
      imagePullSecrets:
{{ toYaml .Values.image.pullSecrets | indent 8 }}
    {{- end }}
    {{- if .Values.nodeSelector }}
      nodeSelector:
{{ toYaml .Values.nodeSelector | indent 8 }}
    {{- end }}
    {{- if .Values.tolerations }}
      tolerations:
{{ toYaml .Values.tolerations | indent 8 }}
    {{- end }}
