Skip to content

Instantly share code, notes, and snippets.

@pbt001
Forked from cwilkers/annotate-pod.sh
Created June 22, 2020 21:35
Show Gist options
  • Save pbt001/79144b9699c176e5ee504b76d16e7f60 to your computer and use it in GitHub Desktop.
Save pbt001/79144b9699c176e5ee504b76d16e7f60 to your computer and use it in GitHub Desktop.
Script to annotate a pod with a Velero Restic volume list
#!/bin/bash
# This script adds Velero/Restic labels to a pod according to the pod's
# current volume set (filtering to only persistentVolumeClaims)
# According to https://heptio.github.io/velero/v0.11.0/restic
# TODO: Make this script produce help if options are not given
# Currently it just assumes you mean to annotate a NooBaa server pod
# Usage:
# annotate-pod.sh namespace pod
#
NS=${1:-noobaa}
POD=${2:-noobaa-server-0}
JQUERY="-o=jsonpath={.spec.volumes[?(@.persistentVolumeClaim)].name}"
PVS=$(oc -n ${NS} get pod ${POD} ${JQUERY} | tr ' ' ,)
oc -n ${NS} annotate pod/${POD} backup.velero.io/backup-volumes=${PVS}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment