Skip to content

Commit

Permalink
Add hack/submodule-k8s script
Browse files Browse the repository at this point in the history
  • Loading branch information
Ben Moss committed Oct 14, 2020
1 parent 8c4c1ff commit ec2c2bf
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
39 changes: 39 additions & 0 deletions cluster-autoscaler/hack/submodule-k8s.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/usr/bin/env bash

###

set -o errexit
set -o pipefail

###
# This script is to be used as a break-glass solution if there is a breaking
# change in a release of Kubernetes. This allows us to switch to an unreleased
# commit by submoduling the whole k/k repository.
###

VERSION=${1}
if [ -z "$VERSION" ]; then
echo "Usage: hack/submodule-k8s.sh <k8s sha>"
exit 1
fi

set -x

MODS=($(
curl -sS https://raw.githubusercontent.com/kubernetes/kubernetes/${VERSION}/go.mod |
sed -n 's|.*k8s.io/\(.*\) => ./staging/src/k8s.io/.*|k8s.io/\1|p'
))

git submodule add --force https://github.com/kubernetes/kubernetes
git submodule update --init --recursive --remote
cd kubernetes
git checkout $VERSION
cd ..

go mod edit "-replace=k8s.io/kubernetes=./kubernetes"

for MOD in "${MODS[@]}"; do
go mod edit "-replace=${MOD}=./kubernetes/staging/src/${MOD}"
done
go mod vendor
go mod tidy
14 changes: 14 additions & 0 deletions cluster-autoscaler/hack/update-vendor.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
#!/usr/bin/env bash

###
# This script is to be used when updating Kubernetes and its staging
# repositories to *tagged* releases. This is the ideal case, but another
# script, submodule-k8s.sh, is available as a break-glass solution if we must
# switch to an unreleased commit.
###

set -o errexit
set -o pipefail

Expand All @@ -8,10 +15,14 @@ if [ -z "$VERSION" ]; then
echo "Usage: hack/update-vendor.sh <k8s version>"
exit 1
fi

set -x

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'
))

for MOD in "${MODS[@]}"; do
V=$(
go mod download -json "${MOD}@kubernetes-${VERSION}" |
Expand All @@ -20,3 +31,6 @@ for MOD in "${MODS[@]}"; do
go mod edit "-replace=${MOD}=${MOD}@${V}"
done
go get "k8s.io/kubernetes@v${VERSION}"
go mod vendor
go mod tidy
git rm -r --force kubernetes

0 comments on commit ec2c2bf

Please sign in to comment.