@@ -26,14 +26,43 @@ set -o pipefail
2626cmd=$0
2727
2828function help () {
29- echo " $cmd <kubernetes version = x.y.z> - update all components from kubernetes/kubernetes to that version"
29+ cat << EOF
30+ $cmd -p <kubernetes version = x.y.z>
31+
32+ Update all components from kubernetes/kubernetes to that version.
33+
34+ By default, replace statements are added for all Kubernetes packages,
35+ whether they are used or not. This is useful when preparing a
36+ repository for using k8s.io/kubernetes, because those replace
37+ statements are needed to avoid "unknown revision v0.0.0" errors
38+ (https://github.com/kubernetes/kubernetes/issues/79384).
39+
40+ With the optional -p flag, all unused replace statements are
41+ pruned. This makes go.mod smaller, but isn't required.
42+
43+ The replace statements are needed for "go get -u ./..." which
44+ otherwise ends up updating Kubernetes packages like client-go to
45+ incompatible versions (in that case, a very old 1.x release which
46+ happens to have a "higher" version number than the current
47+ 0.<Kubernetes minor version>.<Kubernetes patch version> numbers.
48+ EOF
3049}
3150
51+ prune=false
52+
53+ while getopts " ph" o; do
54+ case " $o " in
55+ h) help ; exit 0;;
56+ p) prune=true;;
57+ * ) help ; exit 1;;
58+ esac
59+ done
60+ shift $(( OPTIND- 1 ))
61+
3262if [ $# -ne 1 ]; then
3363 help
3464 exit 1
3565fi
36- case " $1 " in -h|--help|help) help ; exit 0;; esac
3766
3867die () {
3968 echo >&2 " $@ "
@@ -55,7 +84,7 @@ mods=$( (set -x; curl --silent --show-error --fail "https://raw.githubuserconten
5584 sed -n ' s|.*k8s.io/\(.*\) => ./staging/src/k8s.io/.*|k8s.io/\1|p'
5685 ) || die " failed to determine Kubernetes staging modules"
5786for mod in $mods ; do
58- if ! (env GO111MODULE=on go mod graph) | grep " $mod @" > /dev/null; then
87+ if $prune && ! (env GO111MODULE=on go mod graph) | grep " $mod @" > /dev/null; then
5988 echo " Kubernetes module $mod is not used, skipping"
6089 # Remove the module from go.mod "replace" that was added by an older version of this script.
6190 (set -x; env GO111MODULE=on go mod edit " -dropreplace=$mod " ) || die " 'go mod edit' failed"
0 commit comments