-
Notifications
You must be signed in to change notification settings - Fork 18.8k
fix "make generated-files" not generating and validating volume/drivers/volumeDriverProxy, daemon/logger/logPluginProxy #46274
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: master
Are you sure you want to change the base?
Conversation
b0c8cd6
to
84d0823
Compare
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.
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 |
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 we should update the interface to take a context?
{{ else }} | ||
type {{ $.InterfaceType }}Proxy{{ .Name }}Request struct{} | ||
{{ end }} | ||
{{ if eq .Name "ReadLogs" }} |
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.
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
@cpuguy83 I dropped the last commit (for the logging-driver); let me know if the remaining bits are still problematic to keep |
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 generate
the 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-files
target 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-gen
generator 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-gen
and 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)