diff --git a/api/types/volume/options.go b/api/types/volume/prune_report.go similarity index 53% rename from api/types/volume/options.go rename to api/types/volume/prune_report.go index 7237f2db8d..7f501d01a7 100644 --- a/api/types/volume/options.go +++ b/api/types/volume/prune_report.go @@ -1,12 +1,5 @@ package volume -import "github.com/moby/moby/api/types/filters" - -// ListOptions holds parameters to list volumes. -type ListOptions struct { - Filters filters.Args -} - // PruneReport contains the response for Engine API: // POST "/volumes/prune" type PruneReport struct { diff --git a/client/client_interfaces.go b/client/client_interfaces.go index 7a0706d69e..4549aada79 100644 --- a/client/client_interfaces.go +++ b/client/client_interfaces.go @@ -198,7 +198,7 @@ type VolumeAPIClient interface { VolumeCreate(ctx context.Context, options volume.CreateOptions) (volume.Volume, error) VolumeInspect(ctx context.Context, volumeID string) (volume.Volume, error) VolumeInspectWithRaw(ctx context.Context, volumeID string) (volume.Volume, []byte, error) - VolumeList(ctx context.Context, options volume.ListOptions) (volume.ListResponse, error) + VolumeList(ctx context.Context, options VolumeListOptions) (volume.ListResponse, error) VolumeRemove(ctx context.Context, volumeID string, force bool) error VolumesPrune(ctx context.Context, pruneFilter filters.Args) (volume.PruneReport, error) VolumeUpdate(ctx context.Context, volumeID string, version swarm.Version, options volume.UpdateOptions) error diff --git a/client/volume_list.go b/client/volume_list.go index 656dfb05de..8a4d6af7dd 100644 --- a/client/volume_list.go +++ b/client/volume_list.go @@ -11,7 +11,7 @@ import ( ) // VolumeList returns the volumes configured in the docker host. -func (cli *Client) VolumeList(ctx context.Context, options volume.ListOptions) (volume.ListResponse, error) { +func (cli *Client) VolumeList(ctx context.Context, options VolumeListOptions) (volume.ListResponse, error) { query := url.Values{} if options.Filters.Len() > 0 { diff --git a/client/volume_list_opts.go b/client/volume_list_opts.go new file mode 100644 index 0000000000..f59aef94cd --- /dev/null +++ b/client/volume_list_opts.go @@ -0,0 +1,8 @@ +package client + +import "github.com/moby/moby/api/types/filters" + +// VolumeListOptions holds parameters to list volumes. +type VolumeListOptions struct { + Filters filters.Args +} diff --git a/client/volume_list_test.go b/client/volume_list_test.go index 0f1a0d15a2..9849433d1d 100644 --- a/client/volume_list_test.go +++ b/client/volume_list_test.go @@ -22,7 +22,7 @@ func TestVolumeListError(t *testing.T) { client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), } - _, err := client.VolumeList(context.Background(), volume.ListOptions{}) + _, err := client.VolumeList(context.Background(), VolumeListOptions{}) assert.Check(t, is.ErrorType(err, cerrdefs.IsInternal)) } @@ -80,7 +80,7 @@ func TestVolumeList(t *testing.T) { }), } - volumeResponse, err := client.VolumeList(context.Background(), volume.ListOptions{Filters: listCase.filters}) + volumeResponse, err := client.VolumeList(context.Background(), VolumeListOptions{Filters: listCase.filters}) assert.NilError(t, err) assert.Check(t, is.Len(volumeResponse.Volumes, 1)) } diff --git a/daemon/cluster/volumes.go b/daemon/cluster/volumes.go index 72b828ab8d..741b2f5481 100644 --- a/daemon/cluster/volumes.go +++ b/daemon/cluster/volumes.go @@ -7,6 +7,7 @@ import ( cerrdefs "github.com/containerd/errdefs" volumetypes "github.com/moby/moby/api/types/volume" "github.com/moby/moby/v2/daemon/cluster/convert" + "github.com/moby/moby/v2/daemon/server/volumebackend" "github.com/moby/moby/v2/errdefs" swarmapi "github.com/moby/swarmkit/v2/api" "google.golang.org/grpc" @@ -30,7 +31,7 @@ func (c *Cluster) GetVolume(nameOrID string) (volumetypes.Volume, error) { } // GetVolumes returns all of the volumes matching the given options from a swarm cluster. -func (c *Cluster) GetVolumes(options volumetypes.ListOptions) ([]*volumetypes.Volume, error) { +func (c *Cluster) GetVolumes(options volumebackend.ListOptions) ([]*volumetypes.Volume, error) { var volumes []*volumetypes.Volume if err := c.lockedManagerAction(func(ctx context.Context, state nodeState) error { r, err := state.controlClient.ListVolumes( diff --git a/daemon/server/router/volume/backend.go b/daemon/server/router/volume/backend.go index 369953d4c7..24a282c3ec 100644 --- a/daemon/server/router/volume/backend.go +++ b/daemon/server/router/volume/backend.go @@ -5,6 +5,7 @@ import ( "github.com/moby/moby/api/types/filters" "github.com/moby/moby/api/types/volume" + "github.com/moby/moby/v2/daemon/server/volumebackend" "github.com/moby/moby/v2/daemon/volume/service/opts" ) @@ -24,7 +25,7 @@ type Backend interface { // backends here. type ClusterBackend interface { GetVolume(nameOrID string) (volume.Volume, error) - GetVolumes(options volume.ListOptions) ([]*volume.Volume, error) + GetVolumes(options volumebackend.ListOptions) ([]*volume.Volume, error) CreateVolume(volume volume.CreateOptions) (*volume.Volume, error) RemoveVolume(nameOrID string, force bool) error UpdateVolume(nameOrID string, version uint64, volume volume.UpdateOptions) error diff --git a/daemon/server/router/volume/volume_routes.go b/daemon/server/router/volume/volume_routes.go index e7d6aa88cd..ffcf8fedcb 100644 --- a/daemon/server/router/volume/volume_routes.go +++ b/daemon/server/router/volume/volume_routes.go @@ -12,6 +12,7 @@ import ( "github.com/moby/moby/api/types/versions" "github.com/moby/moby/api/types/volume" "github.com/moby/moby/v2/daemon/server/httputils" + "github.com/moby/moby/v2/daemon/server/volumebackend" "github.com/moby/moby/v2/daemon/volume/service/opts" "github.com/moby/moby/v2/errdefs" "github.com/pkg/errors" @@ -39,7 +40,7 @@ func (v *volumeRouter) getVolumesList(ctx context.Context, w http.ResponseWriter version := httputils.VersionFromContext(ctx) if versions.GreaterThanOrEqualTo(version, clusterVolumesVersion) && v.cluster.IsManager() { - clusterVolumes, swarmErr := v.cluster.GetVolumes(volume.ListOptions{Filters: f}) + clusterVolumes, swarmErr := v.cluster.GetVolumes(volumebackend.ListOptions{Filters: f}) if swarmErr != nil { // if there is a swarm error, we may not want to error out right // away. the local list probably worked. instead, let's do what we diff --git a/daemon/server/router/volume/volume_routes_test.go b/daemon/server/router/volume/volume_routes_test.go index f6acde9ad8..5d2c69cda2 100644 --- a/daemon/server/router/volume/volume_routes_test.go +++ b/daemon/server/router/volume/volume_routes_test.go @@ -16,6 +16,7 @@ import ( "github.com/moby/moby/api/types/filters" "github.com/moby/moby/api/types/volume" "github.com/moby/moby/v2/daemon/server/httputils" + "github.com/moby/moby/v2/daemon/server/volumebackend" "github.com/moby/moby/v2/daemon/volume/service/opts" "github.com/moby/moby/v2/errdefs" ) @@ -679,7 +680,7 @@ func (c *fakeClusterBackend) GetVolume(nameOrID string) (volume.Volume, error) { return volume.Volume{}, errdefs.NotFound(fmt.Errorf("volume %s not found", nameOrID)) } -func (c *fakeClusterBackend) GetVolumes(_ volume.ListOptions) ([]*volume.Volume, error) { +func (c *fakeClusterBackend) GetVolumes(_ volumebackend.ListOptions) ([]*volume.Volume, error) { if err := c.checkSwarm(); err != nil { return nil, err } diff --git a/daemon/server/volumebackend/volume.go b/daemon/server/volumebackend/volume.go new file mode 100644 index 0000000000..49416f75c1 --- /dev/null +++ b/daemon/server/volumebackend/volume.go @@ -0,0 +1,7 @@ +package volumebackend + +import "github.com/moby/moby/api/types/filters" + +type ListOptions struct { + Filters filters.Args +} diff --git a/integration/plugin/authz/authz_plugin_v2_test.go b/integration/plugin/authz/authz_plugin_v2_test.go index 728d7bc723..e61202a0fc 100644 --- a/integration/plugin/authz/authz_plugin_v2_test.go +++ b/integration/plugin/authz/authz_plugin_v2_test.go @@ -98,7 +98,7 @@ func TestAuthZPluginV2RejectVolumeRequests(t *testing.T) { assert.Assert(t, err != nil) assert.ErrorContains(t, err, fmt.Sprintf("Error response from daemon: plugin %s failed with error:", authzPluginNameWithTag)) - _, err = c.VolumeList(ctx, volume.ListOptions{}) + _, err = c.VolumeList(ctx, client.VolumeListOptions{}) assert.Assert(t, err != nil) assert.ErrorContains(t, err, fmt.Sprintf("Error response from daemon: plugin %s failed with error:", authzPluginNameWithTag)) diff --git a/integration/volume/volume_test.go b/integration/volume/volume_test.go index 6434c9cc0b..bc599c7959 100644 --- a/integration/volume/volume_test.go +++ b/integration/volume/volume_test.go @@ -49,7 +49,7 @@ func TestVolumesCreateAndList(t *testing.T) { } assert.Check(t, is.DeepEqual(vol, expected, cmpopts.EquateEmpty())) - volList, err := apiClient.VolumeList(ctx, volume.ListOptions{}) + volList, err := apiClient.VolumeList(ctx, client.VolumeListOptions{}) assert.NilError(t, err) assert.Assert(t, len(volList.Volumes) > 0) diff --git a/testutil/environment/clean.go b/testutil/environment/clean.go index 8aab58f07c..03df56403d 100644 --- a/testutil/environment/clean.go +++ b/testutil/environment/clean.go @@ -10,7 +10,6 @@ import ( "github.com/moby/moby/api/types/filters" "github.com/moby/moby/api/types/image" "github.com/moby/moby/api/types/network" - "github.com/moby/moby/api/types/volume" "github.com/moby/moby/client" "go.opentelemetry.io/otel" "gotest.tools/v3/assert" @@ -130,7 +129,7 @@ func removeImage(ctx context.Context, t testing.TB, apiclient client.ImageAPICli func deleteAllVolumes(ctx context.Context, t testing.TB, c client.VolumeAPIClient, protectedVolumes map[string]struct{}) { t.Helper() - volumes, err := c.VolumeList(ctx, volume.ListOptions{}) + volumes, err := c.VolumeList(ctx, client.VolumeListOptions{}) assert.Check(t, err, "failed to list volumes") for _, v := range volumes.Volumes { diff --git a/testutil/environment/protect.go b/testutil/environment/protect.go index 5cf0ec6200..6c2a1004c2 100644 --- a/testutil/environment/protect.go +++ b/testutil/environment/protect.go @@ -9,7 +9,7 @@ import ( "github.com/moby/moby/api/types/filters" "github.com/moby/moby/api/types/image" "github.com/moby/moby/api/types/network" - "github.com/moby/moby/api/types/volume" + "github.com/moby/moby/client" "github.com/moby/moby/v2/testutil" "go.opentelemetry.io/otel" "gotest.tools/v3/assert" @@ -230,8 +230,8 @@ func ProtectVolumes(ctx context.Context, t testing.TB, testEnv *Execution) { func getExistingVolumes(ctx context.Context, t testing.TB, testEnv *Execution) []string { t.Helper() - client := testEnv.APIClient() - volumeList, err := client.VolumeList(ctx, volume.ListOptions{}) + apiClient := testEnv.APIClient() + volumeList, err := apiClient.VolumeList(ctx, client.VolumeListOptions{}) assert.NilError(t, err, "failed to list volumes") var volumes []string diff --git a/vendor/github.com/moby/moby/api/types/volume/options.go b/vendor/github.com/moby/moby/api/types/volume/prune_report.go similarity index 53% rename from vendor/github.com/moby/moby/api/types/volume/options.go rename to vendor/github.com/moby/moby/api/types/volume/prune_report.go index 7237f2db8d..7f501d01a7 100644 --- a/vendor/github.com/moby/moby/api/types/volume/options.go +++ b/vendor/github.com/moby/moby/api/types/volume/prune_report.go @@ -1,12 +1,5 @@ package volume -import "github.com/moby/moby/api/types/filters" - -// ListOptions holds parameters to list volumes. -type ListOptions struct { - Filters filters.Args -} - // PruneReport contains the response for Engine API: // POST "/volumes/prune" type PruneReport struct { diff --git a/vendor/github.com/moby/moby/client/client_interfaces.go b/vendor/github.com/moby/moby/client/client_interfaces.go index 7a0706d69e..4549aada79 100644 --- a/vendor/github.com/moby/moby/client/client_interfaces.go +++ b/vendor/github.com/moby/moby/client/client_interfaces.go @@ -198,7 +198,7 @@ type VolumeAPIClient interface { VolumeCreate(ctx context.Context, options volume.CreateOptions) (volume.Volume, error) VolumeInspect(ctx context.Context, volumeID string) (volume.Volume, error) VolumeInspectWithRaw(ctx context.Context, volumeID string) (volume.Volume, []byte, error) - VolumeList(ctx context.Context, options volume.ListOptions) (volume.ListResponse, error) + VolumeList(ctx context.Context, options VolumeListOptions) (volume.ListResponse, error) VolumeRemove(ctx context.Context, volumeID string, force bool) error VolumesPrune(ctx context.Context, pruneFilter filters.Args) (volume.PruneReport, error) VolumeUpdate(ctx context.Context, volumeID string, version swarm.Version, options volume.UpdateOptions) error diff --git a/vendor/github.com/moby/moby/client/volume_list.go b/vendor/github.com/moby/moby/client/volume_list.go index 656dfb05de..8a4d6af7dd 100644 --- a/vendor/github.com/moby/moby/client/volume_list.go +++ b/vendor/github.com/moby/moby/client/volume_list.go @@ -11,7 +11,7 @@ import ( ) // VolumeList returns the volumes configured in the docker host. -func (cli *Client) VolumeList(ctx context.Context, options volume.ListOptions) (volume.ListResponse, error) { +func (cli *Client) VolumeList(ctx context.Context, options VolumeListOptions) (volume.ListResponse, error) { query := url.Values{} if options.Filters.Len() > 0 { diff --git a/vendor/github.com/moby/moby/client/volume_list_opts.go b/vendor/github.com/moby/moby/client/volume_list_opts.go new file mode 100644 index 0000000000..f59aef94cd --- /dev/null +++ b/vendor/github.com/moby/moby/client/volume_list_opts.go @@ -0,0 +1,8 @@ +package client + +import "github.com/moby/moby/api/types/filters" + +// VolumeListOptions holds parameters to list volumes. +type VolumeListOptions struct { + Filters filters.Args +}