From 1985a8979efb42432d35363b52e7e11281710e14 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Tue, 28 Oct 2025 15:34:41 +0100 Subject: [PATCH] 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 --- client/client_interfaces.go | 3 +-- client/volume_update.go | 18 ++++++++++++++---- client/volume_update_test.go | 11 ++++++----- .../moby/moby/client/client_interfaces.go | 3 +-- .../moby/moby/client/volume_update.go | 18 ++++++++++++++---- 5 files changed, 36 insertions(+), 17 deletions(-) diff --git a/client/client_interfaces.go b/client/client_interfaces.go index 94ebd52c53..cd0948309a 100644 --- a/client/client_interfaces.go +++ b/client/client_interfaces.go @@ -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 diff --git a/client/volume_update.go b/client/volume_update.go index 20b0f34ea0..5aa2a0aa17 100644 --- a/client/volume_update.go +++ b/client/volume_update.go @@ -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 } diff --git a/client/volume_update_test.go b/client/volume_update_test.go index c1afacc469..a09d46d39f 100644 --- a/client/volume_update_test.go +++ b/client/volume_update_test.go @@ -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) } diff --git a/vendor/github.com/moby/moby/client/client_interfaces.go b/vendor/github.com/moby/moby/client/client_interfaces.go index 94ebd52c53..cd0948309a 100644 --- a/vendor/github.com/moby/moby/client/client_interfaces.go +++ b/vendor/github.com/moby/moby/client/client_interfaces.go @@ -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 diff --git a/vendor/github.com/moby/moby/client/volume_update.go b/vendor/github.com/moby/moby/client/volume_update.go index 20b0f34ea0..5aa2a0aa17 100644 --- a/vendor/github.com/moby/moby/client/volume_update.go +++ b/vendor/github.com/moby/moby/client/volume_update.go @@ -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 }