Skip to content

Instantly share code, notes, and snippets.

@LozanoMatheus
Created July 31, 2020 15:14
Show Gist options
  • Save LozanoMatheus/dd0f7f7164c3225dd25a5f346a57da88 to your computer and use it in GitHub Desktop.
Save LozanoMatheus/dd0f7f7164c3225dd25a5f346a57da88 to your computer and use it in GitHub Desktop.
Compare Kubernetes Objects versions from two clusters
#!/usr/bin/env bash
set -e
declare -r Cluster001="mlozano-eks-1-14"
declare -r Cluster002="mlozano-eks-1-17"
declare -rl K8s_Kind_list="$(<K8s_Kind_list.txt)"
kubectx "${Cluster001}" > /dev/null
for i in ${K8s_Kind_list}; do
declare -l Cluster001_Kind_${i}="$(kubectl explain "${i}" 2> /dev/null | awk '/VERSION/{ rc = 1; print $2 }; END { exit !rc }' || echo "unknown-kind")"
done
kubectx "${Cluster002}" > /dev/null
for i in ${K8s_Kind_list}; do
declare -l Cluster002_Kind_${i}="$(kubectl explain "${i}" 2> /dev/null | awk '/VERSION/{ rc = 1; print $2 }; END { exit !rc }' || echo "unknown-kind")"
done
for kind in ${!Cluster001_Kind_*} ${!Cluster002_Kind_*}; do
declare server="${kind//"_Kind_"*}"
All_Kinds+="${!server} ${kind//*"_Kind_"/} ${!kind}\n"
done
echo -e "${All_Kinds}" | sed '/^$/d' | pr -2 -t -s | column -t
Deployment
Ingress
CronJob
Service
ServiceMonitor
ConfigMap
Secret
mlozano-eks-1-17 configmap v1 mlozano-eks-1-14 configmap v1
mlozano-eks-1-17 cronjob batch/v1beta1 mlozano-eks-1-14 cronjob batch/v1beta1
mlozano-eks-1-17 deployment apps/v1 mlozano-eks-1-14 deployment extensions/v1beta1
mlozano-eks-1-17 ingress extensions/v1beta1 mlozano-eks-1-14 ingress extensions/v1beta1
mlozano-eks-1-17 secret v1 mlozano-eks-1-14 secret v1
mlozano-eks-1-17 service v1 mlozano-eks-1-14 service v1
mlozano-eks-1-17 test-kind unknown-kind mlozano-eks-1-14 test-kind unknown-kind
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment