-
Notifications
You must be signed in to change notification settings - Fork 74
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
update Go mod support #34
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
#!/usr/bin/env bash | ||
|
||
# Copyright 2019 The Kubernetes Authors. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
# This script can be used while converting a repo from "dep" to "go mod" | ||
# by calling it after "go mod init" or to update the Kubernetes packages | ||
# in a repo that has already been converted. Only packages that are | ||
# part of kubernetes/kubernetes and thus part of a Kubernetes release | ||
# are modified. Other k8.io packages (like k8s.io/klog, k8s.io/utils) | ||
# need to be updated separately. | ||
|
||
set -o pipefail | ||
|
||
cmd=$0 | ||
|
||
function help () { | ||
echo "$cmd <kubernetes version = x.y.z> - update all components from kubernetes/kubernetes to that version" | ||
} | ||
|
||
if [ $# -ne 1 ]; then | ||
help | ||
exit 1 | ||
fi | ||
case "$1" in -h|--help|help) help; exit 0;; esac | ||
|
||
die () { | ||
echo >&2 "$@" | ||
exit 1 | ||
} | ||
|
||
k8s="$1" | ||
|
||
# If the repo imports k8s.io/kubernetes (directly or indirectly), then | ||
# "go mod" will try to find "v0.0.0" versions because | ||
# k8s.io/kubernetes has those in it's go.mod file | ||
# (https://github.com/kubernetes/kubernetes/blob/2bd9643cee5b3b3a5ecbd3af49d09018f0773c77/go.mod#L146-L157). | ||
# (https://github.com/kubernetes/kubernetes/issues/79384). | ||
# | ||
# We need to replicate the replace statements to override those fake | ||
# versions also in our go.mod file (idea and some code from | ||
# https://github.com/kubernetes/kubernetes/issues/79384#issuecomment-521493597). | ||
mods=$( (set -x; curl --silent --show-error --fail "https://raw.githubusercontent.com/kubernetes/kubernetes/v${k8s}/go.mod") | | ||
sed -n 's|.*k8s.io/\(.*\) => ./staging/src/k8s.io/.*|k8s.io/\1|p' | ||
) || die "failed to determine Kubernetes staging modules" | ||
for mod in $mods; do | ||
# The presence of a potentially incomplete go.mod file affects this command, | ||
# so move elsewhere. | ||
modinfo=$(set -x; cd /; env GO111MODULE=on go mod download -json "$mod@kubernetes-${k8s}") || | ||
die "failed to determine version of $mod: $modinfo" | ||
v=$(echo "$modinfo" | sed -n 's|.*"Version": "\(.*\)".*|\1|p') | ||
(set -x; env GO111MODULE=on go mod edit "-replace=$mod=$mod@$v") || die "'go mod edit' failed" | ||
done | ||
|
||
packages= | ||
|
||
# Beware that we have to work with packages, not modules (i.e. no -m | ||
# flag), because some modules trigger a "no Go code except tests" | ||
# error. Getting their packages works. | ||
if ! packages=$( (set -x; env GO111MODULE=on go list all) | grep ^k8s.io/ | sed -e 's; *;;'); then | ||
cat >&2 <<EOF | ||
|
||
Warning: "GO111MODULE=on go list all" failed, trying individual packages instead. | ||
|
||
EOF | ||
if ! packages=$( (set -x; env GO111MODULE=on go list -f '{{ join .Deps "\n" }}' ./...) | grep ^k8s.io/); then | ||
cat >&2 <<EOF | ||
|
||
ERROR: could not obtain package list, both of these commands failed: | ||
GO111MODULE=on go list all | ||
GO111MODULE=on go list -f '{{ join .Deps "\n" }}' ./pkg/... | ||
EOF | ||
exit 1 | ||
fi | ||
fi | ||
|
||
deps= | ||
for package in $packages; do | ||
# Some k8s.io packages do not come from Kubernetes staging and | ||
# thus have different versioning (or none at all...). We need to | ||
# skip those. We know what packages are from staging because we | ||
# now have "replace" statements for them in go.mod. | ||
# | ||
# shellcheck disable=SC2001 | ||
module=$(echo "$package" | sed -e 's;k8s.io/\([^/]*\)/.*;k8s.io/\1;') | ||
if grep -q -w "$module *=>" go.mod; then | ||
deps="$deps $(echo "$package" | sed -e "s;\$;@kubernetes-$k8s;" -e 's;^k8s.io/kubernetes\(/.*\)@kubernetes-;k8s.io/kubernetes\1@v;')" | ||
fi | ||
done | ||
|
||
# shellcheck disable=SC2086 | ||
(set -x; env GO111MODULE=on go get $deps 2>&1) || die "go get failed" | ||
echo "SUCCESS" |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we actually have repos that do this? I checked csi-lib-utils and external-provisioner, and didn't find any kubernetes/kubernetes dependencies.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
k8s.io/kubernetes
does get pulled in at the moment:For the driver it is the mount code which still hasn't been moved into a staging repo (there is work under way, I just don't remember how far it got). Not sure for
external-provisioner
, haven't checked.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mount dependency is expected and will soon be removed. In general, we should start trying to cleanup and avoid any k8s.io/kubernetes dependencies. But I guess it's fine to have this script in the meantime.
Does this help with the non-k8s.io/kubernetes repos (like k8s.io/api)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
k8s.io/api is from k/k and gets updated by the script.
k8s.io/util isn't, but doesn't tag releases. k8s.io/klog has separate releases and shows up in
go.mod
with a proper version number (k8s.io/klog v0.3.1
). I think "go get" picks the version specified by some other go.mod file for those modules, just as it does for other modules outside of Kubernetes.