From 24aa86991ccbaf3ec69e05888448ab50cdfc7d2d Mon Sep 17 00:00:00 2001 From: Cory Snider Date: Thu, 24 Jul 2025 16:42:40 -0400 Subject: [PATCH] api/types: move PluginCreateOptions to client While it is imported by both the client and the daemon, values of the PluginCreateOptions struct are not marshaled or unmarshaled. The only field is mapped to and from an HTTP query parameter. Furthermore, this options type is the odd one out: the daemon uses types in api/types/backend to pass options around for the other plugin lifecycle operations. Move the PluginCreateOptions type into client, and define a new PluginCreateConfig struct in api/types/backend for the daemon to use alongside PluginRmConfig, PluginEnableConfig and PluginDisableConfig. Signed-off-by: Cory Snider Signed-off-by: Sebastiaan van Stijn --- api/types/backend/backend.go | 5 +++++ api/types/client.go | 6 ------ client/client_interfaces.go | 2 +- client/plugin_create.go | 9 ++++++--- daemon/pkg/plugin/backend_linux.go | 2 +- daemon/pkg/plugin/backend_unsupported.go | 2 +- daemon/server/router/plugin/backend.go | 2 +- daemon/server/router/plugin/plugin_routes.go | 2 +- testutil/fixtures/plugin/plugin.go | 8 +++++--- vendor/github.com/moby/moby/api/types/backend/backend.go | 5 +++++ vendor/github.com/moby/moby/api/types/client.go | 6 ------ vendor/github.com/moby/moby/client/client_interfaces.go | 2 +- vendor/github.com/moby/moby/client/plugin_create.go | 9 ++++++--- 13 files changed, 33 insertions(+), 27 deletions(-) delete mode 100644 api/types/client.go delete mode 100644 vendor/github.com/moby/moby/api/types/client.go diff --git a/api/types/backend/backend.go b/api/types/backend/backend.go index eb1853fba4..4fae874acf 100644 --- a/api/types/backend/backend.go +++ b/api/types/backend/backend.go @@ -150,6 +150,11 @@ type CommitConfig struct { ParentImageID string } +// PluginCreateConfig hold all options to plugin create. +type PluginCreateConfig struct { + RepoName string +} + // PluginRmConfig holds arguments for plugin remove. type PluginRmConfig struct { ForceRemove bool diff --git a/api/types/client.go b/api/types/client.go deleted file mode 100644 index 1c3f4678fb..0000000000 --- a/api/types/client.go +++ /dev/null @@ -1,6 +0,0 @@ -package types - -// PluginCreateOptions hold all options to plugin create. -type PluginCreateOptions struct { - RepoName string -} diff --git a/client/client_interfaces.go b/client/client_interfaces.go index e7f3dce25f..f12105cf67 100644 --- a/client/client_interfaces.go +++ b/client/client_interfaces.go @@ -156,7 +156,7 @@ type PluginAPIClient interface { PluginPush(ctx context.Context, name string, registryAuth string) (io.ReadCloser, error) PluginSet(ctx context.Context, name string, args []string) error PluginInspectWithRaw(ctx context.Context, name string) (*types.Plugin, []byte, error) - PluginCreate(ctx context.Context, createContext io.Reader, options types.PluginCreateOptions) error + PluginCreate(ctx context.Context, createContext io.Reader, options PluginCreateOptions) error } // ServiceAPIClient defines API client methods for the services diff --git a/client/plugin_create.go b/client/plugin_create.go index e7b03fcc59..b1216c1224 100644 --- a/client/plugin_create.go +++ b/client/plugin_create.go @@ -5,12 +5,15 @@ import ( "io" "net/http" "net/url" - - "github.com/moby/moby/api/types" ) +// PluginCreateOptions hold all options to plugin create. +type PluginCreateOptions struct { + RepoName string +} + // PluginCreate creates a plugin -func (cli *Client) PluginCreate(ctx context.Context, createContext io.Reader, createOptions types.PluginCreateOptions) error { +func (cli *Client) PluginCreate(ctx context.Context, createContext io.Reader, createOptions PluginCreateOptions) error { headers := http.Header(make(map[string][]string)) headers.Set("Content-Type", "application/x-tar") diff --git a/daemon/pkg/plugin/backend_linux.go b/daemon/pkg/plugin/backend_linux.go index 774f676bdb..6d0d6dbb93 100644 --- a/daemon/pkg/plugin/backend_linux.go +++ b/daemon/pkg/plugin/backend_linux.go @@ -626,7 +626,7 @@ func (pm *Manager) Set(name string, args []string) error { // CreateFromContext creates a plugin from the given pluginDir which contains // both the rootfs and the config.json and a repoName with optional tag. -func (pm *Manager) CreateFromContext(ctx context.Context, tarCtx io.ReadCloser, options *types.PluginCreateOptions) (retErr error) { +func (pm *Manager) CreateFromContext(ctx context.Context, tarCtx io.ReadCloser, options *backend.PluginCreateConfig) (retErr error) { pm.muGC.RLock() defer pm.muGC.RUnlock() diff --git a/daemon/pkg/plugin/backend_unsupported.go b/daemon/pkg/plugin/backend_unsupported.go index 13786880ff..e7264da71a 100644 --- a/daemon/pkg/plugin/backend_unsupported.go +++ b/daemon/pkg/plugin/backend_unsupported.go @@ -69,6 +69,6 @@ func (pm *Manager) Set(name string, args []string) error { // CreateFromContext creates a plugin from the given pluginDir which contains // both the rootfs and the config.json and a repoName with optional tag. -func (pm *Manager) CreateFromContext(ctx context.Context, tarCtx io.ReadCloser, options *types.PluginCreateOptions) error { +func (pm *Manager) CreateFromContext(ctx context.Context, tarCtx io.ReadCloser, options *backend.PluginCreateConfig) error { return errNotSupported } diff --git a/daemon/server/router/plugin/backend.go b/daemon/server/router/plugin/backend.go index e3be7f6571..2b6631c119 100644 --- a/daemon/server/router/plugin/backend.go +++ b/daemon/server/router/plugin/backend.go @@ -25,5 +25,5 @@ type Backend interface { Pull(ctx context.Context, ref reference.Named, name string, metaHeaders http.Header, authConfig *registry.AuthConfig, privileges types.PluginPrivileges, outStream io.Writer, opts ...plugin.CreateOpt) error Push(ctx context.Context, name string, metaHeaders http.Header, authConfig *registry.AuthConfig, outStream io.Writer) error Upgrade(ctx context.Context, ref reference.Named, name string, metaHeaders http.Header, authConfig *registry.AuthConfig, privileges types.PluginPrivileges, outStream io.Writer) error - CreateFromContext(ctx context.Context, tarCtx io.ReadCloser, options *types.PluginCreateOptions) error + CreateFromContext(ctx context.Context, tarCtx io.ReadCloser, options *backend.PluginCreateConfig) error } diff --git a/daemon/server/router/plugin/plugin_routes.go b/daemon/server/router/plugin/plugin_routes.go index 499f2974f5..06f2457e07 100644 --- a/daemon/server/router/plugin/plugin_routes.go +++ b/daemon/server/router/plugin/plugin_routes.go @@ -186,7 +186,7 @@ func (pr *pluginRouter) createPlugin(ctx context.Context, w http.ResponseWriter, return err } - options := &types.PluginCreateOptions{ + options := &backend.PluginCreateConfig{ RepoName: r.FormValue("name"), } diff --git a/testutil/fixtures/plugin/plugin.go b/testutil/fixtures/plugin/plugin.go index 81f3f38e38..8c2780d815 100644 --- a/testutil/fixtures/plugin/plugin.go +++ b/testutil/fixtures/plugin/plugin.go @@ -13,8 +13,10 @@ import ( registrypkg "github.com/docker/docker/daemon/pkg/registry" "github.com/moby/go-archive" "github.com/moby/moby/api/types" + "github.com/moby/moby/api/types/backend" "github.com/moby/moby/api/types/events" "github.com/moby/moby/api/types/registry" + "github.com/moby/moby/client" "github.com/pkg/errors" ) @@ -49,7 +51,7 @@ func WithBinary(bin string) CreateOpt { // CreateClient is the interface used for `BuildPlugin` to interact with the // daemon. type CreateClient interface { - PluginCreate(context.Context, io.Reader, types.PluginCreateOptions) error + PluginCreate(context.Context, io.Reader, client.PluginCreateOptions) error } // Create creates a new plugin with the specified name @@ -69,7 +71,7 @@ func Create(ctx context.Context, c CreateClient, name string, opts ...CreateOpt) ctx, cancel := context.WithTimeout(ctx, 30*time.Second) defer cancel() - return c.PluginCreate(ctx, tar, types.PluginCreateOptions{RepoName: name}) + return c.PluginCreate(ctx, tar, client.PluginCreateOptions{RepoName: name}) } // CreateInRegistry makes a plugin (locally) and pushes it to a registry. @@ -127,7 +129,7 @@ func CreateInRegistry(ctx context.Context, repo string, auth *registry.AuthConfi ctx, cancel := context.WithTimeout(ctx, 30*time.Second) defer cancel() - if err := manager.CreateFromContext(ctx, tar, &types.PluginCreateOptions{RepoName: repo}); err != nil { + if err := manager.CreateFromContext(ctx, tar, &backend.PluginCreateConfig{RepoName: repo}); err != nil { return err } diff --git a/vendor/github.com/moby/moby/api/types/backend/backend.go b/vendor/github.com/moby/moby/api/types/backend/backend.go index eb1853fba4..4fae874acf 100644 --- a/vendor/github.com/moby/moby/api/types/backend/backend.go +++ b/vendor/github.com/moby/moby/api/types/backend/backend.go @@ -150,6 +150,11 @@ type CommitConfig struct { ParentImageID string } +// PluginCreateConfig hold all options to plugin create. +type PluginCreateConfig struct { + RepoName string +} + // PluginRmConfig holds arguments for plugin remove. type PluginRmConfig struct { ForceRemove bool diff --git a/vendor/github.com/moby/moby/api/types/client.go b/vendor/github.com/moby/moby/api/types/client.go deleted file mode 100644 index 1c3f4678fb..0000000000 --- a/vendor/github.com/moby/moby/api/types/client.go +++ /dev/null @@ -1,6 +0,0 @@ -package types - -// PluginCreateOptions hold all options to plugin create. -type PluginCreateOptions struct { - RepoName string -} diff --git a/vendor/github.com/moby/moby/client/client_interfaces.go b/vendor/github.com/moby/moby/client/client_interfaces.go index e7f3dce25f..f12105cf67 100644 --- a/vendor/github.com/moby/moby/client/client_interfaces.go +++ b/vendor/github.com/moby/moby/client/client_interfaces.go @@ -156,7 +156,7 @@ type PluginAPIClient interface { PluginPush(ctx context.Context, name string, registryAuth string) (io.ReadCloser, error) PluginSet(ctx context.Context, name string, args []string) error PluginInspectWithRaw(ctx context.Context, name string) (*types.Plugin, []byte, error) - PluginCreate(ctx context.Context, createContext io.Reader, options types.PluginCreateOptions) error + PluginCreate(ctx context.Context, createContext io.Reader, options PluginCreateOptions) error } // ServiceAPIClient defines API client methods for the services diff --git a/vendor/github.com/moby/moby/client/plugin_create.go b/vendor/github.com/moby/moby/client/plugin_create.go index e7b03fcc59..b1216c1224 100644 --- a/vendor/github.com/moby/moby/client/plugin_create.go +++ b/vendor/github.com/moby/moby/client/plugin_create.go @@ -5,12 +5,15 @@ import ( "io" "net/http" "net/url" - - "github.com/moby/moby/api/types" ) +// PluginCreateOptions hold all options to plugin create. +type PluginCreateOptions struct { + RepoName string +} + // PluginCreate creates a plugin -func (cli *Client) PluginCreate(ctx context.Context, createContext io.Reader, createOptions types.PluginCreateOptions) error { +func (cli *Client) PluginCreate(ctx context.Context, createContext io.Reader, createOptions PluginCreateOptions) error { headers := http.Header(make(map[string][]string)) headers.Set("Content-Type", "application/x-tar")