{{<- $generator_folder_path := "manifests/deploykf-dependencies/istio" >}}
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
  name: dkf-dep--istio
  namespace: {{< .Values.argocd.namespace | quote >}}
  annotations:
    ## applications in 'deploykf-dependencies' come first
    ## NOTE: in this group, each application has a separate wave to avoid conflicts due to webhooks
    argocd.argoproj.io/sync-wave: "11"
  labels:
    app.kubernetes.io/name: istio
    app.kubernetes.io/component: deploykf-dependencies
    app.kubernetes.io/part-of: {{< print .Values.argocd.appNamePrefix "deploykf" | quote >}}
  finalizers:
    - resources-finalizer.argocd.argoproj.io
spec:
  project: {{< .Values.argocd.project | quote >}}
  {{<- if .Values.argocd.source.plugin.enabled >}}
  {{<- $output_helm_path := $generator_folder_path >}}
  {{<- $output_helm_values_files := coll.Slice "values-overrides.yaml" >}}
  source: {{< tmpl.Exec "argocd.plugin_source.helm" (dict "output_helm_path" $output_helm_path "output_helm_values_files" $output_helm_values_files) | yaml | toJSON >}}
  {{<- else >}}
  source:
    repoURL: {{< .Values.argocd.source.repo.url | quote >}}
    targetRevision: {{< .Values.argocd.source.repo.revision | quote >}}
    path: {{< path.Join .Values.argocd.source.repo.path $generator_folder_path | quote >}}
    helm:
      ignoreMissingValueFiles: true
      valueFiles:
        - values-overrides.yaml
  {{<- end >}}
  destination:
    {{<- if .Values.argocd.destination.name >}}
    name: {{< .Values.argocd.destination.name | quote >}}
    {{<- else >}}
    server: {{< .Values.argocd.destination.server | quote >}}
    {{<- end >}}
    namespace: {{< .Values.deploykf_dependencies.istio.namespace | quote >}}
  ignoreDifferences:
    ## istio patches the `failurePolicy` from "Ignore" to "Fail" once the webhook is up
    - group: admissionregistration.k8s.io
      kind: ValidatingWebhookConfiguration
      name: istiod-default-validator
      jqPathExpressions:
        - ".webhooks[]?.failurePolicy"
    {{<- if .Values.kubernetes.azure.admissionsEnforcerFix >}}
    ## azure aks admissions enforcer fix
    - group: admissionregistration.k8s.io
      kind: ValidatingWebhookConfiguration
      jqPathExpressions:
        - ".webhooks[]?.namespaceSelector"
    - group: admissionregistration.k8s.io
      kind: MutatingWebhookConfiguration
      jqPathExpressions:
        - ".webhooks[]?.namespaceSelector"
    {{<- end >}}