diff --git a/api/types/swarm/node.go b/api/types/swarm/node.go index 3e503ef24b..a41c0e4778 100644 --- a/api/types/swarm/node.go +++ b/api/types/swarm/node.go @@ -1,7 +1,5 @@ package swarm -import "github.com/moby/moby/api/types/filters" - // Node represents a node. type Node struct { ID string @@ -140,11 +138,6 @@ type Topology struct { Segments map[string]string `json:",omitempty"` } -// NodeListOptions holds parameters to list nodes with. -type NodeListOptions struct { - Filters filters.Args -} - // NodeRemoveOptions holds parameters to remove nodes with. type NodeRemoveOptions struct { Force bool diff --git a/client/client_interfaces.go b/client/client_interfaces.go index c962122902..55a30ed056 100644 --- a/client/client_interfaces.go +++ b/client/client_interfaces.go @@ -141,7 +141,7 @@ type NetworkAPIClient interface { // NodeAPIClient defines API client methods for the nodes type NodeAPIClient interface { NodeInspectWithRaw(ctx context.Context, nodeID string) (swarm.Node, []byte, error) - NodeList(ctx context.Context, options swarm.NodeListOptions) ([]swarm.Node, error) + NodeList(ctx context.Context, options NodeListOptions) ([]swarm.Node, error) NodeRemove(ctx context.Context, nodeID string, options swarm.NodeRemoveOptions) error NodeUpdate(ctx context.Context, nodeID string, version swarm.Version, node swarm.NodeSpec) error } diff --git a/client/node_list.go b/client/node_list.go index f6d2cad23e..96e9caba1d 100644 --- a/client/node_list.go +++ b/client/node_list.go @@ -10,7 +10,7 @@ import ( ) // NodeList returns the list of nodes. -func (cli *Client) NodeList(ctx context.Context, options swarm.NodeListOptions) ([]swarm.Node, error) { +func (cli *Client) NodeList(ctx context.Context, options NodeListOptions) ([]swarm.Node, error) { query := url.Values{} if options.Filters.Len() > 0 { diff --git a/client/node_list_test.go b/client/node_list_test.go index 2c412f2397..a4ed738648 100644 --- a/client/node_list_test.go +++ b/client/node_list_test.go @@ -22,7 +22,7 @@ func TestNodeListError(t *testing.T) { client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), } - _, err := client.NodeList(context.Background(), swarm.NodeListOptions{}) + _, err := client.NodeList(context.Background(), NodeListOptions{}) assert.Check(t, is.ErrorType(err, cerrdefs.IsInternal)) } @@ -30,17 +30,17 @@ func TestNodeList(t *testing.T) { const expectedURL = "/nodes" listCases := []struct { - options swarm.NodeListOptions + options NodeListOptions expectedQueryParams map[string]string }{ { - options: swarm.NodeListOptions{}, + options: NodeListOptions{}, expectedQueryParams: map[string]string{ "filters": "", }, }, { - options: swarm.NodeListOptions{ + options: NodeListOptions{ Filters: filters.NewArgs( filters.Arg("label", "label1"), filters.Arg("label", "label2"), diff --git a/client/swarm_node_list_opts.go b/client/swarm_node_list_opts.go new file mode 100644 index 0000000000..9fb8c4245d --- /dev/null +++ b/client/swarm_node_list_opts.go @@ -0,0 +1,8 @@ +package client + +import "github.com/moby/moby/api/types/filters" + +// NodeListOptions holds parameters to list nodes with. +type NodeListOptions struct { + Filters filters.Args +} diff --git a/daemon/cluster/nodes.go b/daemon/cluster/nodes.go index 9b087c1975..1de9c87fab 100644 --- a/daemon/cluster/nodes.go +++ b/daemon/cluster/nodes.go @@ -5,13 +5,14 @@ import ( types "github.com/moby/moby/api/types/swarm" "github.com/moby/moby/v2/daemon/cluster/convert" + "github.com/moby/moby/v2/daemon/server/swarmbackend" "github.com/moby/moby/v2/errdefs" swarmapi "github.com/moby/swarmkit/v2/api" "google.golang.org/grpc" ) // GetNodes returns a list of all nodes known to a cluster. -func (c *Cluster) GetNodes(options types.NodeListOptions) ([]types.Node, error) { +func (c *Cluster) GetNodes(options swarmbackend.NodeListOptions) ([]types.Node, error) { c.mu.RLock() defer c.mu.RUnlock() diff --git a/daemon/server/router/swarm/backend.go b/daemon/server/router/swarm/backend.go index 6e035dd9f3..b299796638 100644 --- a/daemon/server/router/swarm/backend.go +++ b/daemon/server/router/swarm/backend.go @@ -24,7 +24,7 @@ type Backend interface { UpdateService(string, uint64, swarm.ServiceSpec, swarm.ServiceUpdateOptions, bool) (*swarm.ServiceUpdateResponse, error) RemoveService(string) error ServiceLogs(context.Context, *backend.LogSelector, *container.LogsOptions) (<-chan *backend.LogMessage, error) - GetNodes(swarm.NodeListOptions) ([]swarm.Node, error) + GetNodes(swarmbackend.NodeListOptions) ([]swarm.Node, error) GetNode(string) (swarm.Node, error) UpdateNode(string, uint64, swarm.NodeSpec) error RemoveNode(string, bool) error diff --git a/daemon/server/router/swarm/cluster_routes.go b/daemon/server/router/swarm/cluster_routes.go index fe3b87eaf8..5b08532462 100644 --- a/daemon/server/router/swarm/cluster_routes.go +++ b/daemon/server/router/swarm/cluster_routes.go @@ -314,7 +314,7 @@ func (sr *swarmRouter) getNodes(ctx context.Context, w http.ResponseWriter, r *h return err } - nodes, err := sr.backend.GetNodes(types.NodeListOptions{Filters: filter}) + nodes, err := sr.backend.GetNodes(swarmbackend.NodeListOptions{Filters: filter}) if err != nil { log.G(ctx).WithContext(ctx).WithError(err).Debug("Error getting nodes") return err diff --git a/daemon/server/swarmbackend/swarm.go b/daemon/server/swarmbackend/swarm.go index 5d7a6280ca..c7fd12b37c 100644 --- a/daemon/server/swarmbackend/swarm.go +++ b/daemon/server/swarmbackend/swarm.go @@ -5,3 +5,7 @@ import "github.com/moby/moby/api/types/filters" type ConfigListOptions struct { Filters filters.Args } + +type NodeListOptions struct { + Filters filters.Args +} diff --git a/integration-cli/daemon/daemon_swarm.go b/integration-cli/daemon/daemon_swarm.go index 0842d0406a..6fd3d45a11 100644 --- a/integration-cli/daemon/daemon_swarm.go +++ b/integration-cli/daemon/daemon_swarm.go @@ -10,6 +10,7 @@ import ( cerrdefs "github.com/containerd/errdefs" "github.com/moby/moby/api/types/filters" "github.com/moby/moby/api/types/swarm" + "github.com/moby/moby/client" "gotest.tools/v3/assert" ) @@ -178,7 +179,7 @@ func (d *Daemon) CheckLeader(ctx context.Context) func(t *testing.T) (any, strin errList := "could not get node list" - ls, err := cli.NodeList(ctx, swarm.NodeListOptions{}) + ls, err := cli.NodeList(ctx, client.NodeListOptions{}) if err != nil { return err, errList } diff --git a/testutil/daemon/node.go b/testutil/daemon/node.go index 6a3fe6ffad..c5aa3db8d3 100644 --- a/testutil/daemon/node.go +++ b/testutil/daemon/node.go @@ -7,6 +7,7 @@ import ( "time" "github.com/moby/moby/api/types/swarm" + "github.com/moby/moby/client" "gotest.tools/v3/assert" ) @@ -73,7 +74,7 @@ func (d *Daemon) ListNodes(ctx context.Context, t testing.TB) []swarm.Node { cli := d.NewClientT(t) defer cli.Close() - nodes, err := cli.NodeList(ctx, swarm.NodeListOptions{}) + nodes, err := cli.NodeList(ctx, client.NodeListOptions{}) assert.NilError(t, err) return nodes diff --git a/vendor/github.com/moby/moby/api/types/swarm/node.go b/vendor/github.com/moby/moby/api/types/swarm/node.go index 3e503ef24b..a41c0e4778 100644 --- a/vendor/github.com/moby/moby/api/types/swarm/node.go +++ b/vendor/github.com/moby/moby/api/types/swarm/node.go @@ -1,7 +1,5 @@ package swarm -import "github.com/moby/moby/api/types/filters" - // Node represents a node. type Node struct { ID string @@ -140,11 +138,6 @@ type Topology struct { Segments map[string]string `json:",omitempty"` } -// NodeListOptions holds parameters to list nodes with. -type NodeListOptions struct { - Filters filters.Args -} - // NodeRemoveOptions holds parameters to remove nodes with. type NodeRemoveOptions struct { Force bool diff --git a/vendor/github.com/moby/moby/client/client_interfaces.go b/vendor/github.com/moby/moby/client/client_interfaces.go index c962122902..55a30ed056 100644 --- a/vendor/github.com/moby/moby/client/client_interfaces.go +++ b/vendor/github.com/moby/moby/client/client_interfaces.go @@ -141,7 +141,7 @@ type NetworkAPIClient interface { // NodeAPIClient defines API client methods for the nodes type NodeAPIClient interface { NodeInspectWithRaw(ctx context.Context, nodeID string) (swarm.Node, []byte, error) - NodeList(ctx context.Context, options swarm.NodeListOptions) ([]swarm.Node, error) + NodeList(ctx context.Context, options NodeListOptions) ([]swarm.Node, error) NodeRemove(ctx context.Context, nodeID string, options swarm.NodeRemoveOptions) error NodeUpdate(ctx context.Context, nodeID string, version swarm.Version, node swarm.NodeSpec) error } diff --git a/vendor/github.com/moby/moby/client/node_list.go b/vendor/github.com/moby/moby/client/node_list.go index f6d2cad23e..96e9caba1d 100644 --- a/vendor/github.com/moby/moby/client/node_list.go +++ b/vendor/github.com/moby/moby/client/node_list.go @@ -10,7 +10,7 @@ import ( ) // NodeList returns the list of nodes. -func (cli *Client) NodeList(ctx context.Context, options swarm.NodeListOptions) ([]swarm.Node, error) { +func (cli *Client) NodeList(ctx context.Context, options NodeListOptions) ([]swarm.Node, error) { query := url.Values{} if options.Filters.Len() > 0 { diff --git a/vendor/github.com/moby/moby/client/swarm_node_list_opts.go b/vendor/github.com/moby/moby/client/swarm_node_list_opts.go new file mode 100644 index 0000000000..9fb8c4245d --- /dev/null +++ b/vendor/github.com/moby/moby/client/swarm_node_list_opts.go @@ -0,0 +1,8 @@ +package client + +import "github.com/moby/moby/api/types/filters" + +// NodeListOptions holds parameters to list nodes with. +type NodeListOptions struct { + Filters filters.Args +}