@@ -26,14 +26,43 @@ set -o pipefail
26
26
cmd=$0
27
27
28
28
function 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
30
49
}
31
50
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
+
32
62
if [ $# -ne 1 ]; then
33
63
help
34
64
exit 1
35
65
fi
36
- case " $1 " in -h|--help|help) help ; exit 0;; esac
37
66
38
67
die () {
39
68
echo >&2 " $@ "
@@ -55,7 +84,7 @@ mods=$( (set -x; curl --silent --show-error --fail "https://raw.githubuserconten
55
84
sed -n ' s|.*k8s.io/\(.*\) => ./staging/src/k8s.io/.*|k8s.io/\1|p'
56
85
) || die " failed to determine Kubernetes staging modules"
57
86
for 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
59
88
echo " Kubernetes module $mod is not used, skipping"
60
89
# Remove the module from go.mod "replace" that was added by an older version of this script.
61
90
(set -x; env GO111MODULE=on go mod edit " -dropreplace=$mod " ) || die " 'go mod edit' failed"
0 commit comments