Skip to content

[DNM] some experimenting with go.work instead of replace rules#50947

Draft
thaJeztah wants to merge 4 commits intomoby:masterfrom
thaJeztah:use_go_work
Draft

[DNM] some experimenting with go.work instead of replace rules#50947
thaJeztah wants to merge 4 commits intomoby:masterfrom
thaJeztah:use_go_work

Conversation

@thaJeztah
Copy link
Copy Markdown
Member

This was a branch where I started to look at options when using go.work instead of replace rules;

  • 👍 when using go.work, the "local" modules are not vendored while in go workspace mode (see first commit); this means that it's not needed to re-vendor when making changes that impact multiple modules.
  • 👎 this also means that while the go.work exists, the vendor directory does not match what's in go.mod
  • 👎 👉 for the other (api/, client/) modules (that don't use vendor) it also means that the version in go.mod may not be the required minimum version.
  • ☝️ this means that the api, client, and v2 modules may not be buildable for users using the module from "master", and they manually have to force updating the dependent modules to "latest".
  • ☝️ this is NOT new; the same situation exists with replace, where the module versions are not updated, but the code is
  • ☝️ this also means that we must update the module versions in go.mod, and do a vendor before tagging. The "update the module versions in go.mod" is not new, but the vendor (bringing back all files that were removed IS, and causes much code-churn).

There's some other issues;

  • ⚠️ In go workspace mode, all three modules (api, client, and "v2") are put in the same "workspace"; this will result in dependencies AND go version of the api and client modules to be "bumped" if they are bumped in the v2 module.
  • ☝️ this is generally not desirable; we want to stick to go modules MVS (minimum version selection) and don't update minimum dependency versions and minimum go versions of the api and client modules, unless they MUST be updated.

To prevent the vendor-churn, while still taking advantage of go.work, I also tried to disable go.work during vendoring; this would allow updating the dependency versions when needed, while (for development) the go.work allows building the binaries using the local code.

This does NOT fix situations where the api and client modules may be non-functional between releases (i.e., if the client requires a newer version of the api module than is specified in go.mod).

❓ Can we somehow make such updates happen as part of PRs that merge changes that require the version in client to be updated?
❓ We can probably generate a pseudo-version for those, but not sure if we can before the PR is merged.

- What I did

- How I did it

- How to verify it

- Human readable description for the release notes

- A picture of a cute animal (not mandatory but encouraged)

@thaJeztah
Copy link
Copy Markdown
Member Author

Ah, interesting 🤔

0.499 ---> Making bundle: binary (in /tmp/bundles/binary)
0.522 Building static /tmp/bundles/binary-daemon/dockerd (linux/arm64)...
0.526 go: module . listed in go.work file requires go >= 1.24.0, but go.work lists go 1.23.0; to update it:
0.526 	go work use

Using a `go.work` file lets us use the local (unreleased) `api` and
`client` modules during development without having to add `replace`
directives in `go.mod` (which have to be removed for releases).

Unlike `replace` rules, `go.work` is not transitive, so not visible
to users of the module (which *will* mean that unreleased versions
of the client or "v2" module may be non-functional if they depend
on changes in the api or client that are not yet release, and not
yet reflected in their `go.mod`).

Use `GOWORK=off` to verify what "external" users see.

Signed-off-by: Sebastiaan van Stijn <[email protected]>
Disable workspace when tidying the api and client modules to prevent
common dependencies between other modules in the workspace from affecting
the other modules. This allows us to stick to MVS for the api and client
modules, while still updating the main ("v2") module's dependencies.

Signed-off-by: Sebastiaan van Stijn <[email protected]>
This makes the vendor directory reflect what's specified in go.mod;
downside is that this may make the code non-buildable without go.work
enabled (as the vendor directory doesn't reflect what go.work uses),
but it does reduce code-churn w.r.t. vendored files being removed
while go.work is present.

Possibly we can make vendor handle generating a pseudo-version and
update the vendor "as usual" without using a replace rule, but
that needs to be looked into if there's an option for that.

Signed-off-by: Sebastiaan van Stijn <[email protected]>
Basically, let them work as if GOWORK=off

Signed-off-by: Sebastiaan van Stijn <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant