mirror of
https://github.com/moby/moby.git
synced 2026-01-11 18:51:37 +00:00
Merge pull request #50789 from austinvazquez/move-volume-list-options-from-api-to-client
api/types/volume: move volume list options from api to client
This commit is contained in:
@@ -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 {
|
||||
@@ -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
|
||||
|
||||
@@ -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 {
|
||||
|
||||
8
client/volume_list_opts.go
Normal file
8
client/volume_list_opts.go
Normal file
@@ -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
|
||||
}
|
||||
@@ -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))
|
||||
}
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
7
daemon/server/volumebackend/volume.go
Normal file
7
daemon/server/volumebackend/volume.go
Normal file
@@ -0,0 +1,7 @@
|
||||
package volumebackend
|
||||
|
||||
import "github.com/moby/moby/api/types/filters"
|
||||
|
||||
type ListOptions struct {
|
||||
Filters filters.Args
|
||||
}
|
||||
@@ -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))
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 {
|
||||
2
vendor/github.com/moby/moby/client/client_interfaces.go
generated
vendored
2
vendor/github.com/moby/moby/client/client_interfaces.go
generated
vendored
@@ -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
|
||||
|
||||
2
vendor/github.com/moby/moby/client/volume_list.go
generated
vendored
2
vendor/github.com/moby/moby/client/volume_list.go
generated
vendored
@@ -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 {
|
||||
|
||||
8
vendor/github.com/moby/moby/client/volume_list_opts.go
generated
vendored
Normal file
8
vendor/github.com/moby/moby/client/volume_list_opts.go
generated
vendored
Normal file
@@ -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
|
||||
}
|
||||
Reference in New Issue
Block a user