go workspaces usage in kubernetes project
Kubernetes (k/k) recently started using Go Workspaces to manage its multi-module setup more effectively.
The goal is to helps keep things consistent across the many staging repositories and the main k/k project.
At the root of the k/k repo, you’ll find go.work
and go.work.sum
.
These files are auto-generated by the hack/update-vendor.sh
script.
Specifically, the logic lives around lines 198–219 and 293–303.
At a high level, the script runs the following commands from the root of the repo:
go work init
go work edit -go 1.24.0 -godebug default=go1.24
go work edit -use .
git ls-files -z ':(glob)./staging/src/k8s.io/*/go.mod' \
| xargs -0 -n1 dirname -z \
| xargs -0 -n1 go work edit -use
go mod download
go work vendor
This creates:
go.work
file that includes the root module (.) and all the Kubernetes staging modules under staging/src/k8s.io.
go 1.24.0
godebug default=go1.24
use (
.
./staging/src/k8s.io/api
./staging/src/k8s.io/apiextensions-apiserver
./staging/src/k8s.io/apimachinery
...
./staging/src/k8s.io/sample-controller
)
-
go.work.sum
file that tracks checksums for the workspace modules — likego.sum
, but at the workspace level. -
and the
vendor/
directory which is populated viago work vendor
and collects all dependencies from the workspace modules.