Files
moby/client/swarm_update.go
Sebastiaan van Stijn 3a43b5b559 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>
2025-10-23 15:40:18 +02:00

34 lines
1.0 KiB
Go

package client
import (
"context"
"net/url"
"strconv"
"github.com/moby/moby/api/types/swarm"
)
// SwarmUpdateOptions contains options for updating a swarm.
type SwarmUpdateOptions struct {
Version swarm.Version
Spec swarm.Spec
RotateWorkerToken bool
RotateManagerToken bool
RotateManagerUnlockKey bool
}
// SwarmUpdateResult represents the result of a SwarmUpdate operation.
type SwarmUpdateResult struct{}
// SwarmUpdate updates the swarm.
func (cli *Client) SwarmUpdate(ctx context.Context, options SwarmUpdateOptions) (SwarmUpdateResult, error) {
query := url.Values{}
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.Spec, nil)
defer ensureReaderClosed(resp)
return SwarmUpdateResult{}, err
}