Skip to content

Minimal changes to enable a Go workspace #19423

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

ivanvc
Copy link
Member

@ivanvc ivanvc commented Feb 15, 2025

This pull request is a follow-up on #19314.

It introduces minimal changes to enable a workspace in the project. We can iterate on it later to remove the script nuances of looping over the modules to execute commands, as they can now be executed from the top level of the repository.

Part of #18409.

Please read https://github.com/etcd-io/etcd/blob/main/CONTRIBUTING.md#contribution-flow.

@k8s-ci-robot
Copy link

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

Copy link

codecov bot commented Feb 15, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 68.70%. Comparing base (b3b9e98) to head (f2edd8a).
Report is 88 commits behind head on main.

Current head f2edd8a differs from pull request most recent head aba141c

Please upload reports for the commit aba141c to get more accurate results.

Additional details and impacted files

see 30 files with indirect coverage changes

@@            Coverage Diff             @@
##             main   #19423      +/-   ##
==========================================
+ Coverage   66.85%   68.70%   +1.84%     
==========================================
  Files         424      424              
  Lines       35756    35756              
==========================================
+ Hits        23905    24566     +661     
+ Misses      10446     9767     -679     
- Partials     1405     1423      +18     

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b3b9e98...aba141c. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ivanvc
Copy link
Member Author

ivanvc commented Feb 15, 2025

/test all

@ivanvc ivanvc force-pushed the introduce-a-min-workspace branch 2 times, most recently from d555146 to b7e86a4 Compare February 18, 2025 06:03
@ivanvc ivanvc changed the title [do not review] Go workspace Minimal changes to enable a Go workspace Feb 18, 2025
@ivanvc ivanvc force-pushed the introduce-a-min-workspace branch from b7e86a4 to eb81e5b Compare February 18, 2025 06:26
@ivanvc ivanvc marked this pull request as ready for review February 18, 2025 06:45
@ivanvc
Copy link
Member Author

ivanvc commented Feb 18, 2025

/cc @ahrtr @serathius

@ahrtr
Copy link
Member

ahrtr commented Feb 21, 2025

I will review this PR after we officially release v3.6.0, thx

@ivanvc ivanvc force-pushed the introduce-a-min-workspace branch from 5b7fc76 to d30c4c0 Compare May 22, 2025 05:41
@ivanvc
Copy link
Member Author

ivanvc commented May 22, 2025

/test pull-etcd-release-tests

@ivanvc
Copy link
Member Author

ivanvc commented May 22, 2025

/test all

@ivanvc ivanvc marked this pull request as ready for review May 22, 2025 16:56
@ivanvc
Copy link
Member Author

ivanvc commented May 22, 2025

@ahrtr, with 3.6.0 out the door, can we revisit this pull request now?

@ivanvc ivanvc requested a review from serathius May 22, 2025 16:56
@ivanvc ivanvc force-pushed the introduce-a-min-workspace branch from d30c4c0 to 2cab586 Compare May 22, 2025 17:27
@ivanvc
Copy link
Member Author

ivanvc commented May 22, 2025

/test pull-etcd-integration-4-cpu-amd64

@k8s-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: ivanvc, serathius

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ahrtr
Copy link
Member

ahrtr commented May 22, 2025

Will take a look at this PR next week, thx @ivanvc

go.etcd.io/etcd/v3 => ./FORBIDDEN_DEPENDENCY
go.etcd.io/etcd => ../FORBIDDEN_DEPENDENCY
go.etcd.io/etcd/api/v3 v3.999.999 => ../FORBIDDEN_DEPENDENCY
go.etcd.io/etcd/pkg/v3 v3.999.999 => ../FORBIDDEN_DEPENDENCY
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why it's v3.999.999? In this example, we should prevent module api from depending on pkg of all versions, not just specific to a fake v3.999.999.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refer to our conversation from #19314 (comment)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should prevent module api from depending on pkg of all versions, not just specific to a fake v3.999.999.

can you double confirm this? When you set a version, it might just mean that only that version is forbidden.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because Go requires specific versions, it would be for anything in the "3" major version. To the best of my knowledge, there is no way to do this across multiple major versions. If you specify a different version (other than what's defined in the rest of the project) for a module like go.etcd.io/etcd/api/v3, Go will complain with the error:

conflicting replacements found for go.etcd.io/etcd/api/[email protected] in workspace modules
defined by [...]/etcd/etcd/go.mod and [...]/etcd/etcd/api/go.mod

For more context for the 3.999.999 fictitious version, refer to b5cf2ec commit message

Point all forbidden dependencies to a common virtual place (top-level
FORBIDDEN_DEPENDENCY). For the workspace to function we need all
dependencies to be consistent across the repository. That means that the
current approach with FORBIDDEN_DEPENDENCY doesn't work, because they
are pointing to different directories. Set the fictional v3.999.999
version for these dependencies, so they are consitent, and they don't
clash with the actual depdendencies references in other modules.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably I did not say it clearly.

There are two things.

Top level FORBIDDEN_DEPENDENCY is good

All pointing to the same top level FORBIDDEN_DEPENDENCY is good. I have no comment on this.

version v3.999.999 might not correct

For the version v3.999.999, I am afraid it isn't correct. As I mentioned above, it only prevents us from importing that specific version. Let's work with an example, the pkg can't depend on api, because we have line below,

go.etcd.io/etcd/api/v3 => ./FORBIDDEN_DEPENDENCY

When you execute command go get go.etcd.io/etcd/api/[email protected] under the pkg module, you will get error below,

$ go get go.etcd.io/etcd/api/[email protected]
go: go.etcd.io/etcd/api/[email protected]: replacement directory ./FORBIDDEN_DEPENDENCY does not exist

However if you add a version like below,

go.etcd.io/etcd/api/v3 v3.999.999 => ./FORBIDDEN_DEPENDENCY

then you can add api into pkg's go.mod because it only prevents you from importing v3.999.999. see below,

$ go get go.etcd.io/etcd/api/[email protected]
go: added go.etcd.io/etcd/api/v3 v3.6.0

$ git diff
diff --git a/pkg/go.mod b/pkg/go.mod
index ed27778fb..3f6d63aef 100644
--- a/pkg/go.mod
+++ b/pkg/go.mod
@@ -21,6 +21,7 @@ require (
        github.com/google/go-cmp v0.7.0 // indirect
        github.com/inconshreveable/mousetrap v1.1.0 // indirect
        github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
+       go.etcd.io/etcd/api/v3 v3.6.0 // indirect
        go.opentelemetry.io/otel v1.36.0 // indirect
        go.opentelemetry.io/otel/sdk v1.36.0 // indirect
        go.uber.org/multierr v1.11.0 // indirect
@@ -40,7 +41,7 @@ replace go.etcd.io/etcd/client/pkg/v3 => ../client/pkg
 // Shouldn't import unnecessary dependencies
 replace (
        go.etcd.io/etcd => ./FORBIDDEN_DEPENDENCY
-       go.etcd.io/etcd/api/v3 => ./FORBIDDEN_DEPENDENCY
+       go.etcd.io/etcd/api/v3 v3.999.999 => ./FORBIDDEN_DEPENDENCY
        go.etcd.io/etcd/tests/v3 => ./FORBIDDEN_DEPENDENCY
        go.etcd.io/etcd/v3 => ./FORBIDDEN_DEPENDENCY
 )
diff --git a/pkg/go.sum b/pkg/go.sum
index a74117318..3a7e61cf4 100644
--- a/pkg/go.sum
+++ b/pkg/go.sum
@@ -35,6 +35,8 @@ github.com/spf13/pflag v1.0.6 h1:jFzHGLGAlb3ruxLB8MhbI6A8+AQX/2eW4qeyNZXNp2o=
 github.com/spf13/pflag v1.0.6/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
 github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
 github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
+go.etcd.io/etcd/api/v3 v3.6.0 h1:vdbkcUBGLf1vfopoGE/uS3Nv0KPyIpUV/HM6w9yx2kM=
+go.etcd.io/etcd/api/v3 v3.6.0/go.mod h1:Wt5yZqEmxgTNJGHob7mTVBJDZNXiHPtXTcPab37iFOw=
 go.opentelemetry.io/auto/sdk v1.1.0 h1:cH53jehLUN6UFLY71z+NDOiNJqDdPRaXzTel0sJySYA=
 go.opentelemetry.io/auto/sdk v1.1.0/go.mod h1:3wSPjt5PWp2RhlCcmmOial7AvC4DQqZb7a7wCow3W8A=
 go.opentelemetry.io/otel v1.36.0 h1:UumtzIklRBY6cI/lllNZlALOF5nNIzJVb16APdvgTXg=

If you change the definition above to go.etcd.io/etcd/api/v3 v3.6.0 => ./FORBIDDEN_DEPENDENCY, then the command go get go.etcd.io/etcd/api/[email protected] will definitely fail.

Conclusion & Proposal?

Conclusions:

  • The change in this PR breaks the function of FORBIDDEN_DEPENDENCY, because it can't technically prevents us from importing any version other than v3.999.999.
  • Keeping v3.999.999 is better not keeping it, at least it has document purpose.

Proposal:
Can we raise a question on the golang-nuts to get more professional / official advice?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the clear explanation and for helping me with my misunderstanding.

I see and understand the point. Before reaching out to the Go mailing list, I propose an alternative to using the fictitious 3.999.999 version: keep these versions in sync, pointing to the latest released version (i.e., as part of our release script).

We could also reach out to Tim Hockin, as he proposed this solution after I attempted to use k/k's import-boss to solve this issue.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc @dims

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

keep these versions in sync, pointing to the latest released version (i.e., as part of our release script).

Yes, I had the same thought. It's much better although It still has similar flaw, which can also be detected by linter check (inconsistent dependencies). Let me provide an example to avoid misunderstanding (please also double confirm this),

Please try this out.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, I got tagged in but I lack context - what input are you hoping I might offer? :)

@ahrtr
Copy link
Member

ahrtr commented May 27, 2025

I assume that you will remove all permitted replace directive in a followup PR, see one example below, correct?

etcd/etcdctl/go.mod

Lines 49 to 54 in ae01ad8

replace (
go.etcd.io/etcd/api/v3 => ../api
go.etcd.io/etcd/client/pkg/v3 => ../client/pkg
go.etcd.io/etcd/client/v3 => ../client/v3
go.etcd.io/etcd/pkg/v3 => ../pkg
)

@ivanvc
Copy link
Member Author

ivanvc commented May 27, 2025

I assume that you will remove all permitted replace directive in a followup PR, see one example below, correct?

@ahrtr, after I received the suggestion to make minimal changes to enable the Go workspace, I closed my previous pull request, and this one does precisely that. It enables the workspace and allows it to coexist with our previous build system; I made only the minimal changes necessary to achieve this.

Long story short, to keep the changes minimal and reduce friction when merging the pull request, I'll address more changes later on.

@ivanvc ivanvc force-pushed the introduce-a-min-workspace branch from 2cab586 to ca11ee7 Compare May 27, 2025 19:16
@ivanvc ivanvc requested a review from ahrtr May 27, 2025 19:17
@ahrtr
Copy link
Member

ahrtr commented May 27, 2025

@ahrtr, after I received the suggestion to make minimal changes to enable the Go workspace

I am aware of it, and have no any comment on that. I am just double confirming the next step. Even in your previous PR #19314, I do not see you made the change as mentioned in #19423 (comment)

@ivanvc
Copy link
Member Author

ivanvc commented May 28, 2025

I am aware of it, and have no any comment on that. I am just double confirming the next step. Even in your previous PR #19314, I do not see you made the change as mentioned in #19423 (comment)

If I remember correctly, we can't remove the replaces from the top-level go.mod, but we can from the submodules (but my memory may not be serving me well). I'll work on that after, and will get a definitive answer on what we need to do moving forward.

ivanvc and others added 4 commits May 28, 2025 10:15
Introduce a new Go workspace that references all the current submodules.
To preserve the current behavior, point all of the current
FORBIDDEN_DEPENCENCY virtual dependencies to the same path.

Add scripts/update_go_workspace.sh that generates the Go workspace file
(go.work) based on the submodules found in the project (excluding the
tools) and creates the go.work.sum file after running go mod download.
Added this script to the fix Makefile target. Even though, the number of
modules in the etcd repository is small, by adding an automated way of
updating the go.work modules future proofs the project in case there are
new modules or removal of them.

Point all forbidden dependencies to a common virtual place (top-level
FORBIDDEN_DEPENDENCY). For the workspace to function we need all
dependencies to be consistent across the repository. That means that the
current approach with FORBIDDEN_DEPENDENCY doesn't work, because they
are pointing to different directories. Set the fictional v3.999.999
version for these dependencies, so they are consitent, and they don't
clash with the actual depdendencies references in other modules.

Co-authored-by: Tim Hockin <[email protected]>
Signed-off-by: Ivan Valdes <[email protected]>
Introduce a new `verify-go-workspace` make target executed by the
`verify` target. The pull-etcd-verify presubmit prow job will execute
it. It ensures that the Go workspace (`go.work` and `go.work.sum`) is in
sync.

Signed-off-by: Ivan Valdes <[email protected]>
Add checking for the Go toolchain directive in the go.work file too.

Signed-off-by: Ivan Valdes <[email protected]>
Remove `GOFLAGS=-mod=mod` from the execution of
license-bill-of-materials.

Signed-off-by: Ivan Valdes <[email protected]>
@ivanvc ivanvc force-pushed the introduce-a-min-workspace branch from ca11ee7 to f2edd8a Compare May 28, 2025 17:16
@ivanvc
Copy link
Member Author

ivanvc commented May 28, 2025

Rebased/force pushed due to #20039.

@k8s-ci-robot
Copy link

PR needs rebase.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

Update the verify-dep check to include versions from replaced modules,
to ensure consistency across the modules.

Signed-off-by: Ivan Valdes <[email protected]>
@k8s-ci-robot
Copy link

@ivanvc: The following tests failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
ci-etcd-robustness-release36-amd64 2cab586 link true /test ci-etcd-robustness-release36-amd64
pull-etcd-unit-test-arm64 aba141c link true /test pull-etcd-unit-test-arm64
pull-etcd-integration-1-cpu-arm64 aba141c link true /test pull-etcd-integration-1-cpu-arm64
pull-etcd-integration-2-cpu-arm64 aba141c link true /test pull-etcd-integration-2-cpu-arm64
pull-etcd-robustness-amd64 aba141c link true /test pull-etcd-robustness-amd64
pull-etcd-release-tests aba141c link true /test pull-etcd-release-tests
pull-etcd-e2e-arm64 aba141c link true /test pull-etcd-e2e-arm64
pull-etcd-verify aba141c link true /test pull-etcd-verify
pull-etcd-integration-4-cpu-arm64 aba141c link true /test pull-etcd-integration-4-cpu-arm64
pull-etcd-unit-test-386 aba141c link true /test pull-etcd-unit-test-386
pull-etcd-build aba141c link true /test pull-etcd-build
pull-etcd-govulncheck aba141c link true /test pull-etcd-govulncheck
pull-etcd-unit-test-amd64 aba141c link true /test pull-etcd-unit-test-amd64
pull-etcd-e2e-amd64 aba141c link true /test pull-etcd-e2e-amd64
pull-etcd-contrib-mixin aba141c link true /test pull-etcd-contrib-mixin
pull-etcd-e2e-386 aba141c link true /test pull-etcd-e2e-386
pull-etcd-integration-4-cpu-amd64 aba141c link true /test pull-etcd-integration-4-cpu-amd64
pull-etcd-fuzzing-v3rpc aba141c link true /test pull-etcd-fuzzing-v3rpc
pull-etcd-grpcproxy-integration-amd64 aba141c link true /test pull-etcd-grpcproxy-integration-amd64
pull-etcd-grpcproxy-e2e-amd64 aba141c link true /test pull-etcd-grpcproxy-e2e-amd64
pull-etcd-grpcproxy-integration-arm64 aba141c link true /test pull-etcd-grpcproxy-integration-arm64
pull-etcd-coverage-report aba141c link true /test pull-etcd-coverage-report
pull-etcd-grpcproxy-e2e-arm64 aba141c link true /test pull-etcd-grpcproxy-e2e-arm64
pull-etcd-integration-1-cpu-amd64 aba141c link true /test pull-etcd-integration-1-cpu-amd64
pull-etcd-integration-2-cpu-amd64 aba141c link true /test pull-etcd-integration-2-cpu-amd64
pull-etcd-robustness-arm64 aba141c link true /test pull-etcd-robustness-arm64
pull-etcd-govulncheck-main aba141c link true /test pull-etcd-govulncheck-main

Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

5 participants