---
version: "3"

tasks:
  gr-sync:
    desc: Sync all Flux GitRepositories
    cmds:
      - |
        kubectl get gitrepositories --all-namespaces --no-headers | awk '{print $1, $2}' \
          | xargs -P 4 -L 1 bash -c \
            'kubectl -n $0 annotate gitrepository/$1 reconcile.fluxcd.io/requestedAt=$(date +%s) --field-manager=flux-client-side-apply --overwrite'

  ks-sync:
    desc: Sync all Flux Kustomizations
    cmds:
      - |
        kubectl get kustomization --all-namespaces --no-headers | awk '{print $1, $2}' \
          | xargs -P 4 -L 1 bash -c \
            'kubectl -n $0 annotate kustomization/$1 reconcile.fluxcd.io/requestedAt="$(date +%s)" --field-manager=flux-client-side-apply --overwrite'

  ks-suspend:
    desc: Suspend all Flux Kustomizations
    cmds:
      - |
        flux get kustomizations --all-namespaces --no-header | awk '{print $1, $2}' \
          | xargs -L 1 bash -c 'flux -n $0 suspend kustomization $1'

  ks-resume:
    desc: Resume all Flux Kustomizations
    cmds:
      - |
        flux get kustomizations --all-namespaces --no-header | awk '{print $1, $2}' \
          | xargs -L 1 bash -c 'flux -n $0 resume kustomization $1'

  hr-sync:
    desc: Sync all Flux HelmReleases
    cmds:
      - |
        kubectl get helmreleases --all-namespaces --no-headers | awk '{print $1, $2}' \
          | xargs -P 4 -L 1 bash -c \
            'kubectl -n $0 annotate helmrelease/$1 reconcile.fluxcd.io/requestedAt="$(date +%s)" --overwrite'

  tf-sync:
    desc: Sync Flux Terraforms
    cmds:
      - |
        kubectl get terraforms --all-namespaces --no-headers | awk '{print $1, $2}' \
          | xargs -P 4 -L 1 bash -c \
            'kubectl -n $0 annotate terraform/$1 reconcile.fluxcd.io/requestedAt="$(date +%s)" --overwrite'
  hr-suspend:
    desc: Suspend all Flux HelmReleases
    cmds:
      - |
        flux get helmrelease --all-namespaces --no-header | awk '{print $1, $2}' \
          | xargs -L 1 bash -c 'flux -n $0 suspend helmrelease $1'
  hr-resume:
    desc: Resume all Flux HelmReleases
    cmds:
      - |
        flux get helmrelease --all-namespaces --no-header | awk '{print $1, $2}' \
          | xargs -L 1 bash -c 'flux -n $0 resume helmrelease $1'