Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save stang/4c7ee4c7f58aef94b286b727435dd522 to your computer and use it in GitHub Desktop.
Save stang/4c7ee4c7f58aef94b286b727435dd522 to your computer and use it in GitHub Desktop.
#!/bin/bash
EXISTING_PG_CLUSTERS=$(kubectl get pg --all-namespaces -o json |jq '[.items[]|{name: .metadata.name}[]]')
CLUSTER_NAME_LABEL="cluster-name"
kubectl get svc --all-namespaces -l application=spilo -o json \
| jq -r --argjson EXISTING_PG_CLUSTERS "${EXISTING_PG_CLUSTERS}" \
--arg CLUSTER_NAME_LABEL "${CLUSTER_NAME_LABEL}" \
'
.items[]
|. as $x
|select($EXISTING_PG_CLUSTERS|(index($x.metadata.labels[$CLUSTER_NAME_LABEL])|not))
|"kubectl -n " + .metadata.namespace + " delete svc " + .metadata.name
' \
> patroni-headless-svc-config-cleanup.sh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment