From f6ea04be9ee238873d6a9e66a58db7745a5378f3 Mon Sep 17 00:00:00 2001 From: "David A. Bradley" Date: Fri, 9 Jan 2026 08:27:47 -0500 Subject: [PATCH] Clean up update-gomod.sh script --- hack/update-gomod.sh | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/hack/update-gomod.sh b/hack/update-gomod.sh index 964105d15..b9965a97c 100755 --- a/hack/update-gomod.sh +++ b/hack/update-gomod.sh @@ -18,19 +18,29 @@ set -euo pipefail VERSION=${1#"v"} if [ -z "$VERSION" ]; then - echo "Must specify version!" + echo "Please specify the Kubernetes version: e.g." + echo "./update-gomod.sh v1.32.11" exit 1 fi -MODS=($( - curl -sS https://raw.githubusercontent.com/kubernetes/kubernetes/v${VERSION}/go.mod | + +# Determine which imports must be replaced +mapfile -t MODS < <( + curl -sS "https://raw.githubusercontent.com/kubernetes/kubernetes/v${VERSION}/go.mod" | sed -n 's|.*k8s.io/\(.*\) => ./staging/src/k8s.io/.*|k8s.io/\1|p' -)) +) + +# Add replace statements to the go.mod file with the version Kubernetes is using for them. for MOD in "${MODS[@]}"; do - echo $MOD + echo "${MOD}" V=$( go mod download -json "${MOD}@kubernetes-${VERSION}" | sed -n 's|.*"Version": "\(.*\)".*|\1|p' ) - echo ${V} + echo "${V}" go mod edit "-replace=${MOD}=${MOD}@${V}" done + +go get "k8s.io/kubernetes@v${VERSION}" +go mod download +go mod tidy +go mod vendor