Skip to content

Commit 9818ee0

Browse files
committed
vendor latest
Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent a71cb31 commit 9818ee0

File tree

112 files changed

+459
-1023
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

112 files changed

+459
-1023
lines changed

cli/command/completion/functions_test.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88

99
"github.com/google/go-cmp/cmp/cmpopts"
1010
"github.com/moby/moby/api/types/container"
11-
"github.com/moby/moby/api/types/filters"
1211
"github.com/moby/moby/api/types/image"
1312
"github.com/moby/moby/api/types/network"
1413
"github.com/moby/moby/api/types/volume"
@@ -33,7 +32,7 @@ type fakeClient struct {
3332
containerListFunc func(options client.ContainerListOptions) ([]container.Summary, error)
3433
imageListFunc func(options client.ImageListOptions) ([]image.Summary, error)
3534
networkListFunc func(ctx context.Context, options client.NetworkListOptions) ([]network.Summary, error)
36-
volumeListFunc func(filter filters.Args) (volume.ListResponse, error)
35+
volumeListFunc func(filter client.Filters) (volume.ListResponse, error)
3736
}
3837

3938
func (c *fakeClient) ContainerList(_ context.Context, options client.ContainerListOptions) ([]container.Summary, error) {
@@ -156,7 +155,7 @@ func TestCompleteContainerNames(t *testing.T) {
156155
}
157156
comp := ContainerNames(fakeCLI{&fakeClient{
158157
containerListFunc: func(opts client.ContainerListOptions) ([]container.Summary, error) {
159-
assert.Check(t, is.DeepEqual(opts, tc.expOpts, cmpopts.IgnoreUnexported(client.ContainerListOptions{}, filters.Args{})))
158+
assert.Check(t, is.DeepEqual(opts, tc.expOpts, cmpopts.IgnoreUnexported(client.ContainerListOptions{})))
160159
if tc.expDirective == cobra.ShellCompDirectiveError {
161160
return nil, errors.New("some error occurred")
162161
}
@@ -339,7 +338,7 @@ func TestCompleteVolumeNames(t *testing.T) {
339338
for _, tc := range tests {
340339
t.Run(tc.doc, func(t *testing.T) {
341340
comp := VolumeNames(fakeCLI{&fakeClient{
342-
volumeListFunc: func(filter filters.Args) (volume.ListResponse, error) {
341+
volumeListFunc: func(filter client.Filters) (volume.ListResponse, error) {
343342
if tc.expDirective == cobra.ShellCompDirectiveError {
344343
return volume.ListResponse{}, errors.New("some error occurred")
345344
}

cli/command/config/ls_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import (
1313
"github.com/moby/moby/api/types/swarm"
1414
"github.com/moby/moby/client"
1515
"gotest.tools/v3/assert"
16-
is "gotest.tools/v3/assert/cmp"
1716
"gotest.tools/v3/golden"
1817
)
1918

@@ -133,8 +132,8 @@ func TestConfigListWithFormat(t *testing.T) {
133132
func TestConfigListWithFilter(t *testing.T) {
134133
cli := test.NewFakeCli(&fakeClient{
135134
configListFunc: func(_ context.Context, options client.ConfigListOptions) ([]swarm.Config, error) {
136-
assert.Check(t, is.Equal("foo", options.Filters.Get("name")[0]))
137-
assert.Check(t, is.Equal("lbl1=Label-bar", options.Filters.Get("label")[0]))
135+
assert.Check(t, options.Filters["name"]["foo"])
136+
assert.Check(t, options.Filters["label"]["lbl1=Label-bar"])
138137
return []swarm.Config{
139138
*builders.Config(builders.ConfigID("ID-foo"),
140139
builders.ConfigName("foo"),

cli/command/container/client_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"io"
66

77
"github.com/moby/moby/api/types/container"
8-
"github.com/moby/moby/api/types/filters"
98
"github.com/moby/moby/api/types/network"
109
"github.com/moby/moby/api/types/system"
1110
"github.com/moby/moby/client"
@@ -36,7 +35,7 @@ type fakeClient struct {
3635
containerRestartFunc func(ctx context.Context, containerID string, options client.ContainerStopOptions) error
3736
containerStopFunc func(ctx context.Context, containerID string, options client.ContainerStopOptions) error
3837
containerKillFunc func(ctx context.Context, containerID, signal string) error
39-
containerPruneFunc func(ctx context.Context, pruneFilters filters.Args) (container.PruneReport, error)
38+
containerPruneFunc func(ctx context.Context, pruneFilters client.Filters) (container.PruneReport, error)
4039
containerAttachFunc func(ctx context.Context, containerID string, options client.ContainerAttachOptions) (client.HijackedResponse, error)
4140
containerDiffFunc func(ctx context.Context, containerID string) ([]container.FilesystemChange, error)
4241
containerRenameFunc func(ctx context.Context, oldName, newName string) error
@@ -172,7 +171,7 @@ func (f *fakeClient) ContainerKill(ctx context.Context, containerID, signal stri
172171
return nil
173172
}
174173

175-
func (f *fakeClient) ContainersPrune(ctx context.Context, pruneFilters filters.Args) (container.PruneReport, error) {
174+
func (f *fakeClient) ContainersPrune(ctx context.Context, pruneFilters client.Filters) (container.PruneReport, error) {
176175
if f.containerPruneFunc != nil {
177176
return f.containerPruneFunc(ctx, pruneFilters)
178177
}

cli/command/container/list_test.go

Lines changed: 21 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func TestContainerListBuildContainerListOptions(t *testing.T) {
2626
expectedAll bool
2727
expectedSize bool
2828
expectedLimit int
29-
expectedFilters map[string]string
29+
expectedFilters client.Filters
3030
}{
3131
{
3232
psOpts: &psOptions{
@@ -35,13 +35,10 @@ func TestContainerListBuildContainerListOptions(t *testing.T) {
3535
last: 5,
3636
filter: filters,
3737
},
38-
expectedAll: true,
39-
expectedSize: true,
40-
expectedLimit: 5,
41-
expectedFilters: map[string]string{
42-
"foo": "bar",
43-
"baz": "foo",
44-
},
38+
expectedAll: true,
39+
expectedSize: true,
40+
expectedLimit: 5,
41+
expectedFilters: make(client.Filters).Add("foo", "bar").Add("baz", "foo"),
4542
},
4643
{
4744
psOpts: &psOptions{
@@ -50,10 +47,9 @@ func TestContainerListBuildContainerListOptions(t *testing.T) {
5047
last: -1,
5148
nLatest: true,
5249
},
53-
expectedAll: true,
54-
expectedSize: true,
55-
expectedLimit: 1,
56-
expectedFilters: make(map[string]string),
50+
expectedAll: true,
51+
expectedSize: true,
52+
expectedLimit: 1,
5753
},
5854
{
5955
psOpts: &psOptions{
@@ -64,13 +60,10 @@ func TestContainerListBuildContainerListOptions(t *testing.T) {
6460
// With .Size, size should be true
6561
format: "{{.Size}}",
6662
},
67-
expectedAll: true,
68-
expectedSize: true,
69-
expectedLimit: 5,
70-
expectedFilters: map[string]string{
71-
"foo": "bar",
72-
"baz": "foo",
73-
},
63+
expectedAll: true,
64+
expectedSize: true,
65+
expectedLimit: 5,
66+
expectedFilters: make(client.Filters).Add("foo", "bar").Add("baz", "foo"),
7467
},
7568
{
7669
psOpts: &psOptions{
@@ -81,13 +74,10 @@ func TestContainerListBuildContainerListOptions(t *testing.T) {
8174
// With .Size, size should be true
8275
format: "{{.Size}} {{.CreatedAt}} {{upper .Networks}}",
8376
},
84-
expectedAll: true,
85-
expectedSize: true,
86-
expectedLimit: 5,
87-
expectedFilters: map[string]string{
88-
"foo": "bar",
89-
"baz": "foo",
90-
},
77+
expectedAll: true,
78+
expectedSize: true,
79+
expectedLimit: 5,
80+
expectedFilters: make(client.Filters).Add("foo", "bar").Add("baz", "foo"),
9181
},
9282
{
9383
psOpts: &psOptions{
@@ -98,13 +88,10 @@ func TestContainerListBuildContainerListOptions(t *testing.T) {
9888
// Without .Size, size should be false
9989
format: "{{.CreatedAt}} {{.Networks}}",
10090
},
101-
expectedAll: true,
102-
expectedSize: false,
103-
expectedLimit: 5,
104-
expectedFilters: map[string]string{
105-
"foo": "bar",
106-
"baz": "foo",
107-
},
91+
expectedAll: true,
92+
expectedSize: false,
93+
expectedLimit: 5,
94+
expectedFilters: make(client.Filters).Add("foo", "bar").Add("baz", "foo"),
10895
},
10996
}
11097

@@ -115,14 +102,7 @@ func TestContainerListBuildContainerListOptions(t *testing.T) {
115102
assert.Check(t, is.Equal(c.expectedAll, options.All))
116103
assert.Check(t, is.Equal(c.expectedSize, options.Size))
117104
assert.Check(t, is.Equal(c.expectedLimit, options.Limit))
118-
assert.Check(t, is.Equal(len(c.expectedFilters), options.Filters.Len()))
119-
120-
for k, v := range c.expectedFilters {
121-
f := options.Filters
122-
if !f.ExactMatch(k, v) {
123-
t.Fatalf("Expected filter with key %s to be %s but got %s", k, v, f.Get(k))
124-
}
125-
}
105+
assert.Check(t, is.DeepEqual(c.expectedFilters, options.Filters))
126106
}
127107
}
128108

cli/command/container/prune_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ import (
88

99
"github.com/docker/cli/internal/test"
1010
"github.com/moby/moby/api/types/container"
11-
"github.com/moby/moby/api/types/filters"
11+
"github.com/moby/moby/client"
1212
)
1313

1414
func TestContainerPrunePromptTermination(t *testing.T) {
1515
ctx, cancel := context.WithCancel(context.Background())
1616
t.Cleanup(cancel)
1717

1818
cli := test.NewFakeCli(&fakeClient{
19-
containerPruneFunc: func(ctx context.Context, pruneFilters filters.Args) (container.PruneReport, error) {
19+
containerPruneFunc: func(ctx context.Context, pruneFilters client.Filters) (container.PruneReport, error) {
2020
return container.PruneReport{}, errors.New("fakeClient containerPruneFunc should not be called")
2121
},
2222
})

cli/command/container/stats.go

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// FIXME(thaJeztah): remove once we are a module; the go:build directive prevents go from downgrading language version to go1.16:
2+
//go:build go1.23
3+
14
package container
25

36
import (
@@ -6,17 +9,18 @@ import (
69
"errors"
710
"fmt"
811
"io"
12+
"maps"
913
"strings"
1014
"sync"
1115
"time"
1216

17+
"github.com/containerd/errdefs"
1318
"github.com/docker/cli/cli"
1419
"github.com/docker/cli/cli/command"
1520
"github.com/docker/cli/cli/command/completion"
1621
"github.com/docker/cli/cli/command/formatter"
1722
flagsHelper "github.com/docker/cli/cli/flags"
1823
"github.com/moby/moby/api/types/events"
19-
"github.com/moby/moby/api/types/filters"
2024
"github.com/moby/moby/client"
2125
"github.com/sirupsen/logrus"
2226
"github.com/spf13/cobra"
@@ -60,7 +64,7 @@ type StatsOptions struct {
6064
// filter options may be added in future (within the constraints described
6165
// above), but may require daemon-side validation as the list of accepted
6266
// filters can differ between daemon- and API versions.
63-
Filters *filters.Args
67+
Filters client.Filters
6468
}
6569

6670
// newStatsCommand creates a new [cobra.Command] for "docker container stats".
@@ -123,12 +127,14 @@ func RunStats(ctx context.Context, dockerCLI command.Cli, options *StatsOptions)
123127
started := make(chan struct{})
124128

125129
if options.Filters == nil {
126-
f := filters.NewArgs()
127-
options.Filters = &f
130+
options.Filters = make(client.Filters)
128131
}
129132

130-
if err := options.Filters.Validate(acceptedStatsFilters); err != nil {
131-
return err
133+
// FIXME(thaJeztah): any way we can (and should?) validate allowed filters?
134+
for filter := range options.Filters {
135+
if _, ok := acceptedStatsFilters[filter]; !ok {
136+
return errdefs.ErrInvalidArgument.WithMessage("invalid filter '" + filter + "'")
137+
}
132138
}
133139

134140
eh := newEventHandler()
@@ -163,7 +169,7 @@ func RunStats(ctx context.Context, dockerCLI command.Cli, options *StatsOptions)
163169
// the original set of filters. Custom filters are used both
164170
// to list containers and to filter events, but the "type" filter
165171
// is not valid for filtering containers.
166-
f := options.Filters.Clone()
172+
f := maps.Clone(options.Filters) // FIXME(thaJeztah): is this correct?
167173
f.Add("type", string(events.ContainerEventType))
168174
eventChan, errChan := apiClient.Events(ctx, client.EventsListOptions{
169175
Filters: f,
@@ -199,7 +205,7 @@ func RunStats(ctx context.Context, dockerCLI command.Cli, options *StatsOptions)
199205
// to refresh the list of containers.
200206
cs, err := apiClient.ContainerList(ctx, client.ContainerListOptions{
201207
All: options.All,
202-
Filters: *options.Filters,
208+
Filters: options.Filters,
203209
})
204210
if err != nil {
205211
return err
@@ -219,7 +225,7 @@ func RunStats(ctx context.Context, dockerCLI command.Cli, options *StatsOptions)
219225
// only a single code-path is needed, and custom filters can be combined
220226
// with a list of container names/IDs.
221227

222-
if options.Filters != nil && options.Filters.Len() > 0 {
228+
if len(options.Filters) > 0 {
223229
return errors.New("filtering is not supported when specifying a list of containers")
224230
}
225231

cli/command/image/client_test.go

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

9-
"github.com/moby/moby/api/types/filters"
109
"github.com/moby/moby/api/types/image"
1110
"github.com/moby/moby/api/types/system"
1211
"github.com/moby/moby/client"
@@ -19,8 +18,8 @@ type fakeClient struct {
1918
imageRemoveFunc func(image string, options client.ImageRemoveOptions) ([]image.DeleteResponse, error)
2019
imagePushFunc func(ref string, options client.ImagePushOptions) (io.ReadCloser, error)
2120
infoFunc func() (system.Info, error)
22-
imagePullFunc func(ref string, options client.ImagePullOptions) (io.ReadCloser, error)
23-
imagesPruneFunc func(pruneFilter filters.Args) (image.PruneReport, error)
21+
imagePullFunc func(ref string, options client.ImagePullOptions) (client.ImagePullResponse, error)
22+
imagesPruneFunc func(pruneFilter client.Filters) (image.PruneReport, error)
2423
imageLoadFunc func(input io.Reader, options ...client.ImageLoadOption) (client.LoadResponse, error)
2524
imageListFunc func(options client.ImageListOptions) ([]image.Summary, error)
2625
imageInspectFunc func(img string) (image.InspectResponse, error)
@@ -66,14 +65,14 @@ func (cli *fakeClient) Info(_ context.Context) (system.Info, error) {
6665
return system.Info{}, nil
6766
}
6867

69-
func (cli *fakeClient) ImagePull(_ context.Context, ref string, options client.ImagePullOptions) (io.ReadCloser, error) {
68+
func (cli *fakeClient) ImagePull(_ context.Context, ref string, options client.ImagePullOptions) (client.ImagePullResponse, error) {
7069
if cli.imagePullFunc != nil {
7170
return cli.imagePullFunc(ref, options)
7271
}
73-
return io.NopCloser(strings.NewReader("")), nil
72+
return client.ImagePullResponse{}, nil
7473
}
7574

76-
func (cli *fakeClient) ImagesPrune(_ context.Context, pruneFilter filters.Args) (image.PruneReport, error) {
75+
func (cli *fakeClient) ImagesPrune(_ context.Context, pruneFilter client.Filters) (image.PruneReport, error) {
7776
if cli.imagesPruneFunc != nil {
7877
return cli.imagesPruneFunc(pruneFilter)
7978
}

cli/command/image/list_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
"github.com/moby/moby/api/types/image"
1212
"github.com/moby/moby/client"
1313
"gotest.tools/v3/assert"
14-
is "gotest.tools/v3/assert/cmp"
1514
"gotest.tools/v3/golden"
1615
)
1716

@@ -69,15 +68,15 @@ func TestNewImagesCommandSuccess(t *testing.T) {
6968
name: "match-name",
7069
args: []string{"image"},
7170
imageListFunc: func(options client.ImageListOptions) ([]image.Summary, error) {
72-
assert.Check(t, is.Equal("image", options.Filters.Get("reference")[0]))
71+
assert.Check(t, options.Filters["reference"]["image"])
7372
return []image.Summary{}, nil
7473
},
7574
},
7675
{
7776
name: "filters",
7877
args: []string{"--filter", "name=value"},
7978
imageListFunc: func(options client.ImageListOptions) ([]image.Summary, error) {
80-
assert.Check(t, is.Equal("value", options.Filters.Get("name")[0]))
79+
assert.Check(t, options.Filters["name"]["value"])
8180
return []image.Summary{}, nil
8281
},
8382
},

cli/command/image/prune.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1+
// FIXME(thaJeztah): remove once we are a module; the go:build directive prevents go from downgrading language version to go1.16:
2+
//go:build go1.23
3+
14
package image
25

36
import (
47
"context"
58
"errors"
69
"fmt"
10+
"maps"
711
"strconv"
812
"strings"
913

@@ -69,7 +73,7 @@ Are you sure you want to continue?`
6973
)
7074

7175
func runPrune(ctx context.Context, dockerCli command.Cli, options pruneOptions) (spaceReclaimed uint64, output string, err error) {
72-
pruneFilters := options.filter.Value().Clone()
76+
pruneFilters := maps.Clone(options.filter.Value())
7377
pruneFilters.Add("dangling", strconv.FormatBool(!options.all))
7478
pruneFilters = command.PruneFilters(dockerCli, pruneFilters)
7579

0 commit comments

Comments
 (0)