# Move/add to $XDG_CONFIG_HOME/k9s/plugins.yaml
# Requires the cnpg kubectl plugin. See https://cloudnative-pg.io/docs/devel/kubectl-plugin/
#
# Cluster actions:
#   b         Request a new physical backup
#   h         View hibernate status
#   Shift-H   Hibernate cluster (this retains the data, but deletes everything else - including the cluster)
#   l         View cluster logs
#   Shift-L   View cluster logs pretty
#   p         Connect to the cluster via psql
#   r         Reload the cluster
#   Shift-R   Restart the cluster
#   s         View cluster status
#   Shift-S   View cluster status in verbose mode
#
# Namespace actions:
#   Shift-H   Wake up Hibernated cluster in this namespace (assumes cluster name equals namespace name)

plugins:
  cnpg-backup:
    shortCut: b
    description: Backup
    scopes:
      - cluster
    command: bash
    confirm: true
    background: false
    args:
      - -c
      - "kubectl cnpg backup $NAME -n $NAMESPACE --context \"$CONTEXT\" 2>&1 | less -R"
  cnpg-hibernate-status:
    shortCut: h
    description: Hibernate status
    scopes:
      - cluster
    command: bash
    background: false
    args:
      - -c
      - "kubectl cnpg hibernate status $NAME -n $NAMESPACE --context \"$CONTEXT\" 2>&1 | less -R"
  cnpg-hibernate:
    shortCut: Shift-H
    description: Hibernate
    confirm: true
    scopes:
      - cluster
    command: bash
    background: false
    args:
      - -c
      - "kubectl cnpg hibernate on $NAME -n $NAMESPACE --context \"$CONTEXT\" 2>&1 | less -R"
  cnpg-hibernate-off:
    shortCut: Shift-H
    description: Wake up hibernated cluster in this namespace
    confirm: true
    scopes:
      - namespace
    command: bash
    background: false
    args:
      - -c
      - "kubectl cnpg hibernate off $NAME -n $NAME --context \"$CONTEXT\" 2>&1 | less -R"
  cnpg-logs:
    shortCut: l
    description: Logs
    scopes:
      - cluster
    command: bash
    background: false
    args:
      - -c
      - "kubectl cnpg logs cluster $NAME -f -n $NAMESPACE --context $CONTEXT"      
  cnpg-logs-pretty:
    shortCut: Shift-L
    description: Logs pretty
    scopes:
      - cluster
    command: bash
    background: false
    args:
      - -c
      - "kubectl cnpg logs cluster $NAME -f -n $NAMESPACE --context $CONTEXT | kubectl cnpg logs pretty"
  cnpg-psql:
    shortCut: p
    description: PSQL shell
    scopes:
      - cluster
    command: bash
    background: false
    args:
      - -c
      - "kubectl cnpg psql $NAME -n $NAMESPACE --context $CONTEXT"
  cnpg-reload:
    shortCut: r
    description: Reload
    confirm: true
    scopes:
      - cluster
    command: bash
    background: false
    args:
      - -c
      - "kubectl cnpg reload $NAME -n $NAMESPACE --context \"$CONTEXT\" 2>&1 | less -R"
  cnpg-restart:
    shortCut: Shift-R
    description: Restart
    confirm: true
    scopes:
      - cluster
    command: bash
    background: false
    args:
      - -c
      - "kubectl cnpg restart $NAME -n $NAMESPACE --context \"$CONTEXT\" 2>&1 | less -R"
  cnpg-status:
    shortCut: s
    description: Status
    scopes:
      - cluster
    command: bash
    background: false
    args:
      - -c
      - "kubectl cnpg status $NAME -n $NAMESPACE --context \"$CONTEXT\" 2>&1 | less -R"
  cnpg-status-verbose:
    shortCut: Shift-S
    description: Status (verbose)
    scopes:
      - cluster
    command: bash
    background: false
    args:
      - -c
      - "kubectl cnpg status $NAME -n $NAMESPACE --context \"$CONTEXT\" --verbose 2>&1 | less -R"
