Merge pull request #32284 from aaronlehmann/fix-service-defaults

Improve default handling for "service create"
This commit is contained in:
Sebastiaan van Stijn 2017-04-11 13:06:53 +02:00 committed by GitHub
commit f3eacf2983
3 changed files with 12 additions and 6 deletions

View File

@ -123,7 +123,7 @@ type PluginAPIClient interface {
// ServiceAPIClient defines API client methods for the services // ServiceAPIClient defines API client methods for the services
type ServiceAPIClient interface { type ServiceAPIClient interface {
ServiceCreate(ctx context.Context, service swarm.ServiceSpec, options types.ServiceCreateOptions) (types.ServiceCreateResponse, error) ServiceCreate(ctx context.Context, service swarm.ServiceSpec, options types.ServiceCreateOptions) (types.ServiceCreateResponse, error)
ServiceInspectWithRaw(ctx context.Context, serviceID string) (swarm.Service, []byte, error) ServiceInspectWithRaw(ctx context.Context, serviceID string, options types.ServiceInspectOptions) (swarm.Service, []byte, error)
ServiceList(ctx context.Context, options types.ServiceListOptions) ([]swarm.Service, error) ServiceList(ctx context.Context, options types.ServiceListOptions) ([]swarm.Service, error)
ServiceRemove(ctx context.Context, serviceID string) error ServiceRemove(ctx context.Context, serviceID string) error
ServiceUpdate(ctx context.Context, serviceID string, version swarm.Version, service swarm.ServiceSpec, options types.ServiceUpdateOptions) (types.ServiceUpdateResponse, error) ServiceUpdate(ctx context.Context, serviceID string, version swarm.Version, service swarm.ServiceSpec, options types.ServiceUpdateOptions) (types.ServiceUpdateResponse, error)

View File

@ -3,16 +3,21 @@ package client
import ( import (
"bytes" "bytes"
"encoding/json" "encoding/json"
"fmt"
"io/ioutil" "io/ioutil"
"net/http" "net/http"
"net/url"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/swarm" "github.com/docker/docker/api/types/swarm"
"golang.org/x/net/context" "golang.org/x/net/context"
) )
// ServiceInspectWithRaw returns the service information and the raw data. // ServiceInspectWithRaw returns the service information and the raw data.
func (cli *Client) ServiceInspectWithRaw(ctx context.Context, serviceID string) (swarm.Service, []byte, error) { func (cli *Client) ServiceInspectWithRaw(ctx context.Context, serviceID string, opts types.ServiceInspectOptions) (swarm.Service, []byte, error) {
serverResp, err := cli.get(ctx, "/services/"+serviceID, nil, nil) query := url.Values{}
query.Set("insertDefaults", fmt.Sprintf("%v", opts.InsertDefaults))
serverResp, err := cli.get(ctx, "/services/"+serviceID, query, nil)
if err != nil { if err != nil {
if serverResp.statusCode == http.StatusNotFound { if serverResp.statusCode == http.StatusNotFound {
return swarm.Service{}, nil, serviceNotFoundError{serviceID} return swarm.Service{}, nil, serviceNotFoundError{serviceID}

View File

@ -9,6 +9,7 @@ import (
"strings" "strings"
"testing" "testing"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/swarm" "github.com/docker/docker/api/types/swarm"
"golang.org/x/net/context" "golang.org/x/net/context"
) )
@ -18,7 +19,7 @@ func TestServiceInspectError(t *testing.T) {
client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")),
} }
_, _, err := client.ServiceInspectWithRaw(context.Background(), "nothing") _, _, err := client.ServiceInspectWithRaw(context.Background(), "nothing", types.ServiceInspectOptions{})
if err == nil || err.Error() != "Error response from daemon: Server error" { if err == nil || err.Error() != "Error response from daemon: Server error" {
t.Fatalf("expected a Server Error, got %v", err) t.Fatalf("expected a Server Error, got %v", err)
} }
@ -29,7 +30,7 @@ func TestServiceInspectServiceNotFound(t *testing.T) {
client: newMockClient(errorMock(http.StatusNotFound, "Server error")), client: newMockClient(errorMock(http.StatusNotFound, "Server error")),
} }
_, _, err := client.ServiceInspectWithRaw(context.Background(), "unknown") _, _, err := client.ServiceInspectWithRaw(context.Background(), "unknown", types.ServiceInspectOptions{})
if err == nil || !IsErrServiceNotFound(err) { if err == nil || !IsErrServiceNotFound(err) {
t.Fatalf("expected a serviceNotFoundError error, got %v", err) t.Fatalf("expected a serviceNotFoundError error, got %v", err)
} }
@ -55,7 +56,7 @@ func TestServiceInspect(t *testing.T) {
}), }),
} }
serviceInspect, _, err := client.ServiceInspectWithRaw(context.Background(), "service_id") serviceInspect, _, err := client.ServiceInspectWithRaw(context.Background(), "service_id", types.ServiceInspectOptions{})
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }