This was originally added in the early days of go.mod in order to ensure that the root k8s.io/kubernetes
go.mod file reflected all the versions of dependencies we were using, and to ensure that go commands didn't spuriously
increment these versions.
With module pruning in go1.17+ and go defaulting to mod=readonly mode in go1.16+, this is no longer necessary.
This addresses a problem that occurred when trying the following replacement:
hack/pin-dependency.sh k8s.io/klog/v2=github.com/pohly/klog/v2 flush-log-sink
That itself worked, but update-vendor.sh then failed:
=== tidying go.mod/go.sum in staging/src/k8s.io/code-generator/examples
go: k8s.io/apimachinery@v0.0.0 requires
k8s.io/klog/v2@v2.4.1-0.20210909144920-0b91caa8c854: invalid version: unknown revision 0b91caa8c854
go: k8s.io/apimachinery@v0.0.0 requires
k8s.io/klog/v2@v2.4.1-0.20210909144920-0b91caa8c854: invalid version: unknown revision 0b91caa8c854
Sometimes it is useful to fork a dependency in a different repo and
then use that forked code in Kubernetes. Normally one would do `go mod
edit -replace ...=/local/path` but that has drawbacks:
- repos under staging are not updated
- sharing the modified Kubernetes with others is harder, for example
in a WIP or RFC PR
The revised pin-dependencies.sh supports this with an optional
=<replacement> part in the dependency parameter.
Determining the revision upfront with `go mod download` also makes the
script simpler.