# helm_charts_appsrv.yaml
apiVersion: apps/v1
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: {}
        {{- with .Values.extraVolumes }}
{{ toYaml . | indent 8 }}
        {{- end }}
      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
        {{- with .Values.extraInitContainers }}
{{ toYaml . | indent 8 }}
        {{- end }}

      containers:
        - name: {{ .Chart.Name }}
          image: {{ .Values.image.tomcat.repository }}:{{ .Values.image.tomcat.tag }}
          imagePullPolicy: {{ .Values.image.pullPolicy }}
          {{- with .Values.env }}
          env:
{{ toYaml . | indent 12 }}
          {{- end }}
          volumeMounts:
            - name: app-volume
              mountPath: {{ .Values.deploy.directory }}
            {{- with .Values.extraVolumeMounts }}
{{ toYaml . | indent 12 }}
            {{- end }}
          ports:
            - containerPort: {{ .Values.service.internalPort }}
              {{- with .Values.hostPort }}
              hostPort: {{ . }}
              {{- end }}
          livenessProbe:
            httpGet:
              path: {{ .Values.livenessProbe.path }}
              port: {{ .Values.service.internalPort }}
            initialDelaySeconds: {{ .Values.livenessProbe.initialDelaySeconds }}
            periodSeconds: {{ .Values.livenessProbe.periodSeconds }}
            failureThreshold: {{ .Values.livenessProbe.failureThreshold }}
            timeoutSeconds: {{ .Values.livenessProbe.timeoutSeconds }}
          readinessProbe:
            httpGet:
              path: {{ .Values.readinessProbe.path }}
              port: {{ .Values.service.internalPort }}
            initialDelaySeconds: {{ .Values.readinessProbe.initialDelaySeconds }}
            periodSeconds: {{ .Values.readinessProbe.periodSeconds }}
            failureThreshold: {{ .Values.readinessProbe.failureThreshold }}
            timeoutSeconds: {{ .Values.readinessProbe.timeoutSeconds }}
          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 }}