vendor: github.com/docker/docker cdb3f9fb8dca (v25.0.0-dev)
full diff: d3afa80b96...cdb3f9fb8d
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
@ -13,7 +13,7 @@ import (
|
||||
type fakeClient struct {
|
||||
client.Client
|
||||
serviceInspectWithRawFunc func(ctx context.Context, serviceID string, options types.ServiceInspectOptions) (swarm.Service, []byte, error)
|
||||
serviceUpdateFunc func(ctx context.Context, serviceID string, version swarm.Version, service swarm.ServiceSpec, options types.ServiceUpdateOptions) (types.ServiceUpdateResponse, error)
|
||||
serviceUpdateFunc func(ctx context.Context, serviceID string, version swarm.Version, service swarm.ServiceSpec, options types.ServiceUpdateOptions) (swarm.ServiceUpdateResponse, error)
|
||||
serviceListFunc func(context.Context, types.ServiceListOptions) ([]swarm.Service, error)
|
||||
taskListFunc func(context.Context, types.TaskListOptions) ([]swarm.Task, error)
|
||||
infoFunc func(ctx context.Context) (system.Info, error)
|
||||
@ -51,12 +51,12 @@ func (f *fakeClient) ServiceList(ctx context.Context, options types.ServiceListO
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (f *fakeClient) ServiceUpdate(ctx context.Context, serviceID string, version swarm.Version, service swarm.ServiceSpec, options types.ServiceUpdateOptions) (types.ServiceUpdateResponse, error) {
|
||||
func (f *fakeClient) ServiceUpdate(ctx context.Context, serviceID string, version swarm.Version, service swarm.ServiceSpec, options types.ServiceUpdateOptions) (swarm.ServiceUpdateResponse, error) {
|
||||
if f.serviceUpdateFunc != nil {
|
||||
return f.serviceUpdateFunc(ctx, serviceID, version, service, options)
|
||||
}
|
||||
|
||||
return types.ServiceUpdateResponse{}, nil
|
||||
return swarm.ServiceUpdateResponse{}, nil
|
||||
}
|
||||
|
||||
func (f *fakeClient) Info(ctx context.Context) (system.Info, error) {
|
||||
|
||||
@ -14,6 +14,7 @@ import (
|
||||
"github.com/docker/cli/cli/command/idresolver"
|
||||
"github.com/docker/cli/service/logs"
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/api/types/container"
|
||||
"github.com/docker/docker/api/types/swarm"
|
||||
"github.com/docker/docker/client"
|
||||
"github.com/docker/docker/errdefs"
|
||||
@ -74,19 +75,7 @@ func newLogsCommand(dockerCli command.Cli) *cobra.Command {
|
||||
func runLogs(dockerCli command.Cli, opts *logsOptions) error {
|
||||
ctx := context.Background()
|
||||
|
||||
options := types.ContainerLogsOptions{
|
||||
ShowStdout: true,
|
||||
ShowStderr: true,
|
||||
Since: opts.since,
|
||||
Timestamps: opts.timestamps,
|
||||
Follow: opts.follow,
|
||||
Tail: opts.tail,
|
||||
// get the details if we request it OR if we're not doing raw mode
|
||||
// (we need them for the context to pretty print)
|
||||
Details: opts.details || !opts.raw,
|
||||
}
|
||||
|
||||
cli := dockerCli.Client()
|
||||
apiClient := dockerCli.Client()
|
||||
|
||||
var (
|
||||
maxLength = 1
|
||||
@ -94,16 +83,16 @@ func runLogs(dockerCli command.Cli, opts *logsOptions) error {
|
||||
tty bool
|
||||
// logfunc is used to delay the call to logs so that we can do some
|
||||
// processing before we actually get the logs
|
||||
logfunc func(context.Context, string, types.ContainerLogsOptions) (io.ReadCloser, error)
|
||||
logfunc func(context.Context, string, container.LogsOptions) (io.ReadCloser, error)
|
||||
)
|
||||
|
||||
service, _, err := cli.ServiceInspectWithRaw(ctx, opts.target, types.ServiceInspectOptions{})
|
||||
service, _, err := apiClient.ServiceInspectWithRaw(ctx, opts.target, types.ServiceInspectOptions{})
|
||||
if err != nil {
|
||||
// if it's any error other than service not found, it's Real
|
||||
if !errdefs.IsNotFound(err) {
|
||||
return err
|
||||
}
|
||||
task, _, err := cli.TaskInspectWithRaw(ctx, opts.target)
|
||||
task, _, err := apiClient.TaskInspectWithRaw(ctx, opts.target)
|
||||
if err != nil {
|
||||
if errdefs.IsNotFound(err) {
|
||||
// if the task isn't found, rewrite the error to be clear
|
||||
@ -117,10 +106,10 @@ func runLogs(dockerCli command.Cli, opts *logsOptions) error {
|
||||
maxLength = getMaxLength(task.Slot)
|
||||
|
||||
// use the TaskLogs api function
|
||||
logfunc = cli.TaskLogs
|
||||
logfunc = apiClient.TaskLogs
|
||||
} else {
|
||||
// use ServiceLogs api function
|
||||
logfunc = cli.ServiceLogs
|
||||
logfunc = apiClient.ServiceLogs
|
||||
tty = service.Spec.TaskTemplate.ContainerSpec.TTY
|
||||
if service.Spec.Mode.Replicated != nil && service.Spec.Mode.Replicated.Replicas != nil {
|
||||
// if replicas are initialized, figure out if we need to pad them
|
||||
@ -138,7 +127,17 @@ func runLogs(dockerCli command.Cli, opts *logsOptions) error {
|
||||
}
|
||||
|
||||
// now get the logs
|
||||
responseBody, err = logfunc(ctx, opts.target, options)
|
||||
responseBody, err = logfunc(ctx, opts.target, container.LogsOptions{
|
||||
ShowStdout: true,
|
||||
ShowStderr: true,
|
||||
Since: opts.since,
|
||||
Timestamps: opts.timestamps,
|
||||
Follow: opts.follow,
|
||||
Tail: opts.tail,
|
||||
// get the details if we request it OR if we're not doing raw mode
|
||||
// (we need them for the context to pretty print)
|
||||
Details: opts.details || !opts.raw,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -156,7 +155,7 @@ func runLogs(dockerCli command.Cli, opts *logsOptions) error {
|
||||
stdout = dockerCli.Out()
|
||||
stderr = dockerCli.Err()
|
||||
if !opts.raw {
|
||||
taskFormatter := newTaskFormatter(cli, opts, maxLength)
|
||||
taskFormatter := newTaskFormatter(apiClient, opts, maxLength)
|
||||
|
||||
stdout = &logWriter{ctx: ctx, opts: opts, f: taskFormatter, w: stdout}
|
||||
stderr = &logWriter{ctx: ctx, opts: opts, f: taskFormatter, w: stderr}
|
||||
|
||||
@ -18,7 +18,7 @@ func TestRollback(t *testing.T) {
|
||||
testCases := []struct {
|
||||
name string
|
||||
args []string
|
||||
serviceUpdateFunc func(ctx context.Context, serviceID string, version swarm.Version, service swarm.ServiceSpec, options types.ServiceUpdateOptions) (types.ServiceUpdateResponse, error)
|
||||
serviceUpdateFunc func(ctx context.Context, serviceID string, version swarm.Version, service swarm.ServiceSpec, options types.ServiceUpdateOptions) (swarm.ServiceUpdateResponse, error)
|
||||
expectedDockerCliErr string
|
||||
}{
|
||||
{
|
||||
@ -28,8 +28,8 @@ func TestRollback(t *testing.T) {
|
||||
{
|
||||
name: "rollback-service-with-warnings",
|
||||
args: []string{"service-id"},
|
||||
serviceUpdateFunc: func(ctx context.Context, serviceID string, version swarm.Version, service swarm.ServiceSpec, options types.ServiceUpdateOptions) (types.ServiceUpdateResponse, error) {
|
||||
response := types.ServiceUpdateResponse{}
|
||||
serviceUpdateFunc: func(ctx context.Context, serviceID string, version swarm.Version, service swarm.ServiceSpec, options types.ServiceUpdateOptions) (swarm.ServiceUpdateResponse, error) {
|
||||
response := swarm.ServiceUpdateResponse{}
|
||||
|
||||
response.Warnings = []string{
|
||||
"- warning 1",
|
||||
@ -60,7 +60,7 @@ func TestRollbackWithErrors(t *testing.T) {
|
||||
name string
|
||||
args []string
|
||||
serviceInspectWithRawFunc func(ctx context.Context, serviceID string, options types.ServiceInspectOptions) (swarm.Service, []byte, error)
|
||||
serviceUpdateFunc func(ctx context.Context, serviceID string, version swarm.Version, service swarm.ServiceSpec, options types.ServiceUpdateOptions) (types.ServiceUpdateResponse, error)
|
||||
serviceUpdateFunc func(ctx context.Context, serviceID string, version swarm.Version, service swarm.ServiceSpec, options types.ServiceUpdateOptions) (swarm.ServiceUpdateResponse, error)
|
||||
expectedError string
|
||||
}{
|
||||
{
|
||||
@ -83,8 +83,8 @@ func TestRollbackWithErrors(t *testing.T) {
|
||||
{
|
||||
name: "service-update-failed",
|
||||
args: []string{"service-id"},
|
||||
serviceUpdateFunc: func(ctx context.Context, serviceID string, version swarm.Version, service swarm.ServiceSpec, options types.ServiceUpdateOptions) (types.ServiceUpdateResponse, error) {
|
||||
return types.ServiceUpdateResponse{}, fmt.Errorf("no such services: %s", serviceID)
|
||||
serviceUpdateFunc: func(ctx context.Context, serviceID string, version swarm.Version, service swarm.ServiceSpec, options types.ServiceUpdateOptions) (swarm.ServiceUpdateResponse, error) {
|
||||
return swarm.ServiceUpdateResponse{}, fmt.Errorf("no such services: %s", serviceID)
|
||||
},
|
||||
expectedError: "no such services: service-id",
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user