{{- if .Values.kubeconfigGenerator.enabled }}
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    {{- include "kamaji.labels" . | nindent 4 }}
  name: {{ include "kamaji.kubeconfigGeneratorName" . }}
  namespace: {{ .Release.Namespace }}
spec:
  replicas: {{ .Values.kubeconfigGenerator.replicaCount }}
  selector:
    matchLabels:
      {{- include "kamaji.selectorLabels" . | nindent 6 }}
  template:
    metadata:
      {{- with .Values.kubeconfigGenerator.podAnnotations }}
      annotations:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      labels:
        {{- include "kamaji.selectorLabels" . | nindent 8 }}
    spec:
      securityContext:
        {{- toYaml .Values.kubeconfigGenerator.podSecurityContext | nindent 8 }}
      serviceAccountName: {{ default .Values.kubeconfigGenerator.serviceAccountOverride (include "kamaji.serviceAccountName" .) }}
      containers:
        - args:
          - kubeconfig-generator
          - --health-probe-bind-address={{ .Values.kubeconfigGenerator.healthProbeBindAddress }}
          - --leader-elect={{ .Values.kubeconfigGenerator.enableLeaderElect }}
          {{- if .Values.kubeconfigGenerator.loggingDevel.enable }}- --zap-devel{{- end }}
          {{- with .Values.kubeconfigGenerator.extraArgs }}
          {{- toYaml . | nindent 10 }}
          {{- end }}
          image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
          imagePullPolicy: {{ .Values.image.pullPolicy }}
          name: controller
          resources:
            {{- toYaml .Values.kubeconfigGenerator.resources | nindent 12 }}
          securityContext:
            {{- toYaml .Values.kubeconfigGenerator.securityContext | nindent 12 }}
      {{- with .Values.kubeconfigGenerator.nodeSelector }}
      nodeSelector:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      {{- with .Values.kubeconfigGenerator.affinity }}
      affinity:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      {{- with .Values.kubeconfigGenerator.tolerations }}
      tolerations:
        {{- toYaml . | nindent 8 }}
      {{- end }}
{{- end }}
