Skip to content

Commit ebef4ef

Browse files
committed
api/types: move ContainerLogsOptions to api/types/container
Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent 9670d93 commit ebef4ef

30 files changed

Lines changed: 101 additions & 91 deletions

api/server/httputils/write_log_stream.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@ import (
77
"net/url"
88
"sort"
99

10-
"github.com/docker/docker/api/types"
1110
"github.com/docker/docker/api/types/backend"
11+
"github.com/docker/docker/api/types/container"
1212
"github.com/docker/docker/pkg/ioutils"
1313
"github.com/docker/docker/pkg/jsonmessage"
1414
"github.com/docker/docker/pkg/stdcopy"
1515
)
1616

1717
// WriteLogStream writes an encoded byte stream of log messages from the
1818
// messages channel, multiplexing them with a stdcopy.Writer if mux is true
19-
func WriteLogStream(_ context.Context, w io.Writer, msgs <-chan *backend.LogMessage, config *types.ContainerLogsOptions, mux bool) {
19+
func WriteLogStream(_ context.Context, w io.Writer, msgs <-chan *backend.LogMessage, config *container.LogsOptions, mux bool) {
2020
wf := ioutils.NewWriteFlusher(w)
2121
defer wf.Close()
2222

api/server/router/container/backend.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ type stateBackend interface {
5050
type monitorBackend interface {
5151
ContainerChanges(ctx context.Context, name string) ([]archive.Change, error)
5252
ContainerInspect(ctx context.Context, name string, size bool, version string) (interface{}, error)
53-
ContainerLogs(ctx context.Context, name string, config *types.ContainerLogsOptions) (msgs <-chan *backend.LogMessage, tty bool, err error)
53+
ContainerLogs(ctx context.Context, name string, config *container.LogsOptions) (msgs <-chan *backend.LogMessage, tty bool, err error)
5454
ContainerStats(ctx context.Context, name string, config *backend.ContainerStatsConfig) error
5555
ContainerTop(name string, psArgs string) (*container.ContainerTopOKBody, error)
5656
Containers(ctx context.Context, config *container.ListOptions) ([]*types.Container, error)

api/server/router/container/container_routes.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ func (s *containerRouter) getContainersLogs(ctx context.Context, w http.Response
142142
}
143143

144144
containerName := vars["name"]
145-
logsConfig := &types.ContainerLogsOptions{
145+
logsConfig := &container.LogsOptions{
146146
Follow: httputils.BoolValue(r, "follow"),
147147
Timestamps: httputils.BoolValue(r, "timestamps"),
148148
Since: r.Form.Get("since"),

api/server/router/swarm/backend.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55

66
"github.com/docker/docker/api/types"
77
"github.com/docker/docker/api/types/backend"
8+
"github.com/docker/docker/api/types/container"
89
"github.com/docker/docker/api/types/swarm"
910
)
1011

@@ -22,7 +23,7 @@ type Backend interface {
2223
CreateService(swarm.ServiceSpec, string, bool) (*swarm.ServiceCreateResponse, error)
2324
UpdateService(string, uint64, swarm.ServiceSpec, types.ServiceUpdateOptions, bool) (*swarm.ServiceUpdateResponse, error)
2425
RemoveService(string) error
25-
ServiceLogs(context.Context, *backend.LogSelector, *types.ContainerLogsOptions) (<-chan *backend.LogMessage, error)
26+
ServiceLogs(context.Context, *backend.LogSelector, *container.LogsOptions) (<-chan *backend.LogMessage, error)
2627
GetNodes(types.NodeListOptions) ([]swarm.Node, error)
2728
GetNode(string) (swarm.Node, error)
2829
UpdateNode(string, uint64, swarm.NodeSpec) error

api/server/router/swarm/helpers.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"github.com/docker/docker/api/server/httputils"
99
basictypes "github.com/docker/docker/api/types"
1010
"github.com/docker/docker/api/types/backend"
11+
"github.com/docker/docker/api/types/container"
1112
"github.com/docker/docker/api/types/swarm"
1213
"github.com/docker/docker/api/types/versions"
1314
)
@@ -25,9 +26,9 @@ func (sr *swarmRouter) swarmLogs(ctx context.Context, w http.ResponseWriter, r *
2526
return fmt.Errorf("Bad parameters: you must choose at least one stream")
2627
}
2728

28-
// there is probably a neater way to manufacture the ContainerLogsOptions
29+
// there is probably a neater way to manufacture the LogsOptions
2930
// struct, probably in the caller, to eliminate the dependency on net/http
30-
logsConfig := &basictypes.ContainerLogsOptions{
31+
logsConfig := &container.LogsOptions{
3132
Follow: httputils.BoolValue(r, "follow"),
3233
Timestamps: httputils.BoolValue(r, "timestamps"),
3334
Since: r.Form.Get("since"),

api/types/client.go

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,6 @@ type ContainerExecInspect struct {
2020
Pid int
2121
}
2222

23-
// ContainerLogsOptions holds parameters to filter logs with.
24-
type ContainerLogsOptions struct {
25-
ShowStdout bool
26-
ShowStderr bool
27-
Since string
28-
Until string
29-
Timestamps bool
30-
Follow bool
31-
Tail string
32-
Details bool
33-
}
34-
3523
// CopyToContainerOptions holds information
3624
// about files to copy into a container
3725
type CopyToContainerOptions struct {

api/types/container/options.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,15 @@ type ListOptions struct {
5353
Limit int
5454
Filters filters.Args
5555
}
56+
57+
// LogsOptions holds parameters to filter logs with.
58+
type LogsOptions struct {
59+
ShowStdout bool
60+
ShowStderr bool
61+
Since string
62+
Until string
63+
Timestamps bool
64+
Follow bool
65+
Tail string
66+
Details bool
67+
}

api/types/types_deprecated.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,11 @@ type ContainerCommitOptions = container.CommitOptions
119119
// Deprecated: use [container.ListOptions].
120120
type ContainerListOptions = container.ListOptions
121121

122+
// ContainerLogsOptions holds parameters to filter logs with.
123+
//
124+
// Deprecated: use [container.LogsOptions].
125+
type ContainerLogsOptions = container.LogsOptions
126+
122127
// ContainerRemoveOptions holds parameters to remove containers.
123128
//
124129
// Deprecated: use [container.RemoveOptions].

client/container_logs.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"net/url"
77
"time"
88

9-
"github.com/docker/docker/api/types"
9+
"github.com/docker/docker/api/types/container"
1010
timetypes "github.com/docker/docker/api/types/time"
1111
"github.com/pkg/errors"
1212
)
@@ -33,7 +33,7 @@ import (
3333
//
3434
// You can use github.com/docker/docker/pkg/stdcopy.StdCopy to demultiplex this
3535
// stream.
36-
func (cli *Client) ContainerLogs(ctx context.Context, container string, options types.ContainerLogsOptions) (io.ReadCloser, error) {
36+
func (cli *Client) ContainerLogs(ctx context.Context, container string, options container.LogsOptions) (io.ReadCloser, error) {
3737
query := url.Values{}
3838
if options.ShowStdout {
3939
query.Set("stdout", "1")

client/container_logs_test.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
"testing"
1313
"time"
1414

15-
"github.com/docker/docker/api/types"
15+
"github.com/docker/docker/api/types/container"
1616
"github.com/docker/docker/errdefs"
1717
"gotest.tools/v3/assert"
1818
is "gotest.tools/v3/assert/cmp"
@@ -22,22 +22,22 @@ func TestContainerLogsNotFoundError(t *testing.T) {
2222
client := &Client{
2323
client: newMockClient(errorMock(http.StatusNotFound, "Not found")),
2424
}
25-
_, err := client.ContainerLogs(context.Background(), "container_id", types.ContainerLogsOptions{})
25+
_, err := client.ContainerLogs(context.Background(), "container_id", container.LogsOptions{})
2626
assert.Check(t, is.ErrorType(err, errdefs.IsNotFound))
2727
}
2828

2929
func TestContainerLogsError(t *testing.T) {
3030
client := &Client{
3131
client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")),
3232
}
33-
_, err := client.ContainerLogs(context.Background(), "container_id", types.ContainerLogsOptions{})
33+
_, err := client.ContainerLogs(context.Background(), "container_id", container.LogsOptions{})
3434
assert.Check(t, is.ErrorType(err, errdefs.IsSystem))
3535

36-
_, err = client.ContainerLogs(context.Background(), "container_id", types.ContainerLogsOptions{
36+
_, err = client.ContainerLogs(context.Background(), "container_id", container.LogsOptions{
3737
Since: "2006-01-02TZ",
3838
})
3939
assert.Check(t, is.ErrorContains(err, `parsing time "2006-01-02TZ"`))
40-
_, err = client.ContainerLogs(context.Background(), "container_id", types.ContainerLogsOptions{
40+
_, err = client.ContainerLogs(context.Background(), "container_id", container.LogsOptions{
4141
Until: "2006-01-02TZ",
4242
})
4343
assert.Check(t, is.ErrorContains(err, `parsing time "2006-01-02TZ"`))
@@ -46,7 +46,7 @@ func TestContainerLogsError(t *testing.T) {
4646
func TestContainerLogs(t *testing.T) {
4747
expectedURL := "/containers/container_id/logs"
4848
cases := []struct {
49-
options types.ContainerLogsOptions
49+
options container.LogsOptions
5050
expectedQueryParams map[string]string
5151
expectedError string
5252
}{
@@ -56,15 +56,15 @@ func TestContainerLogs(t *testing.T) {
5656
},
5757
},
5858
{
59-
options: types.ContainerLogsOptions{
59+
options: container.LogsOptions{
6060
Tail: "any",
6161
},
6262
expectedQueryParams: map[string]string{
6363
"tail": "any",
6464
},
6565
},
6666
{
67-
options: types.ContainerLogsOptions{
67+
options: container.LogsOptions{
6868
ShowStdout: true,
6969
ShowStderr: true,
7070
Timestamps: true,
@@ -81,7 +81,7 @@ func TestContainerLogs(t *testing.T) {
8181
},
8282
},
8383
{
84-
options: types.ContainerLogsOptions{
84+
options: container.LogsOptions{
8585
// timestamp will be passed as is
8686
Since: "1136073600.000000001",
8787
},
@@ -91,7 +91,7 @@ func TestContainerLogs(t *testing.T) {
9191
},
9292
},
9393
{
94-
options: types.ContainerLogsOptions{
94+
options: container.LogsOptions{
9595
// timestamp will be passed as is
9696
Until: "1136073600.000000001",
9797
},
@@ -101,14 +101,14 @@ func TestContainerLogs(t *testing.T) {
101101
},
102102
},
103103
{
104-
options: types.ContainerLogsOptions{
104+
options: container.LogsOptions{
105105
// An complete invalid date will not be passed
106106
Since: "invalid value",
107107
},
108108
expectedError: `invalid value for "since": failed to parse value as time or duration: "invalid value"`,
109109
},
110110
{
111-
options: types.ContainerLogsOptions{
111+
options: container.LogsOptions{
112112
// An complete invalid date will not be passed
113113
Until: "invalid value",
114114
},
@@ -153,7 +153,7 @@ func ExampleClient_ContainerLogs_withTimeout() {
153153
defer cancel()
154154

155155
client, _ := NewClientWithOpts(FromEnv)
156-
reader, err := client.ContainerLogs(ctx, "container_id", types.ContainerLogsOptions{})
156+
reader, err := client.ContainerLogs(ctx, "container_id", container.LogsOptions{})
157157
if err != nil {
158158
log.Fatal(err)
159159
}

0 commit comments

Comments
 (0)