{{- /*
Copyright Broadcom, Inc. All Rights Reserved.
SPDX-License-Identifier: APACHE-2.0
*/}}

apiVersion: v1
kind: ConfigMap
metadata:
  name: {{ include "harbor.jobservice" . }}-config
  namespace: {{ include "common.names.namespace" . | quote }}
  {{- $versionLabel := dict "app.kubernetes.io/version" ( include "common.images.version" ( dict "imageRoot" .Values.jobservice.image "chart" .Chart ) ) }}
  {{- $labels := include "common.tplvalues.merge" ( dict "values" ( list .Values.commonLabels $versionLabel ) "context" . ) }}
  labels: {{- include "common.labels.standard" ( dict "customLabels" $labels "context" $ ) | nindent 4 }}
    app.kubernetes.io/component: jobservice
  {{- if .Values.commonAnnotations }}
  annotations: {{- include "common.tplvalues.render" ( dict "value" .Values.commonAnnotations "context" $ ) | nindent 4 }}
  {{- end }}
data:
  config.yml: |+
    #Server listening port
    protocol: {{ ternary "https" "http" .Values.internalTLS.enabled | quote }}
    port: {{ ternary .Values.jobservice.containerPorts.https .Values.jobservice.containerPorts.http .Values.internalTLS.enabled }}
    {{- if .Values.internalTLS.enabled }}
    https_config:
      cert: "/etc/harbor/ssl/jobservice/tls.crt"
      key: "/etc/harbor/ssl/jobservice/tls.key"
    {{- end }}
    worker_pool:
      workers: {{ .Values.jobservice.maxJobWorkers }}
      backend: "redis"
      redis_pool:
        namespace: {{ .Values.jobservice.redisNamespace | quote }}
    job_loggers:
      {{- if eq .Values.jobservice.jobLogger "file" }}
      - name: "FILE"
        level: {{ .Values.logLevel | upper }}
        settings: # Customized settings of logger
          base_dir: "/var/log/jobs"
        sweeper:
          duration: 14 #days
          settings: # Customized settings of sweeper
            work_dir: "/var/log/jobs"
      {{- else if eq .Values.jobservice.jobLogger "database" }}
      - name: "DB"
        level: {{ .Values.logLevel | upper }}
        sweeper:
          duration: 14 #days
      {{- else }}
      - name: "STD_OUTPUT"
        level: {{ .Values.logLevel | upper }}
      {{- end }}
    #Loggers for the job service
    loggers:
      - name: "STD_OUTPUT"
        level: {{ .Values.logLevel | upper }}
    metric:
      enabled: {{ .Values.metrics.enabled }}
      path: {{ .Values.metrics.path }}
      port: {{ .Values.jobservice.containerPorts.metrics }}
    reaper:
      max_update_hours: {{ .Values.jobservice.reaper.maxUpdateHours }}
      max_dangling_hours: {{ .Values.jobservice.reaper.maxDanglingHours }}
