{{- $kubeconfigBase64 := .Values.kubeconfig.base64 | default "" -}}
{{- $kubeconfigFile := .Values.kubeconfig.raw | default (.Files.Get "files/org.etsi.osl.cridge/kubeconfig.yaml") -}}
{{- $kubeconfig := "" -}}

{{- if $kubeconfigBase64 }}
  {{- $kubeconfig = $kubeconfigBase64 | b64dec }}
{{- else if $kubeconfigFile }}
  {{- $kubeconfig = $kubeconfigFile }}
{{- end }}

apiVersion: v1
kind: Secret
metadata:
  namespace: {{ .Release.Namespace }}
  labels:
    app: {{ include "openslice.fullname" . }}
    org.etsi.osl.service: cridge
    chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}"
    {{- include "openslice.labels" . | nindent 4 }}
  name: {{ include "openslice.fullname" . }}-kubeconfig
type: Opaque
data:
  config: |-
    {{- if $kubeconfig }}
    {{ $kubeconfig | b64enc | nindent 4 }}
    {{- else }}
    {{- required "A kubeconfig file is required." ($kubeconfig | b64enc) | nindent 4 }}
    {{- end }}
