-
Notifications
You must be signed in to change notification settings - Fork 10.1k
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
base: main
Are you sure you want to change the base?
Conversation
Skipping CI for Draft Pull Request. |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted filessee 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.
🚀 New features to boost your workflow:
|
/test all |
d555146
to
b7e86a4
Compare
b7e86a4
to
eb81e5b
Compare
/cc @ahrtr @serathius |
I will review this PR after we officially release v3.6.0, thx |
eb81e5b
to
9ed8ecc
Compare
9ed8ecc
to
d3c2c0b
Compare
5b7fc76
to
d30c4c0
Compare
/test pull-etcd-release-tests |
/test all |
@ahrtr, with 3.6.0 out the door, can we revisit this pull request now? |
d30c4c0
to
2cab586
Compare
/test pull-etcd-integration-4-cpu-amd64 |
[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 |
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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 onpkg
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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,
Line 43 in b3b9e98
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cc @thockin
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cc @dims
There was a problem hiding this comment.
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),
- Change the definition to
go.etcd.io/etcd/api/v3 v3.6.0 => ../FORBIDDEN_DEPENDENCY
- So you can't import module
api/[email protected]
; but you can import other version, i.e.api/[email protected]
- But the dependencies will be inconsistent (
api/[email protected]
vsapi/[email protected]
, assuming all other permitted modules depend onapi/[email protected]
), so the linter workflow check will fail.
Please try this out.
There was a problem hiding this comment.
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? :)
I assume that you will remove all permitted replace directive in a followup PR, see one example below, correct? Lines 49 to 54 in ae01ad8
|
@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. |
2cab586
to
ca11ee7
Compare
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 |
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]>
ca11ee7
to
f2edd8a
Compare
Rebased/force pushed due to #20039. |
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]>
@ivanvc: The following tests failed, say
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. |
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.