|
2 | 2 | # |
3 | 3 | # Checks the cross-module dependency graph against an explicit allowlist, and catches stale indirect requires. |
4 | 4 | # |
5 | | -# check-acyclic-deps.sh enforces layering: a module may not import from a strictly higher tier. That is necessary but |
6 | | -# not sufficient. aws and k8s are both tier 3, so k8s importing aws for a single EC2 call never violated the tier |
7 | | -# rule, and it went unnoticed until a user reported that depending on k8s pulled in 23 AWS service SDKs (#1875). |
| 5 | +# check-acyclic-deps.sh enforces layering only. aws and k8s are both tier 3, so k8s importing aws for one EC2 call |
| 6 | +# never violated it (#1875). This requires every edge to be listed on purpose instead. |
8 | 7 | # |
9 | | -# This script enforces the complementary rule: every cross-module edge is listed below on purpose. Adding one is a |
10 | | -# deliberate act with a reviewer attached, not something that happens because an import was convenient. |
| 8 | +# It also catches staleness: nothing tidies submodule go.mod files, so when k8s dropped aws, helm kept it as an |
| 9 | +# indirect and shipped 72 aws-sdk-go-v2 go.sum entries for code no module imported. |
11 | 10 | # |
12 | | -# It also catches the second half of that problem. When k8s stopped requiring aws, helm kept carrying aws as an |
13 | | -# indirect require, because nothing tidies submodule go.mod files: the go-mod-tidy-check workflow runs at the repo |
14 | | -# root and diffs only the root go.mod and go.sum. helm shipped 72 aws-sdk-go-v2 entries in its go.sum for code no |
15 | | -# module imported. An indirect require that is not reachable through the declared direct graph is stale. |
16 | | -# |
17 | | -# No -e: accumulate every violation and report them all, rather than aborting on the first. |
| 11 | +# No -e: accumulate every violation rather than aborting on the first. |
18 | 12 | set -uo pipefail |
19 | 13 |
|
20 | | -# Permitted direct cross-module requires, as "importer:importee". |
21 | | -# |
22 | | -# Test-only edges still appear here, because a test dependency is a real entry in go.mod. Keeping the graph small is |
23 | | -# the point of the v2 split, so treat an addition as a design decision: prefer injecting behaviour over taking the |
24 | | -# dependency. modules/k8s/kubectl_options.go NodePublicIPLookup is the worked example. |
| 14 | +# Permitted direct cross-module requires, as "importer:importee". Test-only edges count, since a test dependency is |
| 15 | +# a real go.mod entry. Treat an addition as a design decision: prefer injecting behaviour over taking the dependency |
| 16 | +# (see NodePublicIPLookup in modules/k8s/kubectl_options.go). |
25 | 17 | ALLOWED_EDGES=( |
26 | 18 | "aws:core" |
27 | 19 | "aws:ssh" # Ec2Keypair embeds ssh.KeyPair; SCP helpers |
@@ -119,9 +111,8 @@ for allowed in "${ALLOWED_EDGES[@]}"; do |
119 | 111 | fi |
120 | 112 | done |
121 | 113 |
|
122 | | -# 3. Every indirect terratest require must be reachable through the declared direct graph. An unreachable one is a |
123 | | -# stale entry left behind when some other module dropped the dependency, and it drags that module's whole |
124 | | -# transitive tree into every consumer's go.sum. |
| 114 | +# 3. Every indirect terratest require must be reachable through the declared direct graph. An unreachable one is |
| 115 | +# stale, and drags a whole transitive tree into every consumer's go.sum. |
125 | 116 | reachable_from() { |
126 | 117 | local start="$1" |
127 | 118 | local -A visited=() |
|
0 commit comments