Created
June 30, 2023 14:56
-
-
Save bpow/2575d4be22662799c638d037536d74de to your computer and use it in GitHub Desktop.
Gets the non-transient resources in a kubernetes/openshift namespace, outputting by resource types with bonus of decoding secrets to stringData
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
<<comment | |
REQUIREMENTS: | |
- kubectl (of course) | |
- krew "neat" plugin to remove some extra cruft | |
- yq to decode secrets to stringData | |
The resource types are: | |
- things to not keep | |
- pod : transient, no need to keep | |
- replicationcontroller : deprecated- should be replicaset now, also transient, created by dc | |
- job : transient (from job), no need to keep | |
- build : os-specific, transient, generated from buildconfig | |
- service | |
- cronjob | |
- deploymentconfig | |
- deployment | |
- statefulset | |
- buildconfig : os-specific | |
- imagestream : os-specific | |
- route | |
- configmap | |
- secret : may need special handling | |
- persistentvolumeclaim | |
- ingress | |
comment | |
#for resourceType in service cronjob deploymentconfig deployment statefulset buildconfig imagestream route configmap secret persistentvolumeclaim ingress template | |
for resourceType in svc cj dc deploy sts bc is route cm pvc ingress template secret | |
do | |
for resource in $(kubectl get -o name $resourceType | cut -f2 -d '/') | |
do | |
echo $resource | |
kubectl get -o yaml $resourceType $resource | kubectl neat | tee $resourceType-$resource.yaml | |
done | |
done | |
for resource in $(kubectl get -o name secret | cut -f2 -d '/') | |
do | |
kubectl get secret $resource -o yaml | kubectl neat \ | |
| yq '.stringData = (.data | to_entries | map(. + {"value": .value | @base64d }) | from_entries) | del(.data)' \ | |
| tee sdsecret-$resource.yaml | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment