Created
August 10, 2022 18:18
-
-
Save jovemfelix/2756f1fce75b8db1abd8fecb72dfe2e7 to your computer and use it in GitHub Desktop.
Script to clean YAML using yq
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
ORIGINAL_FILE=$1 | |
echo cleaning $1 | |
yq eval 'del(.metadata.annotations."kubectl.kubernetes.io/last-applied-configuration")' -i $ORIGINAL_FILE | |
yq eval 'del(.metadata.creationTimestamp)' -i $ORIGINAL_FILE | |
yq eval 'del(.metadata.generation)' -i $ORIGINAL_FILE | |
yq eval 'del(.metadata.managedFields)' -i $ORIGINAL_FILE | |
yq eval 'del(.metadata.ownerReferences)' -i $ORIGINAL_FILE | |
yq eval 'del(.metadata.resourceVersion)' -i $ORIGINAL_FILE | |
yq eval 'del(.metadata.selfLink)' -i $ORIGINAL_FILE | |
yq eval 'del(.metadata.uid)' -i $ORIGINAL_FILE | |
yq eval 'del(.status)' -i $ORIGINAL_FILE | |
# to use it just | |
sh ~/cleanup-kubernetes-resource-using-yq.sh my-yaml_file.yaml |
Você consegue apagar tudo de uma vez se você rodar yq eval 'del(.status,.metadata.managedFields,...)
Ou então você usa o plug-in "neat" do kubectl: https://github.com/itaysk/kubectl-neat. Já sai tudo limpo.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://gist.github.com/jovemfelix/ad9bb988903abd410cdcbbefb0762a56