Created
April 29, 2020 03:18
-
-
Save jonhiggs/ad410b5cc7ad104daed69fdcefc4b48c to your computer and use it in GitHub Desktop.
Rewrite deprecated kubernetes APIS. See https://redbubble.atlassian.net/wiki/spaces/SCAL/pages/989331583/Move+Off+Deprecated+Kubernetes+APIs
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
#!/usr/bin/env bash | |
[[ $# -eq 0 ]] && echo "Usage: $0 <kubernetes_manifest_file> ..." && exit 1 | |
_error() { | |
echo "$@" >&2 | |
} | |
api_versions() { | |
awk 'BEGIN {} | |
($1~/kind:/) { kind=$2 } | |
($1~/apiVersion:/) { api_version=$2; nr=NR } | |
(kind!="" && api_version!="") { | |
print nr, kind, api_version | |
kind=""; api_version="" | |
} | |
' /dev/stdin | |
} | |
api_new_versions() { | |
awk '($2=="Deployment") && ($3=="apps/v1beta1") { $3="apps/v1" } | |
($2=="Deployment") && ($3=="extensions/v1beta1") { $3="apps/v1" } | |
($2=="DaemonSet") && ($3=="extensions/v1beta1") { $3="apps/v1" } | |
($2=="Ingress") && ($3=="extensions/v1beta1") { $3="networking.k8s.io/v1beta1" } | |
{ print $0 }' \ | |
/dev/stdin | |
} | |
for file in "$@"; do | |
[[ ! -f "${file}" ]] && _error "Skipping non-existent '${file}'" && continue | |
new_file="$1.tmp" | |
cp "${file}" "${new_file}" | |
IFS=$'\n' | |
for l in $(cat "${file}" | api_versions | api_new_versions); do | |
nr=$(awk '{ print $1 }' <(echo "$l")) | |
v=$(awk '{ print $3 }' <(echo "$l")) | |
sed -i".bak" "${nr}s!:.*!: ${v}!" "${new_file}"; rm "${new_file}.bak" | |
done | |
diff "${new_file}" "${file}" | |
mv "${new_file}" "${file}" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment