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

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

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

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

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

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

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

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

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