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

{{- if .Values.plugins -}}
apiVersion: v1
kind: ConfigMap
metadata:
  name: {{ include "common.names.fullname" . }}-plugins
  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:
  install-plugins.sh: |
    #!/bin/bash
    echo "==> Plugin installation"
    {{- $totalPlugins := len .Values.plugins }}
    echo "Total plugins defined in chart installation: {{ $totalPlugins }}"
    {{- range $i, $plugin := .Values.plugins }}
    echo "Installing plugin {{ add $i 1 }} out of {{ $totalPlugins }}: {{ $plugin }}"
    kibana-plugin install "{{ $plugin }}"
    {{- end }}
    echo "==> End of Plugin installation"
{{- end -}}
