client: refactor ServiceCreate, ServiceUpdate, SwarmUpdate

Put the version and spec in the options-struct, as we did for other
swarm-related methods.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn
2025-10-23 15:38:09 +02:00
parent dcd668d579
commit 3a43b5b559
20 changed files with 188 additions and 119 deletions

View File

@@ -10,7 +10,8 @@ import (
// SwarmUpdateOptions contains options for updating a swarm.
type SwarmUpdateOptions struct {
Swarm swarm.Spec
Version swarm.Version
Spec swarm.Spec
RotateWorkerToken bool
RotateManagerToken bool
RotateManagerUnlockKey bool
@@ -20,13 +21,13 @@ type SwarmUpdateOptions struct {
type SwarmUpdateResult struct{}
// SwarmUpdate updates the swarm.
func (cli *Client) SwarmUpdate(ctx context.Context, version swarm.Version, options SwarmUpdateOptions) (SwarmUpdateResult, error) {
func (cli *Client) SwarmUpdate(ctx context.Context, options SwarmUpdateOptions) (SwarmUpdateResult, error) {
query := url.Values{}
query.Set("version", version.String())
query.Set("version", options.Version.String())
query.Set("rotateWorkerToken", strconv.FormatBool(options.RotateWorkerToken))
query.Set("rotateManagerToken", strconv.FormatBool(options.RotateManagerToken))
query.Set("rotateManagerUnlockKey", strconv.FormatBool(options.RotateManagerUnlockKey))
resp, err := cli.post(ctx, "/swarm/update", query, options.Swarm, nil)
resp, err := cli.post(ctx, "/swarm/update", query, options.Spec, nil)
defer ensureReaderClosed(resp)
return SwarmUpdateResult{}, err
}