apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ include "capacity-planner.fullname" . }}
  labels:
    {{- include "capacity-planner.labels" . | nindent 4 }}
spec:
  replicas: {{ .Values.replicaCount }}
  selector:
    matchLabels:
      {{- include "capacity-planner.selectorLabels" . | nindent 6 }}
  template:
    metadata:
      annotations:
        checksum/config: {{ .Values.config | toJson | sha256sum }}
        checksum/tier-templates: {{ .Values.tierTemplates.config | sha256sum }}
        {{- with .Values.podAnnotations }}
        {{- toYaml . | nindent 8 }}
        {{- end }}
      labels:
        {{- include "capacity-planner.selectorLabels" . | nindent 8 }}
        {{- with .Values.podLabels }}
        {{- toYaml . | nindent 8 }}
        {{- end }}
    spec:
      serviceAccountName: {{ include "capacity-planner.serviceAccountName" . }}
      securityContext:
        {{- toYaml .Values.podSecurityContext | nindent 8 }}
      {{- with .Values.imagePullSecrets }}
      imagePullSecrets:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      containers:
      - name: capacity-planner
        image: "{{ .Values.image.repository }}:{{ default .Chart.AppVersion .Values.image.tag }}"
        imagePullPolicy: {{ .Values.image.pullPolicy }}
        securityContext:
          {{- toYaml .Values.securityContext | nindent 10 }}
        args:
        - --config=/etc/capacity-planner/capacity-planner.yaml
        - --tier-templates-config=/etc/capacity-planner/tier-templates.yaml
        ports:
        - name: health
          containerPort: 8081
          protocol: TCP
        livenessProbe:
          httpGet:
            path: /healthz
            port: health
        readinessProbe:
          httpGet:
            path: /readyz
            port: health
        resources:
          {{- toYaml .Values.resources | nindent 10 }}
        volumeMounts:
        - name: config
          mountPath: /etc/capacity-planner
          readOnly: true
        - name: metrics-storage
          mountPath: {{ .Values.config.storage.path }}
        {{- if .Values.config.records.dir }}
        - name: decision-records
          mountPath: {{ .Values.config.records.dir }}
        {{- end }}
      volumes:
      - name: config
        configMap:
          name: {{ include "capacity-planner.fullname" . }}-config
      - name: metrics-storage
        emptyDir:
          sizeLimit: {{ .Values.storageVolumes.metrics.sizeLimit }}
      {{- if .Values.config.records.dir }}
      - name: decision-records
        emptyDir:
          sizeLimit: {{ .Values.storageVolumes.records.sizeLimit }}
      {{- end }}
      {{- with .Values.nodeSelector }}
      nodeSelector:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      {{- with .Values.affinity }}
      affinity:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      {{- with .Values.tolerations }}
      tolerations:
        {{- toYaml . | nindent 8 }}
      {{- end }}
