{{- if .Values.kustomization }}
apiVersion: kustomize.toolkit.fluxcd.io/v1
kind: Kustomization
metadata:
  name: {{ .Values.kustomization.name }}
  namespace: {{ .Values.kustomization.namespace }}
  labels:
    app.kubernetes.io/name: bakery-ia
    app.kubernetes.io/component: flux
spec:
  # Wait for GitRepository to be ready before reconciling
  dependsOn: []
  interval: {{ .Values.kustomization.interval }}
  path: {{ .Values.kustomization.path }}
  prune: {{ .Values.kustomization.prune }}
  sourceRef:
    kind: {{ .Values.kustomization.sourceRef.kind }}
    name: {{ .Values.kustomization.sourceRef.name }}
  targetNamespace: {{ .Values.kustomization.targetNamespace }}
  timeout: {{ .Values.kustomization.timeout }}
  retryInterval: {{ .Values.kustomization.retryInterval }}
  wait: {{ .Values.kustomization.wait }}
  {{- if .Values.kustomization.healthChecks }}
  healthChecks:
    {{- range .Values.kustomization.healthChecks }}
    - apiVersion: {{ .apiVersion }}
      kind: {{ .kind }}
      name: {{ .name }}
      namespace: {{ .namespace }}
    {{- end }}
  {{- end }}
  {{- if .Values.kustomization.postBuild }}
  postBuild:
    substituteFrom:
      {{- range .Values.kustomization.postBuild.substituteFrom }}
      - kind: {{ .kind }}
        name: {{ .name }}
        {{- if .optional }}
        optional: {{ .optional }}
        {{- end }}
      {{- end }}
  {{- end }}
{{- end }}