diff --git a/api/docs/v1.52.yaml b/api/docs/v1.52.yaml index ff16fb7a41..48cbaceebb 100644 --- a/api/docs/v1.52.yaml +++ b/api/docs/v1.52.yaml @@ -2149,6 +2149,7 @@ definitions: Volume: type: "object" required: [Name, Driver, Mountpoint, Labels, Scope, Options] + x-nullable: false properties: Name: type: "string" diff --git a/api/swagger.yaml b/api/swagger.yaml index ff16fb7a41..48cbaceebb 100644 --- a/api/swagger.yaml +++ b/api/swagger.yaml @@ -2149,6 +2149,7 @@ definitions: Volume: type: "object" required: [Name, Driver, Mountpoint, Labels, Scope, Options] + x-nullable: false properties: Name: type: "string" diff --git a/api/types/volume/list_response.go b/api/types/volume/list_response.go index b725b6f121..f257762f09 100644 --- a/api/types/volume/list_response.go +++ b/api/types/volume/list_response.go @@ -13,7 +13,7 @@ package volume type ListResponse struct { // List of volumes - Volumes []*Volume `json:"Volumes"` + Volumes []Volume `json:"Volumes"` // Warnings that occurred when fetching the list of volumes. // diff --git a/client/volume_list.go b/client/volume_list.go index 802f104eaf..989a0292ec 100644 --- a/client/volume_list.go +++ b/client/volume_list.go @@ -4,7 +4,6 @@ import ( "context" "encoding/json" "net/url" - "slices" "github.com/moby/moby/api/types/volume" ) @@ -40,16 +39,8 @@ func (cli *Client) VolumeList(ctx context.Context, options VolumeListOptions) (V return VolumeListResult{}, err } - res := VolumeListResult{ - Items: make([]volume.Volume, 0, len(apiResp.Volumes)), - Warnings: slices.Clone(apiResp.Warnings), - } - - for _, vol := range apiResp.Volumes { - if vol != nil { - res.Items = append(res.Items, *vol) - } - } - - return res, nil + return VolumeListResult{ + Items: apiResp.Volumes, + Warnings: apiResp.Warnings, + }, nil } diff --git a/client/volume_list_test.go b/client/volume_list_test.go index fac43e0b97..c690c51631 100644 --- a/client/volume_list_test.go +++ b/client/volume_list_test.go @@ -1,7 +1,6 @@ package client import ( - "context" "fmt" "net/http" "testing" @@ -16,7 +15,7 @@ func TestVolumeListError(t *testing.T) { client, err := New(WithMockClient(errorMock(http.StatusInternalServerError, "Server error"))) assert.NilError(t, err) - _, err = client.VolumeList(context.Background(), VolumeListOptions{}) + _, err = client.VolumeList(t.Context(), VolumeListOptions{}) assert.Check(t, is.ErrorType(err, cerrdefs.IsInternal)) } @@ -52,7 +51,7 @@ func TestVolumeList(t *testing.T) { return nil, fmt.Errorf("filters not set in URL query properly. Expected '%s', got %s", listCase.expectedFilters, actualFilters) } return mockJSONResponse(http.StatusOK, nil, volume.ListResponse{ - Volumes: []*volume.Volume{ + Volumes: []volume.Volume{ { Name: "volume", Driver: "local", @@ -62,7 +61,7 @@ func TestVolumeList(t *testing.T) { })) assert.NilError(t, err) - result, err := client.VolumeList(context.Background(), VolumeListOptions{Filters: listCase.filters}) + result, err := client.VolumeList(t.Context(), VolumeListOptions{Filters: listCase.filters}) assert.NilError(t, err) assert.Check(t, is.Len(result.Items, 1)) } diff --git a/daemon/cluster/volumes.go b/daemon/cluster/volumes.go index c35bfdebe8..d44e7b1e31 100644 --- a/daemon/cluster/volumes.go +++ b/daemon/cluster/volumes.go @@ -30,9 +30,9 @@ func (c *Cluster) GetVolume(nameOrID string) (volumetypes.Volume, error) { return convert.VolumeFromGRPC(volume), nil } -// GetVolumes returns all of the volumes matching the given options from a swarm cluster. -func (c *Cluster) GetVolumes(options volumebackend.ListOptions) ([]*volumetypes.Volume, error) { - var volumes []*volumetypes.Volume +// GetVolumes returns all volumes matching the given options from a swarm cluster. +func (c *Cluster) GetVolumes(options volumebackend.ListOptions) ([]volumetypes.Volume, error) { + var volumes []volumetypes.Volume if err := c.lockedManagerAction(context.TODO(), func(ctx context.Context, state nodeState) error { r, err := state.controlClient.ListVolumes( ctx, &swarmapi.ListVolumesRequest{}, @@ -42,10 +42,9 @@ func (c *Cluster) GetVolumes(options volumebackend.ListOptions) ([]*volumetypes. return err } - volumes = make([]*volumetypes.Volume, 0, len(r.Volumes)) + volumes = make([]volumetypes.Volume, 0, len(r.Volumes)) for _, volume := range r.Volumes { - v := convert.VolumeFromGRPC(volume) - volumes = append(volumes, &v) + volumes = append(volumes, convert.VolumeFromGRPC(volume)) } return nil diff --git a/daemon/disk_usage.go b/daemon/disk_usage.go index 067efc587c..c6d30534f6 100644 --- a/daemon/disk_usage.go +++ b/daemon/disk_usage.go @@ -127,7 +127,7 @@ func (daemon *Daemon) localVolumesSize(ctx context.Context, verbose bool) (*back } if verbose { - du.Items = sliceutil.Deref(volumes) + du.Items = volumes } return du, nil diff --git a/daemon/server/router/volume/backend.go b/daemon/server/router/volume/backend.go index 8405aabff5..7ca7a42c2d 100644 --- a/daemon/server/router/volume/backend.go +++ b/daemon/server/router/volume/backend.go @@ -12,7 +12,7 @@ import ( // Backend is the methods that need to be implemented to provide // volume specific functionality type Backend interface { - List(ctx context.Context, filter filters.Args) ([]*volume.Volume, []string, 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 @@ -25,7 +25,7 @@ type Backend interface { // backends here. type ClusterBackend interface { GetVolume(nameOrID string) (volume.Volume, error) - GetVolumes(options volumebackend.ListOptions) ([]*volume.Volume, error) + GetVolumes(options volumebackend.ListOptions) ([]volume.Volume, error) CreateVolume(volume volume.CreateRequest) (*volume.Volume, error) RemoveVolume(nameOrID string, force bool) error UpdateVolume(nameOrID string, version uint64, volume volumebackend.UpdateOptions) error diff --git a/daemon/server/router/volume/volume_routes_test.go b/daemon/server/router/volume/volume_routes_test.go index e5053eec69..0d72824e32 100644 --- a/daemon/server/router/volume/volume_routes_test.go +++ b/daemon/server/router/volume/volume_routes_test.go @@ -589,10 +589,10 @@ type fakeVolumeBackend struct { volumes map[string]*volume.Volume } -func (b *fakeVolumeBackend) List(_ context.Context, _ filters.Args) ([]*volume.Volume, []string, error) { - var volumes []*volume.Volume +func (b *fakeVolumeBackend) List(_ context.Context, _ filters.Args) ([]volume.Volume, []string, error) { + var volumes []volume.Volume for _, v := range b.volumes { - volumes = append(volumes, v) + volumes = append(volumes, *v) } return volumes, nil, nil } @@ -680,14 +680,14 @@ 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(_ volumebackend.ListOptions) ([]*volume.Volume, error) { +func (c *fakeClusterBackend) GetVolumes(_ volumebackend.ListOptions) ([]volume.Volume, error) { if err := c.checkSwarm(); err != nil { return nil, err } - var volumes []*volume.Volume + var volumes []volume.Volume for _, v := range c.volumes { - volumes = append(volumes, v) + volumes = append(volumes, *v) } return volumes, nil } diff --git a/daemon/volume/service/convert.go b/daemon/volume/service/convert.go index 5828a9b325..984ab1cdc2 100644 --- a/daemon/volume/service/convert.go +++ b/daemon/volume/service/convert.go @@ -31,9 +31,9 @@ type pathCacher interface { CachedPath() string } -func (s *VolumesService) volumesToAPI(ctx context.Context, volumes []volume.Volume, opts ...convertOpt) []*volumetypes.Volume { +func (s *VolumesService) volumesToAPI(ctx context.Context, volumes []volume.Volume, opts ...convertOpt) []volumetypes.Volume { var ( - out = make([]*volumetypes.Volume, 0, len(volumes)) + out = make([]volumetypes.Volume, 0, len(volumes)) getSize bool cachedPath bool ) @@ -75,7 +75,7 @@ func (s *VolumesService) volumesToAPI(ctx context.Context, volumes []volume.Volu apiV.UsageData = &volumetypes.UsageData{Size: sz, RefCount: int64(s.vs.CountReferences(v))} } - out = append(out, &apiV) + out = append(out, apiV) } return out } diff --git a/daemon/volume/service/service.go b/daemon/volume/service/service.go index 77bff5257c..3e7c359b58 100644 --- a/daemon/volume/service/service.go +++ b/daemon/volume/service/service.go @@ -195,7 +195,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) ([]*volumetypes.Volume, error) { +func (s *VolumesService) LocalVolumesSize(ctx context.Context) ([]volumetypes.Volume, error) { ls, _, err := s.vs.Find(ctx, And(ByDriver(volume.DefaultDriverName), CustomFilter(func(v volume.Volume) bool { dv, ok := v.(volume.DetailedVolume) return ok && len(dv.Options()) == 0 @@ -262,7 +262,7 @@ func (s *VolumesService) Prune(ctx context.Context, filter filters.Args) (*volum // 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) (volumes []*volumetypes.Volume, warnings []string, _ error) { +func (s *VolumesService) List(ctx context.Context, filter filters.Args) (volumes []volumetypes.Volume, warnings []string, _ error) { by, err := filtersToBy(filter, acceptedListFilters) if err != nil { return nil, nil, err diff --git a/vendor/github.com/moby/moby/api/types/volume/list_response.go b/vendor/github.com/moby/moby/api/types/volume/list_response.go index b725b6f121..f257762f09 100644 --- a/vendor/github.com/moby/moby/api/types/volume/list_response.go +++ b/vendor/github.com/moby/moby/api/types/volume/list_response.go @@ -13,7 +13,7 @@ package volume type ListResponse struct { // List of volumes - Volumes []*Volume `json:"Volumes"` + Volumes []Volume `json:"Volumes"` // Warnings that occurred when fetching the list of volumes. // diff --git a/vendor/github.com/moby/moby/client/volume_list.go b/vendor/github.com/moby/moby/client/volume_list.go index 802f104eaf..989a0292ec 100644 --- a/vendor/github.com/moby/moby/client/volume_list.go +++ b/vendor/github.com/moby/moby/client/volume_list.go @@ -4,7 +4,6 @@ import ( "context" "encoding/json" "net/url" - "slices" "github.com/moby/moby/api/types/volume" ) @@ -40,16 +39,8 @@ func (cli *Client) VolumeList(ctx context.Context, options VolumeListOptions) (V return VolumeListResult{}, err } - res := VolumeListResult{ - Items: make([]volume.Volume, 0, len(apiResp.Volumes)), - Warnings: slices.Clone(apiResp.Warnings), - } - - for _, vol := range apiResp.Volumes { - if vol != nil { - res.Items = append(res.Items, *vol) - } - } - - return res, nil + return VolumeListResult{ + Items: apiResp.Volumes, + Warnings: apiResp.Warnings, + }, nil }