apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ template "name" . }}
  labels:
    app: {{ template "name" . }}
    chart: {{ template "chart" . }}
    release: {{ .Release.Name }}
    heritage: {{ .Release.Service }}
spec:
  replicas: {{ .Values.replicas }}
  selector:
    matchLabels:
      app: {{ template "name" . }}
      release: {{ .Release.Name }}
  strategy:
    type: {{ .Values.deploymentStrategy }}
  template:
    metadata:
      labels:
        app: {{ template "name" . }}
        release: {{ .Release.Name }}
    spec:
      {{- if .Values.priorityClassName }}
      priorityClassName: {{ .Values.priorityClassName  | quote }}
      {{- end }}
      serviceAccountName: {{ template "name" . }}
      containers:
      - image: {{ .Values.image.repository }}:{{ .Values.image.tag }}
        {{- if .Values.args }}
        args:
        {{- range $arg := .Values.args }}
        - {{ $arg }}
        {{- end }}
        {{- end }}
        imagePullPolicy: {{ .Values.image.pullPolicy }}
        name: {{ .Chart.Name }}
        resources:
          {{- toYaml .Values.resourcesCrossplane | nindent 12 }}
        securityContext:
          runAsUser: 2000
          runAsGroup: 2000
          allowPrivilegeEscalation: false
          readOnlyRootFilesystem: true
        env:
          - name: POD_NAMESPACE
            valueFrom:
              fieldRef:
                fieldPath: metadata.namespace
        volumeMounts:
          - mountPath: /cache
            name: package-cache
      volumes:
      - name: package-cache
        {{- if .Values.packageCache.pvc }}
        persistentVolumeClaim:
          claimName: {{ .Values.packageCache.pvc }}
        {{- else }}
        emptyDir:
          medium: {{ .Values.packageCache.medium }}
          sizeLimit: {{ .Values.packageCache.sizeLimit }}
        {{- end }}
        