mirror of
https://github.com/moby/moby.git
synced 2026-01-11 18:51:37 +00:00
api/types/swarm: move ServiceListOptions type to client
Signed-off-by: Austin Vazquez <austin.vazquez@docker.com>
This commit is contained in:
@@ -2,8 +2,6 @@ package swarm
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/moby/moby/api/types/filters"
|
||||
)
|
||||
|
||||
// Service represents a service.
|
||||
@@ -211,15 +209,6 @@ const (
|
||||
RegistryAuthFromPreviousSpec = "previous-spec"
|
||||
)
|
||||
|
||||
// ServiceListOptions holds parameters to list services with.
|
||||
type ServiceListOptions struct {
|
||||
Filters filters.Args
|
||||
|
||||
// Status indicates whether the server should include the service task
|
||||
// count of running and desired tasks.
|
||||
Status bool
|
||||
}
|
||||
|
||||
// ServiceInspectOptions holds parameters related to the "service inspect"
|
||||
// operation.
|
||||
type ServiceInspectOptions struct {
|
||||
|
||||
@@ -164,7 +164,7 @@ type PluginAPIClient interface {
|
||||
type ServiceAPIClient interface {
|
||||
ServiceCreate(ctx context.Context, service swarm.ServiceSpec, options ServiceCreateOptions) (swarm.ServiceCreateResponse, error)
|
||||
ServiceInspectWithRaw(ctx context.Context, serviceID string, options swarm.ServiceInspectOptions) (swarm.Service, []byte, error)
|
||||
ServiceList(ctx context.Context, options swarm.ServiceListOptions) ([]swarm.Service, error)
|
||||
ServiceList(ctx context.Context, options ServiceListOptions) ([]swarm.Service, error)
|
||||
ServiceRemove(ctx context.Context, serviceID string) error
|
||||
ServiceUpdate(ctx context.Context, serviceID string, version swarm.Version, service swarm.ServiceSpec, options ServiceUpdateOptions) (swarm.ServiceUpdateResponse, error)
|
||||
ServiceLogs(ctx context.Context, serviceID string, options container.LogsOptions) (io.ReadCloser, error)
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
)
|
||||
|
||||
// ServiceList returns the list of services.
|
||||
func (cli *Client) ServiceList(ctx context.Context, options swarm.ServiceListOptions) ([]swarm.Service, error) {
|
||||
func (cli *Client) ServiceList(ctx context.Context, options ServiceListOptions) ([]swarm.Service, error) {
|
||||
query := url.Values{}
|
||||
|
||||
if options.Filters.Len() > 0 {
|
||||
|
||||
@@ -22,7 +22,7 @@ func TestServiceListError(t *testing.T) {
|
||||
client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")),
|
||||
}
|
||||
|
||||
_, err := client.ServiceList(context.Background(), swarm.ServiceListOptions{})
|
||||
_, err := client.ServiceList(context.Background(), ServiceListOptions{})
|
||||
assert.Check(t, is.ErrorType(err, cerrdefs.IsInternal))
|
||||
}
|
||||
|
||||
@@ -30,17 +30,17 @@ func TestServiceList(t *testing.T) {
|
||||
const expectedURL = "/services"
|
||||
|
||||
listCases := []struct {
|
||||
options swarm.ServiceListOptions
|
||||
options ServiceListOptions
|
||||
expectedQueryParams map[string]string
|
||||
}{
|
||||
{
|
||||
options: swarm.ServiceListOptions{},
|
||||
options: ServiceListOptions{},
|
||||
expectedQueryParams: map[string]string{
|
||||
"filters": "",
|
||||
},
|
||||
},
|
||||
{
|
||||
options: swarm.ServiceListOptions{
|
||||
options: ServiceListOptions{
|
||||
Filters: filters.NewArgs(
|
||||
filters.Arg("label", "label1"),
|
||||
filters.Arg("label", "label2"),
|
||||
|
||||
12
client/swarm_service_list_opts.go
Normal file
12
client/swarm_service_list_opts.go
Normal file
@@ -0,0 +1,12 @@
|
||||
package client
|
||||
|
||||
import "github.com/moby/moby/api/types/filters"
|
||||
|
||||
// ServiceListOptions holds parameters to list services with.
|
||||
type ServiceListOptions struct {
|
||||
Filters filters.Args
|
||||
|
||||
// Status indicates whether the server should include the service task
|
||||
// count of running and desired tasks.
|
||||
Status bool
|
||||
}
|
||||
@@ -29,7 +29,7 @@ import (
|
||||
)
|
||||
|
||||
// GetServices returns all services of a managed swarm cluster.
|
||||
func (c *Cluster) GetServices(options swarm.ServiceListOptions) ([]swarm.Service, error) {
|
||||
func (c *Cluster) GetServices(options swarmbackend.ServiceListOptions) ([]swarm.Service, error) {
|
||||
c.mu.RLock()
|
||||
defer c.mu.RUnlock()
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ type Backend interface {
|
||||
Update(uint64, swarm.Spec, swarmbackend.UpdateFlags) error
|
||||
GetUnlockKey() (string, error)
|
||||
UnlockSwarm(req swarm.UnlockRequest) error
|
||||
GetServices(swarm.ServiceListOptions) ([]swarm.Service, error)
|
||||
GetServices(swarmbackend.ServiceListOptions) ([]swarm.Service, error)
|
||||
GetService(idOrName string, insertDefaults bool) (swarm.Service, error)
|
||||
CreateService(swarm.ServiceSpec, string, bool) (*swarm.ServiceCreateResponse, error)
|
||||
UpdateService(string, uint64, swarm.ServiceSpec, swarmbackend.ServiceUpdateOptions, bool) (*swarm.ServiceUpdateResponse, error)
|
||||
|
||||
@@ -166,7 +166,7 @@ func (sr *swarmRouter) getServices(ctx context.Context, w http.ResponseWriter, r
|
||||
}
|
||||
}
|
||||
|
||||
services, err := sr.backend.GetServices(types.ServiceListOptions{Filters: filter, Status: status})
|
||||
services, err := sr.backend.GetServices(swarmbackend.ServiceListOptions{Filters: filter, Status: status})
|
||||
if err != nil {
|
||||
log.G(ctx).WithContext(ctx).WithError(err).Debug("Error getting services")
|
||||
return err
|
||||
|
||||
@@ -42,3 +42,11 @@ type ServiceUpdateOptions struct {
|
||||
// same as "none".
|
||||
Rollback string
|
||||
}
|
||||
|
||||
type ServiceListOptions struct {
|
||||
Filters filters.Args
|
||||
|
||||
// Status indicates whether the server should include the service task
|
||||
// count of running and desired tasks.
|
||||
Status bool
|
||||
}
|
||||
|
||||
@@ -331,9 +331,9 @@ func swarmIngressReady(ctx context.Context, apiClient client.NetworkAPIClient) f
|
||||
}
|
||||
}
|
||||
|
||||
func noServices(ctx context.Context, client client.ServiceAPIClient) func(log poll.LogT) poll.Result {
|
||||
func noServices(ctx context.Context, apiClient client.ServiceAPIClient) func(log poll.LogT) poll.Result {
|
||||
return func(log poll.LogT) poll.Result {
|
||||
services, err := client.ServiceList(ctx, swarmtypes.ServiceListOptions{})
|
||||
services, err := apiClient.ServiceList(ctx, client.ServiceListOptions{})
|
||||
switch {
|
||||
case err != nil:
|
||||
return poll.Error(err)
|
||||
|
||||
@@ -79,7 +79,7 @@ func TestServiceListWithStatuses(t *testing.T) {
|
||||
}
|
||||
|
||||
// now, let's do the list operation with no status arg set.
|
||||
resp, err := apiClient.ServiceList(ctx, swarmtypes.ServiceListOptions{})
|
||||
resp, err := apiClient.ServiceList(ctx, client.ServiceListOptions{})
|
||||
assert.NilError(t, err)
|
||||
assert.Check(t, is.Len(resp, serviceCount))
|
||||
for _, service := range resp {
|
||||
@@ -87,7 +87,7 @@ func TestServiceListWithStatuses(t *testing.T) {
|
||||
}
|
||||
|
||||
// now try again, but with Status: true. This time, we should have statuses
|
||||
resp, err = apiClient.ServiceList(ctx, swarmtypes.ServiceListOptions{Status: true})
|
||||
resp, err = apiClient.ServiceList(ctx, client.ServiceListOptions{Status: true})
|
||||
assert.NilError(t, err)
|
||||
assert.Check(t, is.Len(resp, serviceCount))
|
||||
for _, service := range resp {
|
||||
|
||||
@@ -102,7 +102,7 @@ func (d *Daemon) ListServices(ctx context.Context, t testing.TB) []swarm.Service
|
||||
cli := d.NewClientT(t)
|
||||
defer cli.Close()
|
||||
|
||||
services, err := cli.ServiceList(ctx, swarm.ServiceListOptions{})
|
||||
services, err := cli.ServiceList(ctx, client.ServiceListOptions{})
|
||||
assert.NilError(t, err)
|
||||
return services
|
||||
}
|
||||
|
||||
11
vendor/github.com/moby/moby/api/types/swarm/service.go
generated
vendored
11
vendor/github.com/moby/moby/api/types/swarm/service.go
generated
vendored
@@ -2,8 +2,6 @@ package swarm
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/moby/moby/api/types/filters"
|
||||
)
|
||||
|
||||
// Service represents a service.
|
||||
@@ -211,15 +209,6 @@ const (
|
||||
RegistryAuthFromPreviousSpec = "previous-spec"
|
||||
)
|
||||
|
||||
// ServiceListOptions holds parameters to list services with.
|
||||
type ServiceListOptions struct {
|
||||
Filters filters.Args
|
||||
|
||||
// Status indicates whether the server should include the service task
|
||||
// count of running and desired tasks.
|
||||
Status bool
|
||||
}
|
||||
|
||||
// ServiceInspectOptions holds parameters related to the "service inspect"
|
||||
// operation.
|
||||
type ServiceInspectOptions struct {
|
||||
|
||||
2
vendor/github.com/moby/moby/client/client_interfaces.go
generated
vendored
2
vendor/github.com/moby/moby/client/client_interfaces.go
generated
vendored
@@ -164,7 +164,7 @@ type PluginAPIClient interface {
|
||||
type ServiceAPIClient interface {
|
||||
ServiceCreate(ctx context.Context, service swarm.ServiceSpec, options ServiceCreateOptions) (swarm.ServiceCreateResponse, error)
|
||||
ServiceInspectWithRaw(ctx context.Context, serviceID string, options swarm.ServiceInspectOptions) (swarm.Service, []byte, error)
|
||||
ServiceList(ctx context.Context, options swarm.ServiceListOptions) ([]swarm.Service, error)
|
||||
ServiceList(ctx context.Context, options ServiceListOptions) ([]swarm.Service, error)
|
||||
ServiceRemove(ctx context.Context, serviceID string) error
|
||||
ServiceUpdate(ctx context.Context, serviceID string, version swarm.Version, service swarm.ServiceSpec, options ServiceUpdateOptions) (swarm.ServiceUpdateResponse, error)
|
||||
ServiceLogs(ctx context.Context, serviceID string, options container.LogsOptions) (io.ReadCloser, error)
|
||||
|
||||
2
vendor/github.com/moby/moby/client/service_list.go
generated
vendored
2
vendor/github.com/moby/moby/client/service_list.go
generated
vendored
@@ -10,7 +10,7 @@ import (
|
||||
)
|
||||
|
||||
// ServiceList returns the list of services.
|
||||
func (cli *Client) ServiceList(ctx context.Context, options swarm.ServiceListOptions) ([]swarm.Service, error) {
|
||||
func (cli *Client) ServiceList(ctx context.Context, options ServiceListOptions) ([]swarm.Service, error) {
|
||||
query := url.Values{}
|
||||
|
||||
if options.Filters.Len() > 0 {
|
||||
|
||||
12
vendor/github.com/moby/moby/client/swarm_service_list_opts.go
generated
vendored
Normal file
12
vendor/github.com/moby/moby/client/swarm_service_list_opts.go
generated
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
package client
|
||||
|
||||
import "github.com/moby/moby/api/types/filters"
|
||||
|
||||
// ServiceListOptions holds parameters to list services with.
|
||||
type ServiceListOptions struct {
|
||||
Filters filters.Args
|
||||
|
||||
// Status indicates whether the server should include the service task
|
||||
// count of running and desired tasks.
|
||||
Status bool
|
||||
}
|
||||
Reference in New Issue
Block a user