Skip to content

Commit f008d85

Browse files
committed
api/types: move NodeListOptions, NodeRemoveOptions to types/swarm
Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent b135285 commit f008d85

13 files changed

Lines changed: 41 additions & 34 deletions

File tree

api/server/router/swarm/backend.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ type Backend interface {
2424
UpdateService(string, uint64, swarm.ServiceSpec, types.ServiceUpdateOptions, bool) (*swarm.ServiceUpdateResponse, error)
2525
RemoveService(string) error
2626
ServiceLogs(context.Context, *backend.LogSelector, *container.LogsOptions) (<-chan *backend.LogMessage, error)
27-
GetNodes(types.NodeListOptions) ([]swarm.Node, error)
27+
GetNodes(swarm.NodeListOptions) ([]swarm.Node, error)
2828
GetNode(string) (swarm.Node, error)
2929
UpdateNode(string, uint64, swarm.NodeSpec) error
3030
RemoveNode(string, bool) error

api/server/router/swarm/cluster_routes.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ func (sr *swarmRouter) getNodes(ctx context.Context, w http.ResponseWriter, r *h
314314
return err
315315
}
316316

317-
nodes, err := sr.backend.GetNodes(basictypes.NodeListOptions{Filters: filter})
317+
nodes, err := sr.backend.GetNodes(types.NodeListOptions{Filters: filter})
318318
if err != nil {
319319
log.G(ctx).WithContext(ctx).WithError(err).Debug("Error getting nodes")
320320
return err

api/types/client.go

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,6 @@ func (h *HijackedResponse) CloseWrite() error {
4848
return nil
4949
}
5050

51-
// NodeListOptions holds parameters to list nodes with.
52-
type NodeListOptions struct {
53-
Filters filters.Args
54-
}
55-
56-
// NodeRemoveOptions holds parameters to remove nodes with.
57-
type NodeRemoveOptions struct {
58-
Force bool
59-
}
60-
6151
// ServiceCreateOptions contains the options to use when creating a service.
6252
type ServiceCreateOptions struct {
6353
// EncodedRegistryAuth is the encoded registry authorization credentials to

api/types/swarm/node.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
package swarm // import "github.com/docker/docker/api/types/swarm"
2+
import "github.com/docker/docker/api/types/filters"
23

34
// Node represents a node.
45
type Node struct {
@@ -137,3 +138,13 @@ const (
137138
type Topology struct {
138139
Segments map[string]string `json:",omitempty"`
139140
}
141+
142+
// NodeListOptions holds parameters to list nodes with.
143+
type NodeListOptions struct {
144+
Filters filters.Args
145+
}
146+
147+
// NodeRemoveOptions holds parameters to remove nodes with.
148+
type NodeRemoveOptions struct {
149+
Force bool
150+
}

api/types/types_deprecated.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,16 @@ type ConfigCreateResponse = swarm.ConfigCreateResponse
138138
// Deprecated: use [swarm.ConfigListOptions].
139139
type ConfigListOptions = swarm.ConfigListOptions
140140

141+
// NodeListOptions holds parameters to list nodes with.
142+
//
143+
// Deprecated: use [swarm.NodeListOptions].
144+
type NodeListOptions = swarm.NodeListOptions
145+
146+
// NodeRemoveOptions holds parameters to remove nodes with.
147+
//
148+
// Deprecated: use [swarm.NodeRemoveOptions].
149+
type NodeRemoveOptions = swarm.NodeRemoveOptions
150+
141151
// ServiceListOptions holds parameters to list services with.
142152
//
143153
// Deprecated: use [swarm.ServiceListOptions].

client/client_interfaces.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,8 @@ type NetworkAPIClient interface {
155155
// NodeAPIClient defines API client methods for the nodes
156156
type NodeAPIClient interface {
157157
NodeInspectWithRaw(ctx context.Context, nodeID string) (swarm.Node, []byte, error)
158-
NodeList(ctx context.Context, options types.NodeListOptions) ([]swarm.Node, error)
159-
NodeRemove(ctx context.Context, nodeID string, options types.NodeRemoveOptions) error
158+
NodeList(ctx context.Context, options swarm.NodeListOptions) ([]swarm.Node, error)
159+
NodeRemove(ctx context.Context, nodeID string, options swarm.NodeRemoveOptions) error
160160
NodeUpdate(ctx context.Context, nodeID string, version swarm.Version, node swarm.NodeSpec) error
161161
}
162162

client/node_list.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,12 @@ import (
55
"encoding/json"
66
"net/url"
77

8-
"github.com/docker/docker/api/types"
98
"github.com/docker/docker/api/types/filters"
109
"github.com/docker/docker/api/types/swarm"
1110
)
1211

1312
// NodeList returns the list of nodes.
14-
func (cli *Client) NodeList(ctx context.Context, options types.NodeListOptions) ([]swarm.Node, error) {
13+
func (cli *Client) NodeList(ctx context.Context, options swarm.NodeListOptions) ([]swarm.Node, error) {
1514
query := url.Values{}
1615

1716
if options.Filters.Len() > 0 {

client/node_list_test.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"strings"
1111
"testing"
1212

13-
"github.com/docker/docker/api/types"
1413
"github.com/docker/docker/api/types/filters"
1514
"github.com/docker/docker/api/types/swarm"
1615
"github.com/docker/docker/errdefs"
@@ -23,25 +22,25 @@ func TestNodeListError(t *testing.T) {
2322
client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")),
2423
}
2524

26-
_, err := client.NodeList(context.Background(), types.NodeListOptions{})
25+
_, err := client.NodeList(context.Background(), swarm.NodeListOptions{})
2726
assert.Check(t, is.ErrorType(err, errdefs.IsSystem))
2827
}
2928

3029
func TestNodeList(t *testing.T) {
3130
const expectedURL = "/nodes"
3231

3332
listCases := []struct {
34-
options types.NodeListOptions
33+
options swarm.NodeListOptions
3534
expectedQueryParams map[string]string
3635
}{
3736
{
38-
options: types.NodeListOptions{},
37+
options: swarm.NodeListOptions{},
3938
expectedQueryParams: map[string]string{
4039
"filters": "",
4140
},
4241
},
4342
{
44-
options: types.NodeListOptions{
43+
options: swarm.NodeListOptions{
4544
Filters: filters.NewArgs(
4645
filters.Arg("label", "label1"),
4746
filters.Arg("label", "label2"),

client/node_remove.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ import (
44
"context"
55
"net/url"
66

7-
"github.com/docker/docker/api/types"
7+
"github.com/docker/docker/api/types/swarm"
88
)
99

1010
// NodeRemove removes a Node.
11-
func (cli *Client) NodeRemove(ctx context.Context, nodeID string, options types.NodeRemoveOptions) error {
11+
func (cli *Client) NodeRemove(ctx context.Context, nodeID string, options swarm.NodeRemoveOptions) error {
1212
nodeID, err := trimID("node", nodeID)
1313
if err != nil {
1414
return err

client/node_remove_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"strings"
1010
"testing"
1111

12-
"github.com/docker/docker/api/types"
12+
"github.com/docker/docker/api/types/swarm"
1313
"github.com/docker/docker/errdefs"
1414
"gotest.tools/v3/assert"
1515
is "gotest.tools/v3/assert/cmp"
@@ -20,14 +20,14 @@ func TestNodeRemoveError(t *testing.T) {
2020
client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")),
2121
}
2222

23-
err := client.NodeRemove(context.Background(), "node_id", types.NodeRemoveOptions{Force: false})
23+
err := client.NodeRemove(context.Background(), "node_id", swarm.NodeRemoveOptions{Force: false})
2424
assert.Check(t, is.ErrorType(err, errdefs.IsSystem))
2525

26-
err = client.NodeRemove(context.Background(), "", types.NodeRemoveOptions{Force: false})
26+
err = client.NodeRemove(context.Background(), "", swarm.NodeRemoveOptions{Force: false})
2727
assert.Check(t, is.ErrorType(err, errdefs.IsInvalidParameter))
2828
assert.Check(t, is.ErrorContains(err, "value is empty"))
2929

30-
err = client.NodeRemove(context.Background(), " ", types.NodeRemoveOptions{Force: false})
30+
err = client.NodeRemove(context.Background(), " ", swarm.NodeRemoveOptions{Force: false})
3131
assert.Check(t, is.ErrorType(err, errdefs.IsInvalidParameter))
3232
assert.Check(t, is.ErrorContains(err, "value is empty"))
3333
}
@@ -69,7 +69,7 @@ func TestNodeRemove(t *testing.T) {
6969
}),
7070
}
7171

72-
err := client.NodeRemove(context.Background(), "node_id", types.NodeRemoveOptions{Force: removeCase.force})
72+
err := client.NodeRemove(context.Background(), "node_id", swarm.NodeRemoveOptions{Force: removeCase.force})
7373
assert.NilError(t, err)
7474
}
7575
}

0 commit comments

Comments
 (0)