I checked out the kubernetes project at tag v1.20.4.
Then run "go list -deps -json ./... > json.txt" in the project root.
In the produced json.txt file, I noticed that the module path for
two packages look not right. The path of a package should be
prefixed with its module path. But the two aren't. Bug?
If I understand correctly, the kubernetes repo is using something other than the go command to generate their go.mod and vendor/modules.txt files.
The go command maintains a number of invariants on the go.mod and vendor/modules.txt files and expects those invariants to hold. I would not be at all surprised if the k8s hack/update-vendor.sh is generating a malformed file (CC @liggitt).
Note that go1.16.3 mod vendor at that commit produces substantial changes in the vendor/modules.txt file:
~/src/k8s.io/kubernetes$ git status
HEAD detached at v1.20.4
nothing to commit, working tree clean
~/src/k8s.io/kubernetes$ go1.16.3 mod vendor
warning: ignoring symlink /usr/local/google/home/bcmills/src/k8s.io/kubernetes/cluster/gce/cos
warning: ignoring symlink /usr/local/google/home/bcmills/src/k8s.io/kubernetes/cluster/gce/custom
warning: ignoring symlink /usr/local/google/home/bcmills/src/k8s.io/kubernetes/cluster/gce/ubuntu
~/src/k8s.io/kubernetes$ git diff --stat vendor/modules.txt
vendor/modules.txt | 780 ++++++++++++++++++++++++++++++++++++-------------------------------------
1 file changed, 390 insertions(+), 390 deletions(-)
Perhaps we should validate that the vendor/modules.txt file obeys certain basic properties, like listing each package within a module that could lexically contain it. But if we detect a violation of those properties, the best we can do in -mod=vendor mode is to fail with a useful diagnostic.
changed the title
cmd/go: the modules of some packages look not right in the output of ""go list -deps -json"Apr 21, 2021
Kubernetes uses go mod tidy and go mod vendor to generate the vendor/modules.txt, then sorts modules.txt to be deterministically ordered by module name.
At the time we adopted go modules (~go1.11-go1.12 timeframe), go mod vendor produced inconsistent output for vendor/modules.txt due to import order (different across platforms, and impacted by PRs that added files that changed import order but didn't affect overall content of the vendor directory). Those broke presubmit checks that required zero diff on the vendor folder.
Is the generated vendor/modules.txt file now guaranteed to be identical across platforms and independent of import order?
@liggitt, go mod vendor has been sorting packages within each module in vendor/modules.txt since CL 174527, which I believe was included in Go 1.13. As far as I can tell, the order of the modules themselves has always been sorted.