apiVersion: fluxcd.controlplane.io/v1
kind: FluxInstance
metadata:
  name: {{ include "flux-instance.fullname" . }}
  namespace: {{ .Release.Namespace }}
  labels:
    {{- include "flux-instance.labels" . | nindent 4 }}
    {{- with .Values.commonLabels }}
    {{- toYaml . | nindent 4 }}
    {{- end }}
  {{- with .Values.commonAnnotations }}
  annotations:
    {{- toYaml . | nindent 4 }}
  {{- end }}
spec:
  distribution:
    version: {{ .Values.instance.distribution.version }}
    registry: {{ .Values.instance.distribution.registry }}
    artifact: {{ .Values.instance.distribution.artifact }}
    {{- if .Values.instance.distribution.artifactPullSecret }}
    artifactPullSecret: {{ .Values.instance.distribution.artifactPullSecret }}
    {{- end }}
    {{- if .Values.instance.distribution.imagePullSecret }}
    imagePullSecret: {{ .Values.instance.distribution.imagePullSecret }}
    {{- end }}
  components: {{ .Values.instance.components | toYaml | nindent 4 }}
  cluster: {{ .Values.instance.cluster | toYaml | nindent 4 }}
  {{- if or .Values.instance.commonMetadata.annotations  .Values.instance.commonMetadata.labels }}
  commonMetadata:
    {{- with .Values.instance.commonMetadata.annotations }}
    annotations:
      {{- toYaml . | nindent 6 }}
    {{- end }}
    {{- with .Values.instance.commonMetadata.labels }}
    labels:
      {{- toYaml . | nindent 6 }}
    {{- end }}
  {{- end }}
  kustomize: {{ .Values.instance.kustomize | toYaml | nindent 4 }}
  {{- if .Values.instance.sync.url }}
  sync:
    kind: {{ .Values.instance.sync.kind }}
    interval: {{ .Values.instance.sync.interval }}
    url: {{ .Values.instance.sync.url }}
    ref: {{ .Values.instance.sync.ref }}
    path: {{ .Values.instance.sync.path }}
    {{- if .Values.instance.sync.name }}
    name: {{ .Values.instance.sync.name }}
    {{- end }}
    {{- if .Values.instance.sync.provider }}
    provider: {{ .Values.instance.sync.provider }}
    {{- end }}
    {{- if .Values.instance.sync.pullSecret }}
    pullSecret: {{ .Values.instance.sync.pullSecret }}
    {{- end }}
  {{- end }}
  {{- if .Values.instance.storage.size }}
  storage: {{ .Values.instance.storage | toYaml | nindent 4 }}
  {{- end }}
  {{- if .Values.instance.sharding.shards }}
  sharding:
    key: {{ .Values.instance.sharding.key }}
    shards: {{ .Values.instance.sharding.shards | toYaml | nindent 4 }}
  {{- end }}
