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

<pre><code>backup.velero.io/backup-volumes=&lt;volume1 of that pod&gt;,&lt;volume2 of that pod&gt;
</code></pre>

<p>I have tried to run a command like this</p>

<pre><code>    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
</code></pre>

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

kosta
<p>I could solve it like this</p>

<pre><code>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' - {}
</code></pre>
