Browse code

api/types/swarm: move `NodeListOptions` to client mod

Signed-off-by: Austin Vazquez <austin.vazquez@docker.com>

Austin Vazquez authored on 2025/08/23 00:03:57
Showing 15 changed files
... ...
@@ -1,7 +1,5 @@
1 1
 package swarm
2 2
 
3
-import "github.com/moby/moby/api/types/filters"
4
-
5 3
 // Node represents a node.
6 4
 type Node struct {
7 5
 	ID string
... ...
@@ -140,11 +138,6 @@ type Topology struct {
140 140
 	Segments map[string]string `json:",omitempty"`
141 141
 }
142 142
 
143
-// NodeListOptions holds parameters to list nodes with.
144
-type NodeListOptions struct {
145
-	Filters filters.Args
146
-}
147
-
148 143
 // NodeRemoveOptions holds parameters to remove nodes with.
149 144
 type NodeRemoveOptions struct {
150 145
 	Force bool
... ...
@@ -141,7 +141,7 @@ type NetworkAPIClient interface {
141 141
 // NodeAPIClient defines API client methods for the nodes
142 142
 type NodeAPIClient interface {
143 143
 	NodeInspectWithRaw(ctx context.Context, nodeID string) (swarm.Node, []byte, error)
144
-	NodeList(ctx context.Context, options swarm.NodeListOptions) ([]swarm.Node, error)
144
+	NodeList(ctx context.Context, options NodeListOptions) ([]swarm.Node, error)
145 145
 	NodeRemove(ctx context.Context, nodeID string, options swarm.NodeRemoveOptions) error
146 146
 	NodeUpdate(ctx context.Context, nodeID string, version swarm.Version, node swarm.NodeSpec) error
147 147
 }
... ...
@@ -10,7 +10,7 @@ import (
10 10
 )
11 11
 
12 12
 // NodeList returns the list of nodes.
13
-func (cli *Client) NodeList(ctx context.Context, options swarm.NodeListOptions) ([]swarm.Node, error) {
13
+func (cli *Client) NodeList(ctx context.Context, options NodeListOptions) ([]swarm.Node, error) {
14 14
 	query := url.Values{}
15 15
 
16 16
 	if options.Filters.Len() > 0 {
... ...
@@ -22,7 +22,7 @@ func TestNodeListError(t *testing.T) {
22 22
 		client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")),
23 23
 	}
24 24
 
25
-	_, err := client.NodeList(context.Background(), swarm.NodeListOptions{})
25
+	_, err := client.NodeList(context.Background(), NodeListOptions{})
26 26
 	assert.Check(t, is.ErrorType(err, cerrdefs.IsInternal))
27 27
 }
28 28
 
... ...
@@ -30,17 +30,17 @@ func TestNodeList(t *testing.T) {
30 30
 	const expectedURL = "/nodes"
31 31
 
32 32
 	listCases := []struct {
33
-		options             swarm.NodeListOptions
33
+		options             NodeListOptions
34 34
 		expectedQueryParams map[string]string
35 35
 	}{
36 36
 		{
37
-			options: swarm.NodeListOptions{},
37
+			options: NodeListOptions{},
38 38
 			expectedQueryParams: map[string]string{
39 39
 				"filters": "",
40 40
 			},
41 41
 		},
42 42
 		{
43
-			options: swarm.NodeListOptions{
43
+			options: NodeListOptions{
44 44
 				Filters: filters.NewArgs(
45 45
 					filters.Arg("label", "label1"),
46 46
 					filters.Arg("label", "label2"),
47 47
new file mode 100644
... ...
@@ -0,0 +1,8 @@
0
+package client
1
+
2
+import "github.com/moby/moby/api/types/filters"
3
+
4
+// NodeListOptions holds parameters to list nodes with.
5
+type NodeListOptions struct {
6
+	Filters filters.Args
7
+}
... ...
@@ -5,13 +5,14 @@ import (
5 5
 
6 6
 	types "github.com/moby/moby/api/types/swarm"
7 7
 	"github.com/moby/moby/v2/daemon/cluster/convert"
8
+	"github.com/moby/moby/v2/daemon/server/swarmbackend"
8 9
 	"github.com/moby/moby/v2/errdefs"
9 10
 	swarmapi "github.com/moby/swarmkit/v2/api"
10 11
 	"google.golang.org/grpc"
11 12
 )
12 13
 
13 14
 // GetNodes returns a list of all nodes known to a cluster.
14
-func (c *Cluster) GetNodes(options types.NodeListOptions) ([]types.Node, error) {
15
+func (c *Cluster) GetNodes(options swarmbackend.NodeListOptions) ([]types.Node, error) {
15 16
 	c.mu.RLock()
16 17
 	defer c.mu.RUnlock()
17 18
 
... ...
@@ -24,7 +24,7 @@ type Backend interface {
24 24
 	UpdateService(string, uint64, swarm.ServiceSpec, swarm.ServiceUpdateOptions, bool) (*swarm.ServiceUpdateResponse, error)
25 25
 	RemoveService(string) error
26 26
 	ServiceLogs(context.Context, *backend.LogSelector, *container.LogsOptions) (<-chan *backend.LogMessage, error)
27
-	GetNodes(swarm.NodeListOptions) ([]swarm.Node, error)
27
+	GetNodes(swarmbackend.NodeListOptions) ([]swarm.Node, error)
28 28
 	GetNode(string) (swarm.Node, error)
29 29
 	UpdateNode(string, uint64, swarm.NodeSpec) error
30 30
 	RemoveNode(string, bool) error
... ...
@@ -314,7 +314,7 @@ func (sr *swarmRouter) getNodes(ctx context.Context, w http.ResponseWriter, r *h
314 314
 		return err
315 315
 	}
316 316
 
317
-	nodes, err := sr.backend.GetNodes(types.NodeListOptions{Filters: filter})
317
+	nodes, err := sr.backend.GetNodes(swarmbackend.NodeListOptions{Filters: filter})
318 318
 	if err != nil {
319 319
 		log.G(ctx).WithContext(ctx).WithError(err).Debug("Error getting nodes")
320 320
 		return err
... ...
@@ -5,3 +5,7 @@ import "github.com/moby/moby/api/types/filters"
5 5
 type ConfigListOptions struct {
6 6
 	Filters filters.Args
7 7
 }
8
+
9
+type NodeListOptions struct {
10
+	Filters filters.Args
11
+}
... ...
@@ -10,6 +10,7 @@ import (
10 10
 	cerrdefs "github.com/containerd/errdefs"
11 11
 	"github.com/moby/moby/api/types/filters"
12 12
 	"github.com/moby/moby/api/types/swarm"
13
+	"github.com/moby/moby/client"
13 14
 	"gotest.tools/v3/assert"
14 15
 )
15 16
 
... ...
@@ -178,7 +179,7 @@ func (d *Daemon) CheckLeader(ctx context.Context) func(t *testing.T) (any, strin
178 178
 
179 179
 		errList := "could not get node list"
180 180
 
181
-		ls, err := cli.NodeList(ctx, swarm.NodeListOptions{})
181
+		ls, err := cli.NodeList(ctx, client.NodeListOptions{})
182 182
 		if err != nil {
183 183
 			return err, errList
184 184
 		}
... ...
@@ -7,6 +7,7 @@ import (
7 7
 	"time"
8 8
 
9 9
 	"github.com/moby/moby/api/types/swarm"
10
+	"github.com/moby/moby/client"
10 11
 	"gotest.tools/v3/assert"
11 12
 )
12 13
 
... ...
@@ -73,7 +74,7 @@ func (d *Daemon) ListNodes(ctx context.Context, t testing.TB) []swarm.Node {
73 73
 	cli := d.NewClientT(t)
74 74
 	defer cli.Close()
75 75
 
76
-	nodes, err := cli.NodeList(ctx, swarm.NodeListOptions{})
76
+	nodes, err := cli.NodeList(ctx, client.NodeListOptions{})
77 77
 	assert.NilError(t, err)
78 78
 
79 79
 	return nodes
... ...
@@ -1,7 +1,5 @@
1 1
 package swarm
2 2
 
3
-import "github.com/moby/moby/api/types/filters"
4
-
5 3
 // Node represents a node.
6 4
 type Node struct {
7 5
 	ID string
... ...
@@ -140,11 +138,6 @@ type Topology struct {
140 140
 	Segments map[string]string `json:",omitempty"`
141 141
 }
142 142
 
143
-// NodeListOptions holds parameters to list nodes with.
144
-type NodeListOptions struct {
145
-	Filters filters.Args
146
-}
147
-
148 143
 // NodeRemoveOptions holds parameters to remove nodes with.
149 144
 type NodeRemoveOptions struct {
150 145
 	Force bool
... ...
@@ -141,7 +141,7 @@ type NetworkAPIClient interface {
141 141
 // NodeAPIClient defines API client methods for the nodes
142 142
 type NodeAPIClient interface {
143 143
 	NodeInspectWithRaw(ctx context.Context, nodeID string) (swarm.Node, []byte, error)
144
-	NodeList(ctx context.Context, options swarm.NodeListOptions) ([]swarm.Node, error)
144
+	NodeList(ctx context.Context, options NodeListOptions) ([]swarm.Node, error)
145 145
 	NodeRemove(ctx context.Context, nodeID string, options swarm.NodeRemoveOptions) error
146 146
 	NodeUpdate(ctx context.Context, nodeID string, version swarm.Version, node swarm.NodeSpec) error
147 147
 }
... ...
@@ -10,7 +10,7 @@ import (
10 10
 )
11 11
 
12 12
 // NodeList returns the list of nodes.
13
-func (cli *Client) NodeList(ctx context.Context, options swarm.NodeListOptions) ([]swarm.Node, error) {
13
+func (cli *Client) NodeList(ctx context.Context, options NodeListOptions) ([]swarm.Node, error) {
14 14
 	query := url.Values{}
15 15
 
16 16
 	if options.Filters.Len() > 0 {
17 17
new file mode 100644
... ...
@@ -0,0 +1,8 @@
0
+package client
1
+
2
+import "github.com/moby/moby/api/types/filters"
3
+
4
+// NodeListOptions holds parameters to list nodes with.
5
+type NodeListOptions struct {
6
+	Filters filters.Args
7
+}