{{- if .Values.deployments.etcdOperator }}
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ template "etcd-operator.fullname" . }}
  labels:
    chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
    app: {{ template "etcd-operator.name" . }}
    heritage: {{ .Release.Service }}
    release: {{ .Release.Name }}
spec:
  selector:
    matchLabels:
      app: {{ template "etcd-operator.fullname" . }}
      release: {{ .Release.Name }}
  replicas: {{ .Values.etcdOperator.replicaCount }}
  template:
    metadata:
      name: {{ template "etcd-operator.fullname" . }}
      labels:
        app: {{ template "etcd-operator.fullname" . }}
        release: {{ .Release.Name }}
      annotations: {{ toYaml .Values.etcdOperator.podAnnotations | nindent 8}}
    spec:
      {{- if .Values.etcdOperator.priorityClassName }}
      priorityClassName: {{ .Values.etcdOperator.priorityClassName }}
      {{- end }}
      serviceAccountName: {{ template "etcd-operator.serviceAccountName" . }}
      containers:
      - name: {{ template "etcd-operator.fullname" . }}
        image: "{{ .Values.etcdOperator.image.repository }}:{{ .Values.etcdOperator.image.tag }}"
        imagePullPolicy: {{ .Values.etcdOperator.image.pullPolicy }}
        command:
        - etcd-operator
{{- range $key, $value := .Values.etcdOperator.commandArgs }}
        - "--{{ $key }}={{ $value }}"
{{- end }}
        env:
        - name: MY_POD_NAMESPACE
          valueFrom:
            fieldRef:
              fieldPath: metadata.namespace
        - name: MY_POD_NAME
          valueFrom:
            fieldRef:
              fieldPath: metadata.name
        resources:
          limits:
            cpu: {{ .Values.etcdOperator.resources.cpu }}
            memory: {{ .Values.etcdOperator.resources.memory }}
          requests:
            cpu: {{ .Values.etcdOperator.resources.cpu }}
            memory: {{ .Values.etcdOperator.resources.memory }}
        {{- if .Values.etcdOperator.livenessProbe.enabled }}
        livenessProbe:
          httpGet:
            path: /readyz
            port: 8080
          initialDelaySeconds: {{ .Values.etcdOperator.livenessProbe.initialDelaySeconds }}
          periodSeconds: {{ .Values.etcdOperator.livenessProbe.periodSeconds }}
          timeoutSeconds: {{ .Values.etcdOperator.livenessProbe.timeoutSeconds }}
          successThreshold: {{ .Values.etcdOperator.livenessProbe.successThreshold }}
          failureThreshold: {{ .Values.etcdOperator.livenessProbe.failureThreshold }}
        {{- end}}
        {{- if .Values.etcdOperator.readinessProbe.enabled }}
        readinessProbe:
          httpGet:
            path: /readyz
            port: 8080
          initialDelaySeconds: {{ .Values.etcdOperator.readinessProbe.initialDelaySeconds }}
          periodSeconds: {{ .Values.etcdOperator.readinessProbe.periodSeconds }}
          timeoutSeconds: {{ .Values.etcdOperator.readinessProbe.timeoutSeconds }}
          successThreshold: {{ .Values.etcdOperator.readinessProbe.successThreshold }}
          failureThreshold: {{ .Values.etcdOperator.readinessProbe.failureThreshold }}
        {{- end }}
    {{- if .Values.etcdOperator.nodeSelector }}
      nodeSelector: {{ toYaml .Values.etcdOperator.nodeSelector | nindent 8 }}
    {{- end }}
    {{- if .Values.etcdOperator.securityContext }}
      securityContext: {{ toYaml .Values.etcdOperator.securityContext | nindent 8 }}
    {{- end }}
    {{- if .Values.etcdOperator.tolerations }}
      tolerations: {{ toYaml .Values.etcdOperator.tolerations | nindent 8 }}
    {{- end }}
{{- end }}
