{{- if .Values.clusterConfig.argo.enabled }}
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
  name: linkerd
  namespace: argocd
  annotations:
    argocd.argoproj.io/sync-wave: "5"
spec:
  destination:
    namespace: linkerd
    server: 'https://kubernetes.default.svc'
  sources:
  - repoURL: {{ .Values.clusterConfig.manifests }}
    targetRevision: HEAD
    path: helmfile.d
    plugin:
      name: helmfile-cmp
      env:
      - name: CLUSTER_NAME
        value: {{ .Values.clusterConfig.cluster }}
      - name: HELMFILE_ENVIRONMENT
        value: default
      - name: HELMFILE_FILE_PATH
        value: linkerd.yaml.gotmpl
  project: sys
  syncPolicy:
    managedNamespaceMetadata:
      labels:
        component: sys
    syncOptions:
      - CreateNamespace=true
      - ApplyOutOfSyncOnly=true
      - ServerSideApply=true
    {{- if .Values.linkerd.autosync }}
    automated:
      prune: true
      # selfHeal: false
    {{- end }}
  ignoreDifferences:
  - group: batch
    kind: CronJob
    jsonPointers:
      - /spec/schedule
  - kind: Secret
    name:  linkerd-proxy-injector-k8s-tls
    jsonPointers:
    - /data/tls.crt
    - /data/tls.key
  - kind: Secret
    name:  linkerd-sp-validator-k8s-tls
    jsonPointers:
    - /data/tls.crt
    - /data/tls.key
  - kind: Secret
    name:  linkerd-tap-k8s-tls
    jsonPointers:
    - /data/tls.crt
    - /data/tls.key
  - kind: Secret
    name:  linkerd-policy-validator-k8s-tls
    jsonPointers:
    - /data/tls.crt
    - /data/tls.key
  - group: admissionregistration.k8s.io
    kind: MutatingWebhookConfiguration
    name: linkerd-proxy-injector-webhook-config
    jqPathExpressions:
      - '.webhooks[0].clientConfig.caBundle'
  - group: admissionregistration.k8s.io
    kind: ValidatingWebhookConfiguration
    name: linkerd-sp-validator-webhook-config
    jqPathExpressions:
      - '.webhooks[0].clientConfig.caBundle'
  - group: admissionregistration.k8s.io
    kind: ValidatingWebhookConfiguration
    name: linkerd-policy-validator-webhook-config
    jqPathExpressions:
      - '.webhooks[0].clientConfig.caBundle'
  - group: apiregistration.k8s.io/v1
    kind: APIService
    name: v1alpha1.tap.linkerd.io
    jsonPointers:
    - /spec/caBundle
{{- end }}
