{{- if .Values.controller.enabled }}
apiVersion: v1
kind: ConfigMap
metadata:
  name: kargo-controller
  namespace: {{ .Release.Namespace }}
  labels:
    {{- include "kargo.labels" . | nindent 4 }}
    {{- include "kargo.controller.labels" . | nindent 4 }}
data:
  {{- if .Values.api.enabled }}
  {{- if or .Values.api.tls.enabled (and .Values.api.ingress.enabled .Values.api.ingress.tls.enabled) }}
  API_SERVER_BASE_URL: https://{{ .Values.api.host }}
  {{- else }}
  API_SERVER_BASE_URL: http://{{ .Values.api.host }}
  {{- end }}
  {{- end }}
  LOG_LEVEL: {{ quote .Values.controller.logLevel }}
  {{- if .Values.controller.shardName }}
  SHARD_NAME: {{ .Values.controller.shardName }}
  {{- end }}
  {{- if .Values.kubeconfigSecrets.kargo }}
  KUBECONFIG: /etc/kargo/kubeconfigs/kubeconfig.yaml
  {{- end }}
  GLOBAL_CREDENTIALS_NAMESPACES: {{ quote (join "," .Values.controller.globalCredentials.namespaces) }}
  GITCLIENT_NAME: {{ quote .Values.controller.gitClient.name }}
  GITCLIENT_EMAIL: {{ quote .Values.controller.gitClient.email }}
  GITCLIENT_SIGNING_KEY_TYPE: {{ .Values.controller.gitClient.signingKeySecret.type | default "gpg" | quote }}
  {{- if .Values.controller.gitClient.signingKeySecret.name }}
  GITCLIENT_SIGNING_KEY_PATH: /etc/kargo/git/signingKey
  {{- end }}
  ARGOCD_INTEGRATION_ENABLED: {{ quote .Values.controller.argocd.integrationEnabled }}
  {{- if .Values.controller.argocd.integrationEnabled }}
  {{- if .Values.kubeconfigSecrets.argocd }}
  ARGOCD_KUBECONFIG: /etc/kargo/kubeconfigs/argocd-kubeconfig.yaml
  {{- end }}
  ARGOCD_NAMESPACE: {{ .Values.controller.argocd.namespace | default "argocd" }}
  ARGOCD_WATCH_ARGOCD_NAMESPACE_ONLY: {{ quote .Values.controller.argocd.watchArgocdNamespaceOnly }}
  {{- end }}
  ROLLOUTS_INTEGRATION_ENABLED: {{ quote .Values.controller.rollouts.integrationEnabled }}
  {{- if .Values.controller.rollouts.integrationEnabled }}
  ROLLOUTS_CONTROLLER_INSTANCE_ID: {{ quote .Values.controller.rollouts.controllerInstanceID }}
  {{- end }}
  MAX_CONCURRENT_CONTROL_FLOW_RECONCILES: {{ .Values.controller.reconcilers.controlFlowStages.maxConcurrentReconciles | default .Values.controller.reconcilers.maxConcurrentReconciles | quote }}
  MAX_CONCURRENT_PROMOTION_RECONCILES: {{ .Values.controller.reconcilers.promotions.maxConcurrentReconciles | default .Values.controller.reconcilers.maxConcurrentReconciles | quote }}
  MAX_CONCURRENT_STAGE_RECONCILES: {{ .Values.controller.reconcilers.stages.maxConcurrentReconciles | default .Values.controller.reconcilers.maxConcurrentReconciles | quote }}
  MAX_CONCURRENT_WAREHOUSE_RECONCILES: {{ .Values.controller.reconcilers.warehouses.maxConcurrentReconciles | default .Values.controller.reconcilers.maxConcurrentReconciles | quote }}
{{- end }}
