Last active
December 10, 2021 05:53
-
-
Save solidnerd/0adeeb6dc0b0fc23a249959a7283cbb8 to your computer and use it in GitHub Desktop.
Helper script to convert multiple ingress
This file contains hidden or 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/bash | |
set -e | |
set -o pipefail | |
# kubectl convert is a plugin or binary that can be used | |
# can be fetched from https://www.downloadkubernetes.com/ | |
# | |
KUBECTL_CONVERT_BIN=$HOME/Downloads/kubectl-convert | |
mkdir -p {pre,converted} | |
for ing in $(kubectl get ing -o go-template="{{range .items}}{{ .metadata.name }}{{\"\n\"}}{{end}}" 2>&1 | grep -i -v "Warn" | grep -i -v "Deprecat") | |
do | |
kubectl get ing $ing -o yaml > "pre/$ing.yaml" | |
# Transform the current ingress version to networking.k8s.io/v1 | |
$KUBECTL_CONVERT_BIN -f "pre/$ing.yaml" > "converted/$ing.yaml" --output-version networking.k8s.io/v1 | |
# Removes unintended fields from the converted yaml | |
yq e -i 'del(.status)' "converted/$ing.yaml" | |
yq e -i 'del(.metadata.uid)' "converted/$ing.yaml" | |
yq e -i 'del(.metadata.selfLink)' "converted/$ing.yaml" | |
yq e -i 'del(.metadata.resourceVersion)' "converted/$ing.yaml" | |
yq e -i 'del(.metadata.creationTimestamp)' "converted/$ing.yaml" | |
yq e -i 'del(.metadata.generation)' "converted/$ing.yaml" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment