Issue
I am using oc
command (kubectl
alternative for Openshift Clusters) to get pods based on a certain condition like this:
oc get pods -n mynamespace | awk '/mypod-2022-(.)*/{print $1}'
It will give me the following output:
mypod-2022-07-01-11-23-driver
mypod-2022-07-02-11-19-driver
...
Now for each of the pod names I receive above, I need to execute the following curl command:
curl -X POST \
'https://<my endpoint>/podDelete' \
--header 'Authorization: Bearer token' \
--header 'Content-Type: application/json' \
--data-raw '{"POD_NAME": "<output>"}'
I tried following the accepted answer of this question, however xargs -i
does not seem to work in 2022. So is there a way I can substitute <output>
with each of the lines I receive from xargs
and run the curl command?
Solution
You can try this pipeline with xargs -I {}
:
oc get pods -n mynamespace | awk '$1 ~ /^mypod-2022-/{print $1}' |
xargs -I {} curl -X POST 'https://<my endpoint>/podDelete' \
--header 'Authorization: Bearer token' \
--header 'Content-Type: application/json' \
'{"POD_NAME": "{}"}'
Answered By - anubhava Answer Checked By - Cary Denson (WPSolving Admin)