how to patch all deployments at a time

11/17/2020

I am running below command to restart pods , but i could able to patch one deployment at a time, requirement is to patch all the deployments in namespace at a time.

  oc patch deploy  buy-api  -p "{\"spec\":{\"template\":{\"metadata\":{\"annotations\":{\"date\":\"`date +'%s'`\"}}}}}"

Could somebody help me to find command to apply patch for all the deployments in one shot.

Thanks in Advance

-- ramesh reddy
kubernetes
openshift

1 Answer

11/17/2020

Using awk and xargs you can do that:

oc get deploy | awk '{print $1 }' | xargs oc patch deploy $0  -p "{\"spec\":{\"template\":{\"metadata\":{\"annotations\":{\"date\":\"`date +'%s'`\"}}}}}"
-- Shai Katz
Source: StackOverflow