Created
May 15, 2023 19:38
-
-
Save bartvdbraak/eddd19bfe578ed4ec3701af122fc12d0 to your computer and use it in GitHub Desktop.
List all apiVersions for each resource type in a Kubernetes cluster
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
#!/bin/bash | |
# Get the list of resource types | |
resource_types=$(kubectl api-resources | tail +2 | awk '{ print $1 }') | |
# Iterate over each resource type | |
for resource_type in $resource_types; do | |
echo "Resource Type: $resource_type" | |
# Get the latest usable apiVersion | |
latest_version=$(kubectl explain $resource_type | grep -e "VERSION:" | awk '{ print $2 }') | |
echo "Latest Version: $latest_version" | |
# Get other possible versions supported by the cluster | |
supported_versions=$(kubectl api-versions | grep -E "^$resource_type/" | awk -F/ '{ print $2 }') | |
if [[ -n $supported_versions ]]; then | |
echo "Supported Versions:" | |
for version in $supported_versions; do | |
echo "- $version" | |
done | |
else | |
echo "No other versions supported." | |
fi | |
echo "-------------------------------------------" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment