# https://github.com/derailed/k9s/blob/master/plugins/flux.yaml
# move selected line to chosen resource in K9s, then:
# Shift-T (with confirmation) to toggle helm releases or kustomizations suspend and resume
# Shift-R (no confirmation) to reconcile a git source or a helm release or a kustomization
plugin:

  toggle-helmrelease:
    shortCut: Shift-T
    confirm: true
    scopes:
      - helmreleases
    description: Toggle to suspend or resume a HelmRelease
    command: sh
    background: true
    args:
      - -c
      - "flux $([ $(kubectl get helmreleases -n $NAMESPACE $NAME -o=custom-columns=TYPE:.spec.suspend | tail -1) = \"true\" ] && echo \"resume\" || echo \"suspend\") helmrelease -n $NAMESPACE $NAME | less"

  toggle-kustomization:
    shortCut: Shift-T
    confirm: true
    scopes:
      - kustomizations
    description: Toggle to suspend or resume a Kustomization
    command: sh
    background: true
    args:
      - -c
      - "flux $([ $(kubectl get kustomizations -n $NAMESPACE $NAME -o=custom-columns=TYPE:.spec.suspend | tail -1) = \"true\" ] && echo \"resume\" || echo \"suspend\") kustomization -n $NAMESPACE $NAME | less"

  reconcile-git:
    shortCut: Shift-R
    confirm: false
    description: Flux reconcile
    scopes:
    - gitrepositories
    command: sh
    # background: false
    background: true
    args:
    - -c
    - "flux reconcile source git -n $NAMESPACE $NAME | less"

  reconcile-hr:
    shortCut: Shift-R
    confirm: false
    description: Flux reconcile
    scopes:
    - helmreleases
    command: sh
    # background: false
    background: true
    args:
    - -c
    - "flux reconcile helmrelease -n $NAMESPACE $NAME | less"

  reconcile-ks:
    shortCut: Shift-R
    confirm: false
    description: Flux reconcile
    scopes:
    - kustomizations
    command: sh
    # background: false
    background: true
    args:
    - -c
    - "flux reconcile kustomization -n $NAMESPACE $NAME | less"

  getall-ns:
    shortCut: Shift-G
    confirm: false
    description: Get All Resources in NS
    scopes:
    - namespaces
    command: sh
    background: false
    args:
    - -c
    - "kubectl get all -n $NAME | less"

  # https://github.com/derailed/k9s/issues/1017#issuecomment-769005253
  # requires https://github.com/rajatjindal/kubectl-modify-secret installed
  # i.e. by krew install modify-secret
  edit-secret:
    shortCut: Ctrl-X
    confirm: false
    description: "Edit Decoded Secret"
    scopes:
      - secrets
    command: kubectl
    background: false
    args:
      - modify-secret
      - --namespace
      - $NAMESPACE
      - --context
      - $CONTEXT
      - $NAME
