Skip to content

Commit bce499c

Browse files
authored
Merge pull request kubernetes#127131 from liggitt/guard-recursive-deps
Add guard for dependencies recursively depending on kubernetes or staging modules
2 parents fe25e97 + 83f2b39 commit bce499c

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

hack/lint-dependencies.sh

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,19 @@ rc=0
4747
# The array and map in `unwanted-dependencies.json` are in alphabetical order.
4848
go run k8s.io/kubernetes/cmd/dependencyverifier "${KUBE_ROOT}/hack/unwanted-dependencies.json"
4949

50+
k8s_module_regex="k8s[.]io/(kubernetes"
51+
for repo in $(kube::util::list_staging_repos); do
52+
k8s_module_regex="${k8s_module_regex}|${repo}"
53+
done
54+
k8s_module_regex="${k8s_module_regex})"
55+
56+
recursive_dependencies=$(go mod graph | grep -E " ${k8s_module_regex}" | grep -E -v "^${k8s_module_regex}" || true)
57+
if [[ -n "${recursive_dependencies}" ]]; then
58+
echo "These external modules depend on k8s.io/kubernetes or staging modules, which is not allowed:"
59+
echo ""
60+
echo "${recursive_dependencies}"
61+
fi
62+
5063
outdated=$(go list -m -json all | jq -r "
5164
select(.Replace.Version != null) |
5265
select(.Version != .Replace.Version) |
@@ -90,7 +103,7 @@ if [[ -n "${unused}" ]]; then
90103
echo "${unused}" | xargs -L 1 echo 'go mod edit -dropreplace'
91104
fi
92105

93-
if [[ -n "${unused}${outdated}${noncanonical}" ]]; then
106+
if [[ -n "${unused}${outdated}${noncanonical}${recursive_dependencies}" ]]; then
94107
rc=1
95108
else
96109
echo "All pinned versions of checked dependencies match their preferred version."

0 commit comments

Comments
 (0)