Skip to content

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

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

thaJeztah
Copy link
Member

@thaJeztah thaJeztah commented Aug 19, 2023

While working on some changes, I noticed that a file I was editing was a generated file;

// generated code - DO NOT EDIT

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 manually go 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:

  • Update the template to actually generate the expected code.
  • Update the template to have a correctly formatted "this is a generated file" comment.
  • Fix the 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).
  • And finally: update the template with some of the changes I was about to make manually, and to make the code slightly more iodiomatic.

. 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.

  • 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

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 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.

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:

Screenshot 2023-08-19 at 12 01 36

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 plugin

Make 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)

down-the-rabbit-hole

@thaJeztah thaJeztah requested a review from tianon as a code owner August 19, 2023 11:20
@thaJeztah thaJeztah requested review from cpuguy83 and crazy-max and removed request for tianon August 19, 2023 12:57
@thaJeztah thaJeztah changed the title fix "make generated-files" not generating and validating volume/drivers fix "make generated-files" not generating and validating volume/drivers/volumeDriverProxy, daemon/logger/logPluginProxy Aug 19, 2023
Copy link
Member

@cpuguy83 cpuguy83 left a 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
Copy link
Member

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" }}
Copy link
Member

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>
@thaJeztah
Copy link
Member Author

@cpuguy83 I dropped the last commit (for the logging-driver); let me know if the remaining bits are still problematic to keep

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

Successfully merging this pull request may close these issues.

Add make target (and verify step) to regenerate protobufs
2 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy