api/types: replace uses of deprecated types.Volume with volume.Volume

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2022-03-18 16:33:43 +01:00
parent 54386f0c8f
commit 176f66df9c
No known key found for this signature in database
GPG Key ID: 76698F39D527CE8C
16 changed files with 74 additions and 70 deletions

View File

@ -7,14 +7,15 @@ import (
// TODO return types need to be refactored into pkg
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/filters"
"github.com/docker/docker/api/types/volume"
)
// Backend is the methods that need to be implemented to provide
// volume specific functionality
type Backend interface {
List(ctx context.Context, filter filters.Args) ([]*types.Volume, []string, error)
Get(ctx context.Context, name string, opts ...opts.GetOption) (*types.Volume, error)
Create(ctx context.Context, name, driverName string, opts ...opts.CreateOption) (*types.Volume, error)
List(ctx context.Context, filter filters.Args) ([]*volume.Volume, []string, error)
Get(ctx context.Context, name string, opts ...opts.GetOption) (*volume.Volume, error)
Create(ctx context.Context, name, driverName string, opts ...opts.CreateOption) (*volume.Volume, error)
Remove(ctx context.Context, name string, opts ...opts.RemoveOption) error
Prune(ctx context.Context, pruneFilters filters.Args) (*types.VolumesPruneReport, error)
}

View File

@ -14,6 +14,7 @@ import (
"github.com/docker/docker/api/types/network"
"github.com/docker/docker/api/types/registry"
"github.com/docker/docker/api/types/swarm"
"github.com/docker/docker/api/types/volume"
"github.com/docker/go-connections/nat"
)
@ -686,7 +687,7 @@ type DiskUsage struct {
LayersSize int64
Images []*ImageSummary
Containers []*Container
Volumes []*Volume
Volumes []*volume.Volume
BuildCache []*BuildCache
BuilderSize int64 `json:",omitempty"` // Deprecated: deprecated in API 1.38, and no longer used since API 1.40.
}

View File

@ -173,9 +173,9 @@ type SystemAPIClient interface {
// VolumeAPIClient defines API client methods for the volumes
type VolumeAPIClient interface {
VolumeCreate(ctx context.Context, options volume.VolumeCreateBody) (types.Volume, error)
VolumeInspect(ctx context.Context, volumeID string) (types.Volume, error)
VolumeInspectWithRaw(ctx context.Context, volumeID string) (types.Volume, []byte, error)
VolumeCreate(ctx context.Context, options volume.VolumeCreateBody) (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, filter filters.Args) (volume.VolumeListOKBody, error)
VolumeRemove(ctx context.Context, volumeID string, force bool) error
VolumesPrune(ctx context.Context, pruneFilter filters.Args) (types.VolumesPruneReport, error)

View File

@ -4,18 +4,17 @@ import (
"context"
"encoding/json"
"github.com/docker/docker/api/types"
volumetypes "github.com/docker/docker/api/types/volume"
"github.com/docker/docker/api/types/volume"
)
// VolumeCreate creates a volume in the docker host.
func (cli *Client) VolumeCreate(ctx context.Context, options volumetypes.VolumeCreateBody) (types.Volume, error) {
var volume types.Volume
func (cli *Client) VolumeCreate(ctx context.Context, options volume.VolumeCreateBody) (volume.Volume, error) {
var vol volume.Volume
resp, err := cli.post(ctx, "/volumes/create", nil, options, nil)
defer ensureReaderClosed(resp)
if err != nil {
return volume, err
return vol, err
}
err = json.NewDecoder(resp.body).Decode(&volume)
return volume, err
err = json.NewDecoder(resp.body).Decode(&vol)
return vol, err
}

View File

@ -10,8 +10,7 @@ import (
"strings"
"testing"
"github.com/docker/docker/api/types"
volumetypes "github.com/docker/docker/api/types/volume"
"github.com/docker/docker/api/types/volume"
"github.com/docker/docker/errdefs"
)
@ -20,7 +19,7 @@ func TestVolumeCreateError(t *testing.T) {
client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")),
}
_, err := client.VolumeCreate(context.Background(), volumetypes.VolumeCreateBody{})
_, err := client.VolumeCreate(context.Background(), volume.VolumeCreateBody{})
if !errdefs.IsSystem(err) {
t.Fatalf("expected a Server Error, got %[1]T: %[1]v", err)
}
@ -39,7 +38,7 @@ func TestVolumeCreate(t *testing.T) {
return nil, fmt.Errorf("expected POST method, got %s", req.Method)
}
content, err := json.Marshal(types.Volume{
content, err := json.Marshal(volume.Volume{
Name: "volume",
Driver: "local",
Mountpoint: "mountpoint",
@ -54,7 +53,7 @@ func TestVolumeCreate(t *testing.T) {
}),
}
volume, err := client.VolumeCreate(context.Background(), volumetypes.VolumeCreateBody{
vol, err := client.VolumeCreate(context.Background(), volume.VolumeCreateBody{
Name: "myvolume",
Driver: "mydriver",
DriverOpts: map[string]string{
@ -64,13 +63,13 @@ func TestVolumeCreate(t *testing.T) {
if err != nil {
t.Fatal(err)
}
if volume.Name != "volume" {
t.Fatalf("expected volume.Name to be 'volume', got %s", volume.Name)
if vol.Name != "volume" {
t.Fatalf("expected volume.Name to be 'volume', got %s", vol.Name)
}
if volume.Driver != "local" {
t.Fatalf("expected volume.Driver to be 'local', got %s", volume.Driver)
if vol.Driver != "local" {
t.Fatalf("expected volume.Driver to be 'local', got %s", vol.Driver)
}
if volume.Mountpoint != "mountpoint" {
t.Fatalf("expected volume.Mountpoint to be 'mountpoint', got %s", volume.Mountpoint)
if vol.Mountpoint != "mountpoint" {
t.Fatalf("expected volume.Mountpoint to be 'mountpoint', got %s", vol.Mountpoint)
}
}

View File

@ -6,33 +6,33 @@ import (
"encoding/json"
"io"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/volume"
)
// VolumeInspect returns the information about a specific volume in the docker host.
func (cli *Client) VolumeInspect(ctx context.Context, volumeID string) (types.Volume, error) {
volume, _, err := cli.VolumeInspectWithRaw(ctx, volumeID)
return volume, err
func (cli *Client) VolumeInspect(ctx context.Context, volumeID string) (volume.Volume, error) {
vol, _, err := cli.VolumeInspectWithRaw(ctx, volumeID)
return vol, err
}
// VolumeInspectWithRaw returns the information about a specific volume in the docker host and its raw representation
func (cli *Client) VolumeInspectWithRaw(ctx context.Context, volumeID string) (types.Volume, []byte, error) {
func (cli *Client) VolumeInspectWithRaw(ctx context.Context, volumeID string) (volume.Volume, []byte, error) {
if volumeID == "" {
return types.Volume{}, nil, objectNotFoundError{object: "volume", id: volumeID}
return volume.Volume{}, nil, objectNotFoundError{object: "volume", id: volumeID}
}
var volume types.Volume
var vol volume.Volume
resp, err := cli.get(ctx, "/volumes/"+volumeID, nil, nil)
defer ensureReaderClosed(resp)
if err != nil {
return volume, nil, err
return vol, nil, err
}
body, err := io.ReadAll(resp.body)
if err != nil {
return volume, nil, err
return vol, nil, err
}
rdr := bytes.NewReader(body)
err = json.NewDecoder(rdr).Decode(&volume)
return volume, body, err
err = json.NewDecoder(rdr).Decode(&vol)
return vol, body, err
}

View File

@ -10,7 +10,7 @@ import (
"strings"
"testing"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/volume"
"github.com/docker/docker/errdefs"
"github.com/pkg/errors"
"gotest.tools/v3/assert"
@ -51,7 +51,7 @@ func TestVolumeInspectWithEmptyID(t *testing.T) {
func TestVolumeInspect(t *testing.T) {
expectedURL := "/volumes/volume_id"
expected := types.Volume{
expected := volume.Volume{
Name: "name",
Driver: "driver",
Mountpoint: "mountpoint",

View File

@ -10,9 +10,8 @@ import (
"strings"
"testing"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/filters"
volumetypes "github.com/docker/docker/api/types/volume"
"github.com/docker/docker/api/types/volume"
"github.com/docker/docker/errdefs"
)
@ -70,8 +69,8 @@ func TestVolumeList(t *testing.T) {
if actualFilters != listCase.expectedFilters {
return nil, fmt.Errorf("filters not set in URL query properly. Expected '%s', got %s", listCase.expectedFilters, actualFilters)
}
content, err := json.Marshal(volumetypes.VolumeListOKBody{
Volumes: []*types.Volume{
content, err := json.Marshal(volume.VolumeListOKBody{
Volumes: []*volume.Volume{
{
Name: "volume",
Driver: "local",

View File

@ -14,6 +14,7 @@ import (
"github.com/docker/docker/api/types/filters"
"github.com/docker/docker/api/types/network"
swarmtypes "github.com/docker/docker/api/types/swarm"
"github.com/docker/docker/api/types/volume"
containerpkg "github.com/docker/docker/container"
clustertypes "github.com/docker/docker/daemon/cluster/provider"
networkSettings "github.com/docker/docker/daemon/network"
@ -66,7 +67,7 @@ type Backend interface {
// VolumeBackend is used by an executor to perform volume operations
type VolumeBackend interface {
Create(ctx context.Context, name, driverName string, opts ...volumeopts.CreateOption) (*types.Volume, error)
Create(ctx context.Context, name, driverName string, opts ...volumeopts.CreateOption) (*volume.Volume, error)
}
// ImageBackend is used by an executor to perform image operations

View File

@ -6,6 +6,7 @@ import (
"github.com/docker/docker/api/server/router/system"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/volume"
"golang.org/x/sync/errgroup"
)
@ -64,7 +65,7 @@ func (daemon *Daemon) SystemDiskUsage(ctx context.Context, opts system.DiskUsage
})
}
var volumes []*types.Volume
var volumes []*volume.Volume
if opts.Volumes {
eg.Go(func() error {
var err error

View File

@ -8,10 +8,10 @@ import (
"strings"
"time"
"github.com/docker/docker/api/types"
containertypes "github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/mount"
mounttypes "github.com/docker/docker/api/types/mount"
volumetypes "github.com/docker/docker/api/types/volume"
"github.com/docker/docker/container"
"github.com/docker/docker/errdefs"
"github.com/docker/docker/volume"
@ -186,7 +186,7 @@ func (daemon *Daemon) registerMountPoints(container *container.Container, hostCo
}
if mp.Type == mounttypes.TypeVolume {
var v *types.Volume
var v *volumetypes.Volume
if cfg.VolumeOptions != nil {
var driverOpts map[string]string
if cfg.VolumeOptions.DriverConfig != nil {
@ -384,12 +384,12 @@ func (daemon *Daemon) VolumesService() *service.VolumesService {
}
type volumeMounter interface {
Mount(ctx context.Context, v *types.Volume, ref string) (string, error)
Unmount(ctx context.Context, v *types.Volume, ref string) error
Mount(ctx context.Context, v *volumetypes.Volume, ref string) (string, error)
Unmount(ctx context.Context, v *volumetypes.Volume, ref string) error
}
type volumeWrapper struct {
v *types.Volume
v *volumetypes.Volume
s volumeMounter
}

View File

@ -14,6 +14,7 @@ import (
"time"
"github.com/docker/docker/api/types"
volumetypes "github.com/docker/docker/api/types/volume"
"github.com/docker/docker/integration-cli/daemon"
"github.com/docker/docker/pkg/stringid"
testdaemon "github.com/docker/docker/testutil/daemon"
@ -565,7 +566,7 @@ func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverOutOfBandDelete(c *t
out, err = s.d.Cmd("volume", "inspect", "test")
assert.NilError(c, err, out)
var vs []types.Volume
var vs []volumetypes.Volume
err = json.Unmarshal([]byte(out), &vs)
assert.NilError(c, err)
assert.Equal(c, len(vs), 1)

View File

@ -5,6 +5,7 @@ import (
"testing"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/volume"
"github.com/docker/docker/integration/internal/container"
"github.com/docker/docker/testutil/daemon"
"gotest.tools/v3/assert"
@ -37,7 +38,7 @@ func TestDiskUsage(t *testing.T) {
assert.DeepEqual(t, du, types.DiskUsage{
Images: []*types.ImageSummary{},
Containers: []*types.Container{},
Volumes: []*types.Volume{},
Volumes: []*volume.Volume{},
BuildCache: []*types.BuildCache{},
})
return du
@ -64,7 +65,7 @@ func TestDiskUsage(t *testing.T) {
},
},
Containers: []*types.Container{},
Volumes: []*types.Volume{},
Volumes: []*volume.Volume{},
BuildCache: []*types.BuildCache{},
})
return du
@ -107,7 +108,7 @@ func TestDiskUsage(t *testing.T) {
Mounts: du.Containers[0].Mounts, // not relevant for the test
},
},
Volumes: []*types.Volume{},
Volumes: []*volume.Volume{},
BuildCache: []*types.BuildCache{},
})
return du

View File

@ -10,7 +10,7 @@ import (
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/filters"
volumetypes "github.com/docker/docker/api/types/volume"
"github.com/docker/docker/api/types/volume"
"github.com/docker/docker/integration/internal/container"
"github.com/docker/docker/testutil/request"
"github.com/google/go-cmp/cmp/cmpopts"
@ -28,12 +28,12 @@ func TestVolumesCreateAndList(t *testing.T) {
if testEnv.OSType == "windows" {
name = strings.ToLower(name)
}
vol, err := client.VolumeCreate(ctx, volumetypes.VolumeCreateBody{
vol, err := client.VolumeCreate(ctx, volume.VolumeCreateBody{
Name: name,
})
assert.NilError(t, err)
expected := types.Volume{
expected := volume.Volume{
// Ignore timestamp of CreatedAt
CreatedAt: vol.CreatedAt,
Driver: "local",
@ -90,7 +90,7 @@ func TestVolumesInspect(t *testing.T) {
ctx := context.Background()
now := time.Now()
vol, err := client.VolumeCreate(ctx, volumetypes.VolumeCreateBody{})
vol, err := client.VolumeCreate(ctx, volume.VolumeCreateBody{})
assert.NilError(t, err)
inspected, err := client.VolumeInspect(ctx, vol.Name)

View File

@ -4,8 +4,8 @@ import (
"context"
"time"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/filters"
volumetypes "github.com/docker/docker/api/types/volume"
"github.com/docker/docker/pkg/directory"
"github.com/docker/docker/volume"
"github.com/sirupsen/logrus"
@ -28,9 +28,9 @@ type pathCacher interface {
CachedPath() string
}
func (s *VolumesService) volumesToAPI(ctx context.Context, volumes []volume.Volume, opts ...convertOpt) []*types.Volume {
func (s *VolumesService) volumesToAPI(ctx context.Context, volumes []volume.Volume, opts ...convertOpt) []*volumetypes.Volume {
var (
out = make([]*types.Volume, 0, len(volumes))
out = make([]*volumetypes.Volume, 0, len(volumes))
getSize bool
cachedPath bool
)
@ -69,7 +69,7 @@ func (s *VolumesService) volumesToAPI(ctx context.Context, volumes []volume.Volu
logrus.WithError(err).WithField("volume", v.Name()).Warnf("Failed to determine size of volume")
sz = -1
}
apiV.UsageData = &types.VolumeUsageData{Size: sz, RefCount: int64(s.vs.CountReferences(v))}
apiV.UsageData = &volumetypes.VolumeUsageData{Size: sz, RefCount: int64(s.vs.CountReferences(v))}
}
out = append(out, &apiV)
@ -77,9 +77,9 @@ func (s *VolumesService) volumesToAPI(ctx context.Context, volumes []volume.Volu
return out
}
func volumeToAPIType(v volume.Volume) types.Volume {
func volumeToAPIType(v volume.Volume) volumetypes.Volume {
createdAt, _ := v.CreatedAt()
tv := types.Volume{
tv := volumetypes.Volume{
Name: v.Name(),
Driver: v.DriverName(),
CreatedAt: createdAt.Format(time.RFC3339),

View File

@ -7,6 +7,7 @@ import (
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/filters"
volumetypes "github.com/docker/docker/api/types/volume"
"github.com/docker/docker/errdefs"
"github.com/docker/docker/pkg/directory"
"github.com/docker/docker/pkg/idtools"
@ -66,7 +67,7 @@ func (s *VolumesService) GetDriverList() []string {
//
// A good example for a reference ID is a container's ID.
// When whatever is going to reference this volume is removed the caller should defeference the volume by calling `Release`.
func (s *VolumesService) Create(ctx context.Context, name, driverName string, opts ...opts.CreateOption) (*types.Volume, error) {
func (s *VolumesService) Create(ctx context.Context, name, driverName string, opts ...opts.CreateOption) (*volumetypes.Volume, error) {
if name == "" {
name = stringid.GenerateRandomID()
}
@ -80,7 +81,7 @@ func (s *VolumesService) Create(ctx context.Context, name, driverName string, op
}
// Get returns details about a volume
func (s *VolumesService) Get(ctx context.Context, name string, getOpts ...opts.GetOption) (*types.Volume, error) {
func (s *VolumesService) Get(ctx context.Context, name string, getOpts ...opts.GetOption) (*volumetypes.Volume, error) {
v, err := s.vs.Get(ctx, name, getOpts...)
if err != nil {
return nil, err
@ -107,7 +108,7 @@ func (s *VolumesService) Get(ctx context.Context, name string, getOpts ...opts.G
// s.Mount(ctx, vol, mountID)
// s.Unmount(ctx, vol, mountID)
// ```
func (s *VolumesService) Mount(ctx context.Context, vol *types.Volume, ref string) (string, error) {
func (s *VolumesService) Mount(ctx context.Context, vol *volumetypes.Volume, ref string) (string, error) {
v, err := s.vs.Get(ctx, vol.Name, opts.WithGetDriver(vol.Driver))
if err != nil {
if IsNotExist(err) {
@ -124,7 +125,7 @@ func (s *VolumesService) Mount(ctx context.Context, vol *types.Volume, ref strin
// The reference specified here should be the same reference specified during `Mount` and should be
// unique for each mount/unmount pair.
// See `Mount` documentation for an example.
func (s *VolumesService) Unmount(ctx context.Context, vol *types.Volume, ref string) error {
func (s *VolumesService) Unmount(ctx context.Context, vol *volumetypes.Volume, ref string) error {
v, err := s.vs.Get(ctx, vol.Name, opts.WithGetDriver(vol.Driver))
if err != nil {
if IsNotExist(err) {
@ -183,7 +184,7 @@ var acceptedListFilters = map[string]bool{
// Note that this intentionally skips volumes which have mount options. Typically
// volumes with mount options are not really local even if they are using the
// local driver.
func (s *VolumesService) LocalVolumesSize(ctx context.Context) ([]*types.Volume, error) {
func (s *VolumesService) LocalVolumesSize(ctx context.Context) ([]*volumetypes.Volume, error) {
ch := s.usage.DoChan("LocalVolumesSize", func() (interface{}, error) {
ls, _, err := s.vs.Find(ctx, And(ByDriver(volume.DefaultDriverName), CustomFilter(func(v volume.Volume) bool {
dv, ok := v.(volume.DetailedVolume)
@ -201,7 +202,7 @@ func (s *VolumesService) LocalVolumesSize(ctx context.Context) ([]*types.Volume,
if res.Err != nil {
return nil, res.Err
}
return res.Val.([]*types.Volume), nil
return res.Val.([]*volumetypes.Volume), nil
}
}
@ -257,7 +258,7 @@ func (s *VolumesService) Prune(ctx context.Context, filter filters.Args) (*types
// List gets the list of volumes which match the past in filters
// If filters is nil or empty all volumes are returned.
func (s *VolumesService) List(ctx context.Context, filter filters.Args) (volumesOut []*types.Volume, warnings []string, err error) {
func (s *VolumesService) List(ctx context.Context, filter filters.Args) (volumesOut []*volumetypes.Volume, warnings []string, err error) {
by, err := filtersToBy(filter, acceptedListFilters)
if err != nil {
return nil, nil, err