0

I have a set of pods and they have volumes. I want to annotate each pod with

backup.velero.io/backup-volumes=<volume1 of that pod>,<volume2 of that pod>

I have tried to run a command like this

    kubectl get pods -n dev -o name | \
xargs -I{} kubectl -n dev annotate {} backup.velero.io/backup-volumes=$(bash -c 'kubectl get {} -n dev -o json | jq -r ".spec.volumes[0].name | paste -sd, -"') --overwrite

But, in this case the inner {} does seem to get the correct value. Is there an easier way to annotate the pods with the volumes that they have?

kosta
  • 4,302
  • 10
  • 50
  • 104

1 Answers1

1

I could solve it like this

kubectl get pods -n dev -o name | xargs -I{} sh -c 'kubectl -n dev annotate "$1" backup.velero.io/backup-volumes=$(kubectl get  "$1" -n dev -o json | jq -r .spec.volumes[].name | paste -sd, -) --overwrite' - {}
kosta
  • 4,302
  • 10
  • 50
  • 104