{{- $operatorValues :=  index .Values "reporting-operator" -}}
apiVersion: v1
kind: ConfigMap
metadata:
  name: reporting-operator-config
  labels:
    app: reporting-operator
data:
  log-level: {{ $operatorValues.spec.config.logLevel | quote}}
  log-reports: {{ $operatorValues.spec.config.logReports | quote}}
  log-ddl-queries: {{ $operatorValues.spec.config.logDDLQueries | quote}}
  log-dml-queries: {{ $operatorValues.spec.config.logDMLQueries | quote}}

{{- if $operatorValues.spec.config.hive.host }}
  hive-host: {{ $operatorValues.spec.config.hive.host | quote }}
{{- else }}
  hive-host: "hive-server:10000"
{{- end }}

{{- if $operatorValues.spec.config.hive.tls.enabled }}
  hive-ca-file: "/var/run/secrets/hive-tls/ca.crt"
{{- if $operatorValues.spec.config.hive.auth.enabled }}
  hive-client-cert-file: "/var/run/secrets/hive-auth/tls.crt"
  hive-client-key-file: "/var/run/secrets/hive-auth/tls.key"
{{- end }}
{{- end }}

  presto-host: {{ $operatorValues.spec.config.presto.host | quote }}
{{- if $operatorValues.spec.config.presto.tls.enabled }}
  presto-ca-file: "/var/run/secrets/presto-tls/ca.crt"
{{- if $operatorValues.spec.config.presto.auth.enabled }}
  presto-client-cert-file: "/var/run/secrets/presto-auth/tls.crt"
  presto-client-key-file: "/var/run/secrets/presto-auth/tls.key"
{{- end }}
{{- end }}

  prometheus-url: {{ $operatorValues.spec.config.prometheus.url | quote}}
  disable-prometheus-metrics-importer: {{ not $operatorValues.spec.config.prometheus.metricsImporter.enabled | quote}}
{{- if $operatorValues.spec.config.prometheus.metricsImporter.config.pollInterval }}
  prometheus-metrics-importer-poll-interval: {{ $operatorValues.spec.config.prometheus.metricsImporter.config.pollInterval | quote}}
{{- end }}
{{- if $operatorValues.spec.config.prometheus.metricsImporter.config.chunkSize }}
  prometheus-metrics-importer-chunk-size: {{ $operatorValues.spec.config.prometheus.metricsImporter.config.chunkSize | quote}}
{{- end }}
{{- if $operatorValues.spec.config.prometheus.metricsImporter.config.stepSize }}
  prometheus-metrics-importer-step-size: {{ $operatorValues.spec.config.prometheus.metricsImporter.config.stepSize | quote}}
{{- end }}
{{- if $operatorValues.spec.config.leaderLeaseDuration }}
  leader-lease-duration: {{ $operatorValues.spec.config.leaderLeaseDuration | quote }}
{{- end }}
{{- if $operatorValues.spec.config.prestoMaxQueryLength }}
  presto-max-query-length: {{ $operatorValues.spec.config.presto.maxQueryLength | quote }}
{{- end }}
{{- if $operatorValues.spec.config.prometheus.metricsImporter.config.maxQueryRangeDuration }}
  prometheus-datasource-max-query-range-duration: {{ $operatorValues.spec.config.prometheus.metricsImporter.config.maxQueryRangeDuration | quote }}
{{- end }}
{{- if $operatorValues.spec.config.prometheus.metricsImporter.config.maxImportBackfillDuration }}
  prometheus-datasource-max-import-backfill-duration: {{ $operatorValues.spec.config.prometheus.metricsImporter.config.maxImportBackfillDuration | quote }}
{{- end }}
{{- if $operatorValues.spec.config.prometheus.metricsImporter.config.importFrom }}
  prometheus-datasource-import-from: {{ $operatorValues.spec.config.prometheus.metricsImporter.config.importFrom | quote }}
{{- end }}
{{- if $operatorValues.spec.config.prometheus.metricsImporter.auth.useServiceAccountToken }}
  prometheus-bearer-token-file: "/var/run/secrets/kubernetes.io/serviceaccount/token"
{{- else }}
  prometheus-bearer-token-file: "/var/run/reporting-operator/token"
{{- end }}
{{- if $operatorValues.spec.config.allNamespaces }}
  all-namespaces: "true"
{{- end }}
{{- if $operatorValues.spec.config.targetNamespaces }}
  target-namespaces: {{ $operatorValues.spec.config.targetNamespaces | join "," | quote }}
{{- end }}
  enable-finalizers: {{ $operatorValues.spec.config.enableFinalizers | quote}}
