Skip to content

Commit b135285

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

19 files changed

Lines changed: 67 additions & 58 deletions

api/server/router/swarm/backend.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ type Backend interface {
1818
Update(uint64, swarm.Spec, swarm.UpdateFlags) error
1919
GetUnlockKey() (string, error)
2020
UnlockSwarm(req swarm.UnlockRequest) error
21-
GetServices(types.ServiceListOptions) ([]swarm.Service, error)
21+
GetServices(swarm.ServiceListOptions) ([]swarm.Service, error)
2222
GetService(idOrName string, insertDefaults bool) (swarm.Service, error)
2323
CreateService(swarm.ServiceSpec, string, bool) (*swarm.ServiceCreateResponse, error)
2424
UpdateService(string, uint64, swarm.ServiceSpec, types.ServiceUpdateOptions, bool) (*swarm.ServiceUpdateResponse, error)

api/server/router/swarm/cluster_routes.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ func (sr *swarmRouter) getServices(ctx context.Context, w http.ResponseWriter, r
166166
}
167167
}
168168

169-
services, err := sr.backend.GetServices(basictypes.ServiceListOptions{Filters: filter, Status: status})
169+
services, err := sr.backend.GetServices(types.ServiceListOptions{Filters: filter, Status: status})
170170
if err != nil {
171171
log.G(ctx).WithContext(ctx).WithError(err).Debug("Error getting services")
172172
return err

api/types/client.go

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -109,21 +109,6 @@ type ServiceUpdateOptions struct {
109109
QueryRegistry bool
110110
}
111111

112-
// ServiceListOptions holds parameters to list services with.
113-
type ServiceListOptions struct {
114-
Filters filters.Args
115-
116-
// Status indicates whether the server should include the service task
117-
// count of running and desired tasks.
118-
Status bool
119-
}
120-
121-
// ServiceInspectOptions holds parameters related to the "service inspect"
122-
// operation.
123-
type ServiceInspectOptions struct {
124-
InsertDefaults bool
125-
}
126-
127112
// TaskListOptions holds parameters to list tasks with.
128113
type TaskListOptions struct {
129114
Filters filters.Args

api/types/swarm/service.go

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
package swarm // import "github.com/docker/docker/api/types/swarm"
22

3-
import "time"
3+
import (
4+
"time"
5+
6+
"github.com/docker/docker/api/types/filters"
7+
)
48

59
// Service represents a service.
610
type Service struct {
@@ -200,3 +204,18 @@ type JobStatus struct {
200204
// Swarm manager.
201205
LastExecution time.Time `json:",omitempty"`
202206
}
207+
208+
// ServiceListOptions holds parameters to list services with.
209+
type ServiceListOptions struct {
210+
Filters filters.Args
211+
212+
// Status indicates whether the server should include the service task
213+
// count of running and desired tasks.
214+
Status bool
215+
}
216+
217+
// ServiceInspectOptions holds parameters related to the "service inspect"
218+
// operation.
219+
type ServiceInspectOptions struct {
220+
InsertDefaults bool
221+
}

api/types/types_deprecated.go

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

141+
// ServiceListOptions holds parameters to list services with.
142+
//
143+
// Deprecated: use [swarm.ServiceListOptions].
144+
type ServiceListOptions = swarm.ServiceListOptions
145+
146+
// ServiceInspectOptions holds parameters related to the "service inspect"
147+
// operation.
148+
//
149+
// Deprecated: use [swarm.ServiceInspectOptions].
150+
type ServiceInspectOptions = swarm.ServiceInspectOptions
151+
141152
// BuildCache contains information about a build cache record.
142153
//
143154
// Deprecated: deprecated in API 1.49. Use [build.CacheRecord] instead.

client/client_interfaces.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,8 @@ type PluginAPIClient interface {
177177
// ServiceAPIClient defines API client methods for the services
178178
type ServiceAPIClient interface {
179179
ServiceCreate(ctx context.Context, service swarm.ServiceSpec, options types.ServiceCreateOptions) (swarm.ServiceCreateResponse, error)
180-
ServiceInspectWithRaw(ctx context.Context, serviceID string, options types.ServiceInspectOptions) (swarm.Service, []byte, error)
181-
ServiceList(ctx context.Context, options types.ServiceListOptions) ([]swarm.Service, error)
180+
ServiceInspectWithRaw(ctx context.Context, serviceID string, options swarm.ServiceInspectOptions) (swarm.Service, []byte, error)
181+
ServiceList(ctx context.Context, options swarm.ServiceListOptions) ([]swarm.Service, error)
182182
ServiceRemove(ctx context.Context, serviceID string) error
183183
ServiceUpdate(ctx context.Context, serviceID string, version swarm.Version, service swarm.ServiceSpec, options types.ServiceUpdateOptions) (swarm.ServiceUpdateResponse, error)
184184
ServiceLogs(ctx context.Context, serviceID string, options container.LogsOptions) (io.ReadCloser, error)

client/service_inspect.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,11 @@ import (
88
"io"
99
"net/url"
1010

11-
"github.com/docker/docker/api/types"
1211
"github.com/docker/docker/api/types/swarm"
1312
)
1413

1514
// ServiceInspectWithRaw returns the service information and the raw data.
16-
func (cli *Client) ServiceInspectWithRaw(ctx context.Context, serviceID string, opts types.ServiceInspectOptions) (swarm.Service, []byte, error) {
15+
func (cli *Client) ServiceInspectWithRaw(ctx context.Context, serviceID string, opts swarm.ServiceInspectOptions) (swarm.Service, []byte, error) {
1716
serviceID, err := trimID("service", serviceID)
1817
if err != nil {
1918
return swarm.Service{}, nil, err

client/service_inspect_test.go

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

14-
"github.com/docker/docker/api/types"
1514
"github.com/docker/docker/api/types/swarm"
1615
"github.com/docker/docker/errdefs"
1716
"gotest.tools/v3/assert"
@@ -23,7 +22,7 @@ func TestServiceInspectError(t *testing.T) {
2322
client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")),
2423
}
2524

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

@@ -32,7 +31,7 @@ func TestServiceInspectServiceNotFound(t *testing.T) {
3231
client: newMockClient(errorMock(http.StatusNotFound, "Server error")),
3332
}
3433

35-
_, _, err := client.ServiceInspectWithRaw(context.Background(), "unknown", types.ServiceInspectOptions{})
34+
_, _, err := client.ServiceInspectWithRaw(context.Background(), "unknown", swarm.ServiceInspectOptions{})
3635
assert.Check(t, is.ErrorType(err, errdefs.IsNotFound))
3736
}
3837

@@ -42,11 +41,11 @@ func TestServiceInspectWithEmptyID(t *testing.T) {
4241
return nil, errors.New("should not make request")
4342
}),
4443
}
45-
_, _, err := client.ServiceInspectWithRaw(context.Background(), "", types.ServiceInspectOptions{})
44+
_, _, err := client.ServiceInspectWithRaw(context.Background(), "", swarm.ServiceInspectOptions{})
4645
assert.Check(t, is.ErrorType(err, errdefs.IsInvalidParameter))
4746
assert.Check(t, is.ErrorContains(err, "value is empty"))
4847

49-
_, _, err = client.ServiceInspectWithRaw(context.Background(), " ", types.ServiceInspectOptions{})
48+
_, _, err = client.ServiceInspectWithRaw(context.Background(), " ", swarm.ServiceInspectOptions{})
5049
assert.Check(t, is.ErrorType(err, errdefs.IsInvalidParameter))
5150
assert.Check(t, is.ErrorContains(err, "value is empty"))
5251
}
@@ -71,7 +70,7 @@ func TestServiceInspect(t *testing.T) {
7170
}),
7271
}
7372

74-
serviceInspect, _, err := client.ServiceInspectWithRaw(context.Background(), "service_id", types.ServiceInspectOptions{})
73+
serviceInspect, _, err := client.ServiceInspectWithRaw(context.Background(), "service_id", swarm.ServiceInspectOptions{})
7574
assert.NilError(t, err)
7675
assert.Check(t, is.Equal(serviceInspect.ID, "service_id"))
7776
}

client/service_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
// ServiceList returns the list of services.
14-
func (cli *Client) ServiceList(ctx context.Context, options types.ServiceListOptions) ([]swarm.Service, error) {
13+
func (cli *Client) ServiceList(ctx context.Context, options swarm.ServiceListOptions) ([]swarm.Service, error) {
1514
query := url.Values{}
1615

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

client/service_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 TestServiceListError(t *testing.T) {
2322
client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")),
2423
}
2524

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

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

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

0 commit comments

Comments
 (0)