apiVersion: metering.openshift.io/v1
kind: MeteringConfig
metadata:
  name: "{{ .Values.deployPlatform }}-metering"
spec:
  logHelmTemplate: true

  monitoring:
    enabled: true

  unsupportedFeatures:
    enableHDFS: true

  tls:
    enabled: true

  storage:
    type: "hive"
    hive:
      type: "hdfs"
      hdfs:
        namenode: "hdfs-namenode-0.hdfs-namenode:9820"

  openshift-reporting:
    spec:
      awsBillingReportDataSource:
        enabled: {{ .Values.enableAwsBilling }}
        bucket: "{{ .Values.awsBillingBucket }}"
        prefix: "{{ .Values.awsBillingBucketPrefix }}"
        region: "{{ .Values.awsBillingBucketRegion }}"

  reporting-operator:
    spec:
      replicas: {{ .Values.reportingOperatorReplicas }}
      {{- if or .Values.reportingOperatorDeployRepo .Values.reportingOperatorDeployTag .Values.imagePullSecretName }}
      image:
        {{- if .Values.reportingOperatorDeployRepo }}
        repository: {{ .Values.reportingOperatorDeployRepo }}
        {{- end }}
        {{- if .Values.reportingOperatorDeployTag }}
        tag: {{ .Values.reportingOperatorDeployTag }}
        {{- end }}
        {{- if .Values.imagePullSecretName }}
        pullSecrets: [ { name: "{{ .Values.imagePullSecretName }}" } ]
        {{- end }}
      {{- end }}
      {{- if .Values.dateAnnotationValue }}
      annotations: { "metering.deploy-custom/deploy-time": "{{ .Values.dateAnnotationValue }}" }
      {{- end }}

      route:
        enabled: true

      config:
        logLevel: "debug"
        aws:
          accessKeyID: "{{ .Values.awsAccessKeyId }}"
          secretAccessKey: "{{ .Values.awsSecretAccessKey }}"

        prometheus:
          metricsImporter:
            enabled: {{ not .Values.disablePrometheusMetricsImporter }}
            config:
              # decrease backfill for e2e since we run for a short period of
              # time and run reports against the last ~15 minutes of data
              maxImportBackfillDuration: "15m"

              # increase the poll interval for tests so that the Reports can
              # run sooner
              pollInterval: "30s"

              # set chunk/query size to a value suitable for the backfill
              # duration
              maxQueryRangeDuration: "5m"
              chunkSize: "5m"

              # e2e runs a per-minute report so the metric resolution should be
              # 60s or less
              stepSize: "60s"

      {{- if or .Values.reportingOperatorMemory .Values.reportingOperatorCpu }}
      resources:
        requests:
          memory: "{{ .Values.reportingOperatorMemory }}"
          cpu: "{{ .Values.reportingOperatorCpu }}"
      {{- end }}

  presto:
    spec:
      {{- if .Values.imagePullSecretName }}
      imagePullSecrets: [ { name: "{{ .Values.imagePullSecretName }}" } ]
      {{- end }}
      {{- if .Values.dateAnnotationValue }}
      annotations: { "metering.deploy-custom/deploy-time": "{{ .Values.dateAnnotationValue }}" }
      {{- end }}
      {{- if .Values.terminationGracePeriodSeconds  }}
      terminationGracePeriodSeconds: {{ .Values.terminationGracePeriodSeconds }}
      {{- end }}
      config:
        aws:
          accessKeyID: "{{ .Values.awsAccessKeyId }}"
          secretAccessKey: "{{ .Values.awsSecretAccessKey }}"
      {{- if or .Values.prestoMemory .Values.prestoCpu }}
      coordinator:
        {{- if or .Values.prestoMemory .Values.prestoCpu }}
        resources:
          requests:
            memory: "{{ .Values.prestoMemory }}"
            cpu: "{{ .Values.prestoCpu }}"
        {{- end }}
      {{- end }}
  hive:
    spec:
      config:
        aws:
          accessKeyID: "{{ .Values.awsAccessKeyId }}"
          secretAccessKey: "{{ .Values.awsSecretAccessKey }}"
      {{- if .Values.imagePullSecretName }}
      image:
        imagePullSecrets: [ { name: "{{ .Values.imagePullSecretName }}" } ]
      {{- end }}
      {{- if .Values.dateAnnotationValue }}
      annotations: { "metering.deploy-custom/deploy-time": "{{ .Values.dateAnnotationValue }}" }
      {{- end }}
      {{- if .Values.terminationGracePeriodSeconds  }}
      terminationGracePeriodSeconds: {{ .Values.terminationGracePeriodSeconds }}
      {{- end }}
      {{- if or .Values.hiveMetastoreMemory .Values.hiveMetastoreCpu .Values.hiveMetastoreStorageSize }}
      metastore:
        {{- if or .Values.hiveMetastoreMemory .Values.hiveMetastoreCpu }}
        resources:
          requests:
            memory: "{{ .Values.hiveMetastoreMemory }}"
            cpu: "{{ .Values.hiveMetastoreCpu }}"
        {{- end }}
        {{- if .Values.hiveMetastoreStorageSize }}
        storage:
          size: "{{ .Values.hiveMetastoreStorageSize }}"
        {{- end }}
      {{- end }}
      {{- if or .Values.hiveServerMemory .Values.hiveServerCpu .Values.hiveServerStorageSize }}
      server:
        {{- if or .Values.hiveServerMemory .Values.hiveServerCpu }}
        resources:
          requests:
            memory: "{{ .Values.hiveServerMemory }}"
            cpu: "{{ .Values.hiveServerCpu }}"
        {{- end }}
      {{- end }}

  hadoop:
    spec:
      {{- if .Values.imagePullSecretName }}
      imagePullSecrets: [ { name: "{{ .Values.imagePullSecretName }}" } ]
      {{- end }}
      hdfs:
        enabled: true
        datanode:
          {{- if .Values.dateAnnotationValue }}
          annotations: { "metering.deploy-custom/deploy-time": "{{ .Values.dateAnnotationValue }}" }
          {{- end }}
          {{- if .Values.terminationGracePeriodSeconds  }}
          terminationGracePeriodSeconds: {{ .Values.terminationGracePeriodSeconds }}
          {{- end }}
          {{- if .Values.hdfsDatanodeMemory }}
          resources:
            requests:
              memory: "{{ .Values.hdfsDatanodeMemory }}"
          {{- end }}
          {{- if .Values.hdfsDatanodeStorageSize }}
          storage:
            size: {{ .Values.hdfsDatanodeStorageSize }}
          {{- end }}
        namenode:
          {{- if .Values.dateAnnotationValue }}
          annotations: { "metering.deploy-custom/deploy-time": "{{ .Values.dateAnnotationValue }}" }
          {{- end }}
          {{- if .Values.terminationGracePeriodSeconds  }}
          terminationGracePeriodSeconds: {{ .Values.terminationGracePeriodSeconds }}
          {{- end }}
          {{- if .Values.hdfsNamenodeMemory }}
          resources:
            requests:
              memory: "{{ .Values.hdfsNamenodeMemory }}"
          {{- end }}
          {{- if .Values.hdfsNamenodeStorageSize   }}
          storage:
            size: {{ .Values.hdfsNamenodeStorageSize }}
          {{- end }}
