{{/*
# Copyright 2020-present Open Networking Foundation

# SPDX-License-Identifier: LicenseRef-ONF-Member-Only-1.0
*/}}

{{- if .Values.config.udr.deploy }}

{{- if not .Values.config.useExistingConfigMap -}}
{{- $udrcfg := index .Values.config.udr.cfgFiles "udrcfg.conf" }}
{{- $config := index $udrcfg "configuration" }}
{{- $sbi := index $config "sbi" }}

{{- if not (hasKey $config "mongodb") -}}
{{- $_ := dict "name" .Values.config.mongodb.name "url" .Values.config.mongodb.url | set $config "mongodb" -}}
{{- end }}

{{- if not (hasKey $udrcfg "logger") -}}
{{- $_ := .Values.config.logger | set $udrcfg "logger" -}}
{{- end }}

{{- if not (hasKey $sbi "port") -}}
{{- $_ := .Values.config.udr.sbi.port | set $sbi "port" -}}
{{- end }}
{{- end }}

---
apiVersion: v1
kind: ConfigMap
metadata:
  name: udr
  labels:
{{ tuple "udr" . | include "5g-control-plane.metadata_labels" | indent 4 }}
data:
  udr-run.sh: |
{{ tuple "bin/_udr-run.sh.tpl" . | include "5g-control-plane.template" | indent 4 }}
{{- if not .Values.config.useExistingConfigMap -}}
{{- range $key, $value := .Values.config.udr.cfgFiles }}
  {{ $key }}: |-
{{ toYaml $value | indent 4 }}
{{- end }}
{{- end }}
{{- end }}
