Created
March 25, 2025 19:51
-
-
Save Lumexralph/044b0af3fc4e5a3ad8b57294eb04edff to your computer and use it in GitHub Desktop.
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 | |
# This script is needed to help us resolve the k8s go modules that breaks: | |
# go list -m -json -mod=mod all | |
# Ref: https://github.com/kubernetes-csi/csi-driver-host-path/pull/583 | |
# How to use: bash go_k8s_mod_update.sh <kubernetes-version> | |
# Strict error handling | |
set -euo pipefail | |
# Function to print usage and exit | |
usage() { | |
echo "Usage: $0 <kubernetes-version>" | |
echo "Example: $0 1.28.3" | |
exit 1 | |
} | |
# Validate input | |
VERSION=${1#"v"} # Strip leading 'v' if present | |
if [ -z "$VERSION" ]; then | |
usage | |
fi | |
# Fetch Kubernetes modules from go.mod | |
echo "π Discovering Kubernetes modules..." | |
MODULES=$( | |
curl -sS "https://raw.githubusercontent.com/kubernetes/kubernetes/v${VERSION}/go.mod" | | |
grep -E "k8s.io/.* => ./staging/src/k8s.io" | | |
sed -E 's|.*k8s.io/([^ ]*) => ./staging/src/k8s.io/.*|k8s.io/\1|' | |
) | |
# Function to get module version | |
get_module_version() { | |
local module="$1" | |
go mod download -json "${module}@kubernetes-${VERSION}" | | |
grep -o '"Version": "[^"]*' | | |
cut -d'"' -f4 | |
} | |
# Update modules | |
echo "π Updating Kubernetes modules to version v${VERSION}..." | |
for MODULE in $MODULES; do | |
echo " Processing module: $MODULE" | |
MODULE_VERSION=$(get_module_version "$MODULE") | |
if [ -n "$MODULE_VERSION" ]; then | |
go mod edit "-replace=${MODULE}=${MODULE}@${MODULE_VERSION}" | |
echo " β Updated to ${MODULE_VERSION}" | |
else | |
echo " β Could not fetch version for $MODULE" | |
fi | |
done | |
# Update Kubernetes dependency | |
echo "π Finalizing Kubernetes version..." | |
go get "k8s.io/kubernetes@v${VERSION}" | |
echo "β¨ Kubernetes module updates complete!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment