pods= $( curl -s $base/api/v1/${ns}/pods?labelSelector=$selector | \ jq -r .items[].metadata.name ) for  pod in $pods;  do curl -s -X DELETE $base/api/v1/${ns}/pods/$pod done fi done Extract the type and name of the ConfigMap from the event. If the event indicates an update of the ConfigMap and our annotation is attached, then find all Pods matching this label selector. Extract all annotations on the ConfigMap with key  k8spatterns.io/podDeleteSelec‐ tor . See “Some jq Fu” on page 182 for an explanation of this jq expression. Delete all Pods that match the selector. First, the script extracts the event type that specifies what action happened to the ConfigMap. After we have extracted the ConfigMap, we derive the annotations with jq . jq is an excellent tool for parsing JSON documents from the command line, and the script assumes it is available in the container the script is running in. If the ConfigMap has annotations, we check for the annotation  k8spatterns.io/ podDeleteSelector  by using a more complex  jq  query. The purpose of this query is to convert the annotation value to a Pod selector that can be used in an API query option in the next step: an annotation  k8spatterns.io/podDeleteSelector: "app=webapp  is transformed to  app%3Dwebapp  that is used as a Pod selector. This con‐ version is performed with  jq  and is explained in “Some jq Fu” on page 182 if you are interested in how this extraction works. Extracting the ConfigMap’s  k8spatterns.io/podDeleteSelector  annotation value and converting it to a Pod selector is performed with  jq . This is an excellent JSON command-line tool, but some concepts can be a bit confusing. Let’s have a close look at how the expressions work in detail: Some jq Fu selector= $( echo $annotations |  \ jq -r "\ to_entries |\ .[] |\ select(.key == "k8spatterns.io/podDeleteSelector") |\ .value |\ @uri \  " ) 182  |  Chapter 22: Controller