0

I am using ArgoCD for a couple of weeks now and I don't really understand how to define spec.source.path in the application.

I have set the following path:

...
spec:
  source:
    repoURL: https://github.com/theautomation/home-assistant.git
    targetRevision: main
    path: deploy/k8s
...

but still argoCD syncs when a commit is committed outside this path in the repo, argoCD should ONLY watch this path for changes right? or does it not work that way?

Full application yaml:

---
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
  name: home-assistant
  namespace: devops
  annotations:
    notifications.argoproj.io/subscribe.slack: cicd
    argocd.argoproj.io/manifest-generate-paths: /deploy
spec:
  project: default
  source:
    repoURL: https://github.com/theautomation/home-assistant.git
    targetRevision: main
    path: deploy/k8s
    directory:
      recurse: true
  destination:
    server: https://kubernetes.default.svc
    namespace: home-automation
  syncPolicy:
    syncOptions:
      - CreateNamespace=true
      - Validate=true
      - PrunePropagationPolicy=foreground
      - PruneLast=true
    automated:
      selfHeal: true
      prune: true
    retry:
      limit: 2
      backoff:
        duration: 5s
        factor: 2
        maxDuration: 3m
Nick ODell
  • 15,465
  • 3
  • 32
  • 66
theautomation
  • 35
  • 1
  • 6

2 Answers2

1

By default, Argo CD will sync when the commit changes regardless of what files were modified. This can be helpful when something in an App's directory references (via symlink or some other mechanism) something outside its directory.

If you are using webhooks to trigger the syncs, and you know an App isn't influenced by outside files, you can use an annotation to specify which directory (or directories) to watch for changes.

If you are not using webhooks and are relying on the usual reconciliation loop, the sync will still happen regardless of the annotation.

crenshaw-dev
  • 7,504
  • 3
  • 45
  • 81
  • Thanks for your answer, I will try webhooks but I don't want to expose my ArgoCD deployment to the wordwideweb so I guess I have to figure out how to trigger a webhook from local network after a commit, maybe a CI pipeline... – theautomation Jul 30 '22 at 17:40
  • That makes sense. I agree, avoiding publicly exposing Argo CD is a good idea. – crenshaw-dev Aug 01 '22 at 13:51
0

Argo CD will ONLY look for changes that have been applied to your targetRevision (ie main) and changes within your defined path. Assuming you have deploy/k8s with a bunch of manifests in that space, it will automatically look for changes to files within that path. Also, bc you have syncPolicy.automated configured, it will automatically apply changes when it is found (normally ab 3-5 mins bc of git polling, unless you have have webhooks configured)

LostJon
  • 2,287
  • 11
  • 20
  • Thanks for your answer, what you describe is not happening i have setup the path in the application to: ```/deploy/k8s``` but when i commit for example to: ```/README.md``` it also trigger an sync in argoCD – theautomation Jul 25 '22 at 20:45
  • is it possible your application manifest that is applied is NOT what is represented in git? If you go to the UI and dig into the application manifest details, does it reflect whats in git? you can also `kubectl get application home-assistant -o yaml` to verify – LostJon Jul 26 '22 at 19:12