apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ template "k8s-spot-rescheduler.fullname" . }}
  labels:
    app: {{ template "k8s-spot-rescheduler.name" . }}
    chart: {{ template "k8s-spot-rescheduler.chart" . }}
    release: {{ .Release.Name }}
    heritage: {{ .Release.Service }}
spec:
  replicas: {{ .Values.replicaCount }}
  selector:
    matchLabels:
      app: {{ template "k8s-spot-rescheduler.name" . }}
      release: {{ .Release.Name }}
  template:
    metadata:
      labels:
        app: {{ template "k8s-spot-rescheduler.name" . }}
        release: {{ .Release.Name }}
{{- with .Values.podAnnotations }}
      annotations:
{{ toYaml . | indent 8 }}
{{- end }}
    spec:
      serviceAccountName: {{ template "k8s-spot-rescheduler.serviceAccountName" . }}
      {{- if .Values.priorityClassName }}
      priorityClassName: "{{ .Values.priorityClassName }}"
      {{- end }}
      containers:
        - name: {{ .Chart.Name }}
          image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
          imagePullPolicy: {{ .Values.image.pullPolicy }}
          command:
            - k8s-spot-rescheduler
            - --namespace={{ .Release.Namespace }}
          {{- range $key, $value := .Values.cmdOptions }}
            - --{{ $key }}{{ if $value }}={{ $value }}{{ end }}
          {{- end }}
          ports:
          - name: http
            containerPort: 9235
          resources:
{{ toYaml .Values.resources | indent 12 }}
    {{- if .Values.affinity }}
      affinity:
{{ toYaml .Values.affinity | indent 8 }}
    {{- end }}
      nodeSelector:
{{ toYaml .Values.nodeSelector | indent 8 }}
      tolerations:
{{ toYaml .Values.tolerations | indent 8 }}
