Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jovemfelix/2756f1fce75b8db1abd8fecb72dfe2e7 to your computer and use it in GitHub Desktop.
Save jovemfelix/2756f1fce75b8db1abd8fecb72dfe2e7 to your computer and use it in GitHub Desktop.
Script to clean YAML using yq
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
@ammachado
Copy link

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