Skip to content

Commit

Permalink
api/types: replace uses of deprecated types.Volume with volume.Volume
Browse files Browse the repository at this point in the history
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>

Resolved conflicts:
	client/volume_inspect.go
	daemon/disk_usage.go
	integration/system/disk_usage_test.go
	volume/service/service.go

(cherry picked from commit 176f66d)
Co-authored-by: Bjorn Neergaard <bjorn.neergaard@docker.com>
Signed-off-by: Bjorn Neergaard <bjorn.neergaard@docker.com>
  • Loading branch information
thaJeztah and neersighted committed Jun 27, 2023
1 parent e27c043 commit 7ac6922
Show file tree
Hide file tree
Showing 16 changed files with 68 additions and 65 deletions.
7 changes: 4 additions & 3 deletions api/server/router/volume/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
3 changes: 2 additions & 1 deletion api/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -536,7 +537,7 @@ type DiskUsage struct {
LayersSize int64
Images []*ImageSummary
Containers []*Container
Volumes []*Volume
Volumes []*volume.Volume
BuildCache []*BuildCache
BuilderSize int64 // deprecated
}
Expand Down
6 changes: 3 additions & 3 deletions client/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,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)
Expand Down
13 changes: 6 additions & 7 deletions client/volume_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
21 changes: 10 additions & 11 deletions client/volume_create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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)
}
Expand All @@ -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",
Expand All @@ -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{
Expand All @@ -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)
}
}
22 changes: 11 additions & 11 deletions client/volume_inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, wrapResponseError(err, resp, "volume", volumeID)
return vol, nil, wrapResponseError(err, resp, "volume", volumeID)
}

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
}
4 changes: 2 additions & 2 deletions client/volume_inspect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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",
Expand Down
7 changes: 3 additions & 4 deletions client/volume_list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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",
Expand Down
3 changes: 2 additions & 1 deletion daemon/cluster/executor/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions daemon/disk_usage.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/filters"
"github.com/docker/docker/api/types/volume"
)

// SystemDiskUsage returns information about the daemon data disk usage
Expand Down
10 changes: 5 additions & 5 deletions daemon/volumes.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -385,12 +385,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
}

Expand Down
3 changes: 2 additions & 1 deletion integration-cli/docker_cli_external_volume_driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -564,7 +565,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)
Expand Down
Empty file.
8 changes: 4 additions & 4 deletions integration/volume/volume_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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",
Expand Down Expand Up @@ -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)
Expand Down
12 changes: 6 additions & 6 deletions volume/service/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
)
Expand Down Expand Up @@ -69,17 +69,17 @@ 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)
}
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),
Expand Down
Loading

0 comments on commit 7ac6922

Please sign in to comment.