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 <[email protected]>
  • Loading branch information
thaJeztah committed Apr 21, 2022
1 parent 54386f0 commit 176f66d
Show file tree
Hide file tree
Showing 16 changed files with 74 additions and 70 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 @@ -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.
}
Expand Down
6 changes: 3 additions & 3 deletions client/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
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, 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
}
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
3 changes: 2 additions & 1 deletion daemon/disk_usage.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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
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 @@ -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
}

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 @@ -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)
Expand Down
7 changes: 4 additions & 3 deletions integration/system/disk_usage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand All @@ -64,7 +65,7 @@ func TestDiskUsage(t *testing.T) {
},
},
Containers: []*types.Container{},
Volumes: []*types.Volume{},
Volumes: []*volume.Volume{},
BuildCache: []*types.BuildCache{},
})
return du
Expand Down Expand Up @@ -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
Expand Down
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
Loading

0 comments on commit 176f66d

Please sign in to comment.