verify-no-vendor-cycles: set up Go environment

This script relies on Go but doesn't set up the private Go environment
(which ensures that the go command meets k/k's requirements). This
fixes that.

As a drive-by improvement, drop two unnecessary backslashes from
regexes (before / which doesn't need to be escaped).

Signed-off-by: Stephen Kitt <skitt@redhat.com>
This commit is contained in:
Stephen Kitt 2023-11-10 10:58:53 +01:00
parent 8a9b209cb1
commit f040d9012c
No known key found for this signature in database
GPG Key ID: 1CC5FA453662A71D

View File

@ -27,6 +27,9 @@ source "${KUBE_ROOT}/hack/lib/init.sh"
export GO111MODULE=on export GO111MODULE=on
kube::golang::verify_go_version
kube::golang::setup_env
staging_repos=() staging_repos=()
kube::util::read-array staging_repos < <(kube::util::list_staging_repos) kube::util::read-array staging_repos < <(kube::util::list_staging_repos)
staging_repos_pattern=$(IFS="|"; echo "${staging_repos[*]}") staging_repos_pattern=$(IFS="|"; echo "${staging_repos[*]}")
@ -34,7 +37,7 @@ staging_repos_pattern=$(IFS="|"; echo "${staging_repos[*]}")
cd "${KUBE_ROOT}" cd "${KUBE_ROOT}"
# Check for any module that is not main or staging and depends on main or staging # Check for any module that is not main or staging and depends on main or staging
bad_deps=$(go mod graph | grep -vE "^k8s.io\/(kubernetes|${staging_repos_pattern})" | grep -E "\sk8s.io\/(kubernetes|${staging_repos_pattern})" || true) bad_deps=$(go mod graph | grep -vE "^k8s.io/(kubernetes|${staging_repos_pattern})" | grep -E "\sk8s.io/(kubernetes|${staging_repos_pattern})" || true)
if [[ -n "${bad_deps}" ]]; then if [[ -n "${bad_deps}" ]]; then
echo "Found disallowed dependencies that transitively depend on k8s.io/kubernetes or staging modules:" echo "Found disallowed dependencies that transitively depend on k8s.io/kubernetes or staging modules:"
echo "${bad_deps}" echo "${bad_deps}"