fix "make generated-files" not generating and validating volume/drivers/volumeDriverProxy, daemon/logger/logPluginProxy#46274
Open
thaJeztah wants to merge 7 commits intomoby:masterfrom
Open
fix "make generated-files" not generating and validating volume/drivers/volumeDriverProxy, daemon/logger/logPluginProxy#46274thaJeztah wants to merge 7 commits intomoby:masterfrom
thaJeztah wants to merge 7 commits intomoby:masterfrom
Conversation
b0c8cd6 to
84d0823
Compare
cpuguy83
reviewed
Aug 21, 2023
Member
cpuguy83
left a comment
There was a problem hiding this comment.
I'm not sure about this.
I'd almost prefer to remove the generator at this point, or completely rewrite it and probably the plugin client interface.
| {{ imports .Imports "time" "" "github.com/docker/docker/pkg/plugins"}} | ||
|
|
||
| const ( | ||
| longTimeout = 2 * time.Minute |
Member
There was a problem hiding this comment.
Probably we should update the interface to take a context?
| {{ else }} | ||
| type {{ $.InterfaceType }}Proxy{{ .Name }}Request struct{} | ||
| {{ end }} | ||
| {{ if eq .Name "ReadLogs" }} |
Member
There was a problem hiding this comment.
I'm not sure this is worth it if it means special casing specific interface methods.
The volume driver plugin generated code was manually updated in b15f8d2, so generating the code would no longer produce the same output. This patch updates the generator code to allow regenerating the volume driver plugin. - update buildImports to allow additional imports to be passed - add a conditional block to the template for volumeDriver - add a conditional block to set the right timeout, depending on what method we're generating code for. - slightly adjust the template to make the output format match the existing code. Some of this is a bit quirky, so we should look for a more generic option, but I tried to preserve the ability to generate this code, so that it can evolve if things change. To verify the generated code: GO111MODULE=off go install ./pkg/plugins/pluginrpc-gen GO111MODULE=off go generate ./volume/drivers Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Maybe this was left out on purpose in 7daaa00, because the `pluginrpc-gen` generator was broken for this code, but now that the generator works correctly, we can enable generating this package, and validate it in CI. The Dockerfile was actually building `pluginrpc-gen` and generating the plugin (`volume/drivers`), but was not copying the result, and as a result also not validating the results. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
pluginrpc-gen is also "go install"-able (if there's a go.mod), so let's use it :) Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Update the comment to match the format defined by [Golang][1], otherwise it won't be detected by IDEs and linters. [1]: https://pkg.go.dev/cmd/go@go1.21.0#hdr-Generate_Go_files_by_processing_source Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Makes the generated code slightly nicer :) Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Don't assign output variables if an error occurred. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Make sure the generated code matches the interface, and produce a compile-time error otherwise. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
8ffe99d to
15e020e
Compare
Member
Author
|
@cpuguy83 I dropped the last commit (for the logging-driver); let me know if the remaining bits are still problematic to keep |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
While working on some changes, I noticed that a file I was editing was a generated file;
moby/volume/drivers/proxy.go
Line 1 in cf15460
However, the header didn't have the correct format for generated files so didn't warn me about this, so I thought: "let me update the template to have the right comment". To verify my changes, I ran
make generated-files, which didn't complain, but did not update the generated file. When I tried to manuallygo generatethe file, the file did change, but also generated very different code.So, looking at the file's history (perhaps I used the wrong command for generating the file?), I found various manual changes were made to this file in the past, but CI never complained about this 🤔
In short: this PR is the result of one of those "down the rabbit-hole" cases:
make generated-filestarget to also include this file (fun fact: it was generating the file, but not copying it out, and because of that, was not validating it for changes).. Looking at the history of the file, I then noticed that the file was manually updated a few times in the past.
pkg/plugins: pluginrpc-gen: fix go generate for volume driver
The volume driver plugin generated code was manually updated in
b15f8d2, so generating the code
would no longer produce the same output.
This patch updates the generator code to allow regenerating the volume
driver plugin.
method we're generating code for.
existing code.
Some of this is a bit quirky, so we should look for a more generic option,
but I tried to preserve the ability to generate this code, so that it
can evolve if things change.
To verify the generated code:
hack: generate-files.Dockerfile: validate volume/drivers
Maybe this was left out on purpose in 7daaa00,
because the
pluginrpc-gengenerator was broken for this code, but nowthat the generator works correctly, we can enable generating this package,
and validate it in CI.
The Dockerfile was actually building
pluginrpc-genand generating theplugin (
volume/drivers), but was not copying the result, and as a resultalso not validating the results.
hack: generate-files.Dockerfile: simplify pluginrpc-gen install
pluginrpc-gen is also "go install"-able (if there's a go.mod), so let's
use it :)
pkg/plugins: pluginrpc-gen: fix "generated code" header to be detected
Update the comment to match the format defined by Golang, otherwise
it won't be detected by IDEs and linters.
With this change, my IDE properly picks up that the file is generated:
pkg/plugins: pluginrpc-gen: use struct-literals in generated code
Makes the generated code slightly nicer :)
pkg/plugins: pluginrpc-gen: use early return on error
Don't assign output variables if an error occurred.
pkg/plugins: pluginrpc-gen: assert interface
Make sure the generated code matches the interface, and produce a
compile-time error otherwise.
pkg/plugins: pluginrpc-gen: fix generating logger pluginMake the generator work for generating daemon/logger/logPluginProxy.(removed this commit)
- Description for the changelog
- A picture of a cute animal (not mandatory but encouraged)