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

{{- if and (not .Values.configurationCM) (and .Values.elasticsearch.hosts .Values.elasticsearch.port) }}
apiVersion: v1
kind: ConfigMap
metadata:
  name: {{printf "%s-conf" (include "common.names.fullname" .) }}
  namespace: {{ include "common.names.namespace" . | quote }}
  labels: {{- include "common.labels.standard" ( dict "customLabels" .Values.commonLabels "context" $ ) | nindent 4 }}
  {{- if .Values.commonAnnotations }}
  annotations: {{- include "common.tplvalues.render" ( dict "value" .Values.commonAnnotations "context" $ ) | nindent 4 }}
  {{- end }}
data:
  kibana.yml: |
    pid.file: /opt/bitnami/kibana/tmp/kibana.pid
    server.host: {{ .Values.configuration.server.host | quote }}
    server.port: {{ .Values.containerPorts.http }}
    elasticsearch.hosts: [{{ include "kibana.elasticsearch.url" . }}]
    {{- if .Values.configuration.server.basePath }}
    server.basePath: {{ .Values.configuration.server.basePath | quote }}
    {{- end }}
    {{- if .Values.configuration.server.publicBaseUrl }}
    server.publicBaseUrl: {{ include "common.tplvalues.render" ( dict "value" .Values.configuration.server.publicBaseUrl "context" $ ) }}
    {{- else }}
    {{- if .Values.ingress.enabled }}
    {{- $protocol := ternary "https" "http" .Values.ingress.tls -}}
    {{- $hostname := required "Ingress hostname must be specified" (tpl .Values.ingress.hostname .) }}
    server.publicBaseUrl: {{ printf "%s://%s" $protocol $hostname }}
    {{- end }}
    {{- end }}
    server.rewriteBasePath: {{ .Values.configuration.server.rewriteBasePath }}
    {{- if .Values.extraConfiguration }}
    {{- include "common.tplvalues.render" ( dict "value" .Values.extraConfiguration "context" $ ) | nindent 4 }}
    {{- end }}
{{- end }}
