{{- if and .Values.clustermesh.useAPIServer .Values.clustermesh.config.enabled .Values.clustermesh.apiserver.kvstoremesh.enabled }}
---
apiVersion: v1
kind: Secret
metadata:
  name: cilium-kvstoremesh
  namespace: {{ .Release.Namespace }}
data:
  {{- range .Values.clustermesh.config.clusters }}
  {{- $hasCustomCACert := or (.tls).caCert $.Values.clustermesh.apiserver.tls.ca.cert }}
  {{ .name }}: {{ include "clustermesh-config-generate-etcd-cfg" (list . $.Values.clustermesh.config.domain $hasCustomCACert "") | b64enc }}
  {{- /* The parenthesis around .tls are required, since it can be null: https://stackoverflow.com/a/68807258 */}}
  {{- if and (.tls).cert (.tls).key }}
  {{- if $hasCustomCACert }}
  {{ .name }}.etcd-client-ca.crt: {{ .tls.caCert | default $.Values.clustermesh.apiserver.tls.ca.cert }}
  {{- end }}
  {{ .name }}.etcd-client.key: {{ .tls.key }}
  {{ .name }}.etcd-client.crt: {{ .tls.cert }}
  {{- end }}
  {{- end }}
{{- end }}
