{{ if .Values.argocd.enabled }}
apiVersion: argoproj.io/v1alpha1
kind: AppProject
metadata:
  name: {{.Values.customer}}
  namespace: argocd
spec:
  syncWindows:
  - kind: allow
    schedule: "{{ .Values.argocd.sync_window_start }}"
    duration: {{ .Values.argocd.sync_window_duration }}
    timeZone: {{ .Values.timeZone }}
    manualSync: true
    applications:
    - {{.Values.customer}}
  sourceRepos:
  - '*'
  destinations:
  - name: in-cluster
    server: https://kubernetes.default.svc
    namespace: '*'
  clusterResourceWhitelist:
  - group: '*'
    kind: '*'
---
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
  name: {{.Values.customer}}
  namespace: argocd
spec:
  project: {{.Values.customer}}
  source:
    repoURL: git@github.com:GoalProfit/gp-helm-repository.git
    targetRevision: HEAD
    path: {{.Values.customer}}
  destination:
    server: 'https://kubernetes.default.svc'
    namespace: {{.Values.namespace}}

  syncPolicy:
    automated: # automated sync by default retries failed attempts 5 times with following delays between attempts ( 5s, 10s, 20s, 40s, 80s ); retry controlled using `retry` field.
      prune: true # Specifies if resources should be pruned during auto-syncing ( false by default ).
      selfHeal: true # Specifies if partial app sync should be executed when resources are changed only in target Kubernetes cluster and no git change detected ( false by default ).
      allowEmpty: false # Allows deleting all application resources during automatic syncing ( false by default ).
    syncOptions:     # Sync options which modifies sync behavior
    - Validate=false # disables resource validation (equivalent to 'kubectl apply --validate=false') ( true by default ).
    - CreateNamespace=true # Namespace Auto-Creation ensures that namespace specified as the application destination exists in the destination cluster.
    - PrunePropagationPolicy=foreground # Supported policies are background, foreground and orphan.
    - PruneLast=true # Allow the ability for resource pruning to happen as a final, implicit wave of a sync operation
{{ end }}
