mirror of
https://github.com/moby/moby.git
synced 2026-01-11 10:41:43 +00:00
client: VolumeUpdate: add output struct, and move "version"
- Add a VolumeUpdateResult output struct - Move the swarm version argument to the options, to align with other swarm-related methods. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
@@ -10,7 +10,6 @@ import (
|
||||
"github.com/moby/moby/api/types/events"
|
||||
"github.com/moby/moby/api/types/network"
|
||||
"github.com/moby/moby/api/types/registry"
|
||||
"github.com/moby/moby/api/types/swarm"
|
||||
"github.com/moby/moby/api/types/system"
|
||||
)
|
||||
|
||||
@@ -193,7 +192,7 @@ type VolumeAPIClient interface {
|
||||
VolumeList(ctx context.Context, options VolumeListOptions) (VolumeListResult, error)
|
||||
VolumeRemove(ctx context.Context, volumeID string, options VolumeRemoveOptions) (VolumeRemoveResult, error)
|
||||
VolumesPrune(ctx context.Context, opts VolumePruneOptions) (VolumePruneResult, error)
|
||||
VolumeUpdate(ctx context.Context, volumeID string, version swarm.Version, options VolumeUpdateOptions) error
|
||||
VolumeUpdate(ctx context.Context, volumeID string, options VolumeUpdateOptions) (VolumeUpdateResult, error)
|
||||
}
|
||||
|
||||
// SecretAPIClient defines API client methods for secrets
|
||||
|
||||
@@ -8,23 +8,33 @@ import (
|
||||
"github.com/moby/moby/api/types/volume"
|
||||
)
|
||||
|
||||
// VolumeUpdateOptions holds options for [Client.VolumeUpdate].
|
||||
type VolumeUpdateOptions struct {
|
||||
Version swarm.Version
|
||||
// Spec is the ClusterVolumeSpec to update the volume to.
|
||||
Spec *volume.ClusterVolumeSpec `json:"Spec,omitempty"`
|
||||
}
|
||||
|
||||
// VolumeUpdateResult holds the result of [Client.VolumeUpdate],
|
||||
type VolumeUpdateResult struct {
|
||||
// Add future fields here.
|
||||
}
|
||||
|
||||
// VolumeUpdate updates a volume. This only works for Cluster Volumes, and
|
||||
// only some fields can be updated.
|
||||
func (cli *Client) VolumeUpdate(ctx context.Context, volumeID string, version swarm.Version, options VolumeUpdateOptions) error {
|
||||
func (cli *Client) VolumeUpdate(ctx context.Context, volumeID string, options VolumeUpdateOptions) (VolumeUpdateResult, error) {
|
||||
volumeID, err := trimID("volume", volumeID)
|
||||
if err != nil {
|
||||
return err
|
||||
return VolumeUpdateResult{}, err
|
||||
}
|
||||
|
||||
query := url.Values{}
|
||||
query.Set("version", version.String())
|
||||
query.Set("version", options.Version.String())
|
||||
|
||||
resp, err := cli.put(ctx, "/volumes/"+volumeID, query, options, nil)
|
||||
defer ensureReaderClosed(resp)
|
||||
return err
|
||||
if err != nil {
|
||||
return VolumeUpdateResult{}, err
|
||||
}
|
||||
return VolumeUpdateResult{}, nil
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package client
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strings"
|
||||
@@ -17,14 +16,14 @@ func TestVolumeUpdateError(t *testing.T) {
|
||||
client, err := NewClientWithOpts(WithMockClient(errorMock(http.StatusInternalServerError, "Server error")))
|
||||
assert.NilError(t, err)
|
||||
|
||||
err = client.VolumeUpdate(context.Background(), "volume", swarm.Version{}, VolumeUpdateOptions{})
|
||||
_, err = client.VolumeUpdate(t.Context(), "volume", VolumeUpdateOptions{})
|
||||
assert.Check(t, is.ErrorType(err, cerrdefs.IsInternal))
|
||||
|
||||
err = client.VolumeUpdate(context.Background(), "", swarm.Version{}, VolumeUpdateOptions{})
|
||||
_, err = client.VolumeUpdate(t.Context(), "", VolumeUpdateOptions{})
|
||||
assert.Check(t, is.ErrorType(err, cerrdefs.IsInvalidArgument))
|
||||
assert.Check(t, is.ErrorContains(err, "value is empty"))
|
||||
|
||||
err = client.VolumeUpdate(context.Background(), " ", swarm.Version{}, VolumeUpdateOptions{})
|
||||
_, err = client.VolumeUpdate(t.Context(), " ", VolumeUpdateOptions{})
|
||||
assert.Check(t, is.ErrorType(err, cerrdefs.IsInvalidArgument))
|
||||
assert.Check(t, is.ErrorContains(err, "value is empty"))
|
||||
}
|
||||
@@ -46,6 +45,8 @@ func TestVolumeUpdate(t *testing.T) {
|
||||
}))
|
||||
assert.NilError(t, err)
|
||||
|
||||
err = client.VolumeUpdate(context.Background(), "test1", swarm.Version{Index: uint64(10)}, VolumeUpdateOptions{})
|
||||
_, err = client.VolumeUpdate(t.Context(), "test1", VolumeUpdateOptions{
|
||||
Version: swarm.Version{Index: uint64(10)},
|
||||
})
|
||||
assert.NilError(t, err)
|
||||
}
|
||||
|
||||
3
vendor/github.com/moby/moby/client/client_interfaces.go
generated
vendored
3
vendor/github.com/moby/moby/client/client_interfaces.go
generated
vendored
@@ -10,7 +10,6 @@ import (
|
||||
"github.com/moby/moby/api/types/events"
|
||||
"github.com/moby/moby/api/types/network"
|
||||
"github.com/moby/moby/api/types/registry"
|
||||
"github.com/moby/moby/api/types/swarm"
|
||||
"github.com/moby/moby/api/types/system"
|
||||
)
|
||||
|
||||
@@ -193,7 +192,7 @@ type VolumeAPIClient interface {
|
||||
VolumeList(ctx context.Context, options VolumeListOptions) (VolumeListResult, error)
|
||||
VolumeRemove(ctx context.Context, volumeID string, options VolumeRemoveOptions) (VolumeRemoveResult, error)
|
||||
VolumesPrune(ctx context.Context, opts VolumePruneOptions) (VolumePruneResult, error)
|
||||
VolumeUpdate(ctx context.Context, volumeID string, version swarm.Version, options VolumeUpdateOptions) error
|
||||
VolumeUpdate(ctx context.Context, volumeID string, options VolumeUpdateOptions) (VolumeUpdateResult, error)
|
||||
}
|
||||
|
||||
// SecretAPIClient defines API client methods for secrets
|
||||
|
||||
18
vendor/github.com/moby/moby/client/volume_update.go
generated
vendored
18
vendor/github.com/moby/moby/client/volume_update.go
generated
vendored
@@ -8,23 +8,33 @@ import (
|
||||
"github.com/moby/moby/api/types/volume"
|
||||
)
|
||||
|
||||
// VolumeUpdateOptions holds options for [Client.VolumeUpdate].
|
||||
type VolumeUpdateOptions struct {
|
||||
Version swarm.Version
|
||||
// Spec is the ClusterVolumeSpec to update the volume to.
|
||||
Spec *volume.ClusterVolumeSpec `json:"Spec,omitempty"`
|
||||
}
|
||||
|
||||
// VolumeUpdateResult holds the result of [Client.VolumeUpdate],
|
||||
type VolumeUpdateResult struct {
|
||||
// Add future fields here.
|
||||
}
|
||||
|
||||
// VolumeUpdate updates a volume. This only works for Cluster Volumes, and
|
||||
// only some fields can be updated.
|
||||
func (cli *Client) VolumeUpdate(ctx context.Context, volumeID string, version swarm.Version, options VolumeUpdateOptions) error {
|
||||
func (cli *Client) VolumeUpdate(ctx context.Context, volumeID string, options VolumeUpdateOptions) (VolumeUpdateResult, error) {
|
||||
volumeID, err := trimID("volume", volumeID)
|
||||
if err != nil {
|
||||
return err
|
||||
return VolumeUpdateResult{}, err
|
||||
}
|
||||
|
||||
query := url.Values{}
|
||||
query.Set("version", version.String())
|
||||
query.Set("version", options.Version.String())
|
||||
|
||||
resp, err := cli.put(ctx, "/volumes/"+volumeID, query, options, nil)
|
||||
defer ensureReaderClosed(resp)
|
||||
return err
|
||||
if err != nil {
|
||||
return VolumeUpdateResult{}, err
|
||||
}
|
||||
return VolumeUpdateResult{}, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user