api/types/swarm: move UpdateFlags type to client

Signed-off-by: Austin Vazquez <austin.vazquez@docker.com>
This commit is contained in:
Austin Vazquez
2025-08-22 14:05:33 -05:00
parent ad0fa5a872
commit 4dcc7af116
14 changed files with 35 additions and 25 deletions

View File

@@ -229,13 +229,6 @@ type Peer struct {
Addr string
}
// UpdateFlags contains flags for SwarmUpdate.
type UpdateFlags struct {
RotateWorkerToken bool
RotateManagerToken bool
RotateManagerUnlockKey bool
}
// UnlockKeyResponse contains the response for Engine API:
// GET /swarm/unlockkey
type UnlockKeyResponse struct {

View File

@@ -181,7 +181,7 @@ type SwarmAPIClient interface {
SwarmUnlock(ctx context.Context, req swarm.UnlockRequest) error
SwarmLeave(ctx context.Context, force bool) error
SwarmInspect(ctx context.Context) (swarm.Swarm, error)
SwarmUpdate(ctx context.Context, version swarm.Version, swarm swarm.Spec, flags swarm.UpdateFlags) error
SwarmUpdate(ctx context.Context, version swarm.Version, swarm swarm.Spec, flags SwarmUpdateFlags) error
}
// SystemAPIClient defines API client methods for the system

View File

@@ -9,7 +9,7 @@ import (
)
// SwarmUpdate updates the swarm.
func (cli *Client) SwarmUpdate(ctx context.Context, version swarm.Version, swarm swarm.Spec, flags swarm.UpdateFlags) error {
func (cli *Client) SwarmUpdate(ctx context.Context, version swarm.Version, swarm swarm.Spec, flags SwarmUpdateFlags) error {
query := url.Values{}
query.Set("version", version.String())
query.Set("rotateWorkerToken", strconv.FormatBool(flags.RotateWorkerToken))

View File

@@ -0,0 +1,8 @@
package client
// SwarmUpdateFlags contains flags for SwarmUpdate.
type SwarmUpdateFlags struct {
RotateWorkerToken bool
RotateManagerToken bool
RotateManagerUnlockKey bool
}

View File

@@ -20,7 +20,7 @@ func TestSwarmUpdateError(t *testing.T) {
client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")),
}
err := client.SwarmUpdate(context.Background(), swarm.Version{}, swarm.Spec{}, swarm.UpdateFlags{})
err := client.SwarmUpdate(context.Background(), swarm.Version{}, swarm.Spec{}, SwarmUpdateFlags{})
assert.Check(t, is.ErrorType(err, cerrdefs.IsInternal))
}
@@ -42,6 +42,6 @@ func TestSwarmUpdate(t *testing.T) {
}),
}
err := client.SwarmUpdate(context.Background(), swarm.Version{}, swarm.Spec{}, swarm.UpdateFlags{})
err := client.SwarmUpdate(context.Background(), swarm.Version{}, swarm.Spec{}, SwarmUpdateFlags{})
assert.NilError(t, err)
}

View File

@@ -15,6 +15,7 @@ import (
"github.com/moby/moby/v2/daemon/internal/stack"
"github.com/moby/moby/v2/daemon/pkg/opts"
"github.com/moby/moby/v2/daemon/server/backend"
"github.com/moby/moby/v2/daemon/server/swarmbackend"
"github.com/moby/moby/v2/errdefs"
swarmapi "github.com/moby/swarmkit/v2/api"
"github.com/moby/swarmkit/v2/manager/encryption"
@@ -240,7 +241,7 @@ func (c *Cluster) inspect(ctx context.Context, state nodeState) (types.Swarm, er
}
// Update updates configuration of a managed swarm cluster.
func (c *Cluster) Update(version uint64, spec types.Spec, flags types.UpdateFlags) error {
func (c *Cluster) Update(version uint64, spec types.Spec, flags swarmbackend.UpdateFlags) error {
return c.lockedManagerAction(func(ctx context.Context, state nodeState) error {
swarm, err := getSwarm(ctx, state.controlClient)
if err != nil {

View File

@@ -15,7 +15,7 @@ type Backend interface {
Join(req swarm.JoinRequest) error
Leave(ctx context.Context, force bool) error
Inspect() (swarm.Swarm, error)
Update(uint64, swarm.Spec, swarm.UpdateFlags) error
Update(uint64, swarm.Spec, swarmbackend.UpdateFlags) error
GetUnlockKey() (string, error)
UnlockSwarm(req swarm.UnlockRequest) error
GetServices(swarm.ServiceListOptions) ([]swarm.Service, error)

View File

@@ -82,7 +82,7 @@ func (sr *swarmRouter) updateCluster(ctx context.Context, w http.ResponseWriter,
return errdefs.InvalidParameter(err)
}
var flags types.UpdateFlags
var flags swarmbackend.UpdateFlags
if value := r.URL.Query().Get("rotateWorkerToken"); value != "" {
rot, err := strconv.ParseBool(value)

View File

@@ -13,3 +13,9 @@ type NodeListOptions struct {
type TaskListOptions struct {
Filters filters.Args
}
type UpdateFlags struct {
RotateWorkerToken bool
RotateManagerToken bool
RotateManagerUnlockKey bool
}

View File

@@ -6,6 +6,7 @@ import (
"testing"
"github.com/moby/moby/api/types/swarm"
"github.com/moby/moby/client"
"github.com/pkg/errors"
"gotest.tools/v3/assert"
)
@@ -177,7 +178,7 @@ func (d *Daemon) UpdateSwarm(t testing.TB, f ...SpecConstructor) {
fn(&sw.Spec)
}
err := cli.SwarmUpdate(context.Background(), sw.Version, sw.Spec, swarm.UpdateFlags{})
err := cli.SwarmUpdate(context.Background(), sw.Version, sw.Spec, client.SwarmUpdateFlags{})
assert.NilError(t, err)
}
@@ -190,7 +191,7 @@ func (d *Daemon) RotateTokens(t testing.TB) {
sw, err := cli.SwarmInspect(context.Background())
assert.NilError(t, err)
flags := swarm.UpdateFlags{
flags := client.SwarmUpdateFlags{
RotateManagerToken: true,
RotateWorkerToken: true,
}

View File

@@ -229,13 +229,6 @@ type Peer struct {
Addr string
}
// UpdateFlags contains flags for SwarmUpdate.
type UpdateFlags struct {
RotateWorkerToken bool
RotateManagerToken bool
RotateManagerUnlockKey bool
}
// UnlockKeyResponse contains the response for Engine API:
// GET /swarm/unlockkey
type UnlockKeyResponse struct {

View File

@@ -181,7 +181,7 @@ type SwarmAPIClient interface {
SwarmUnlock(ctx context.Context, req swarm.UnlockRequest) error
SwarmLeave(ctx context.Context, force bool) error
SwarmInspect(ctx context.Context) (swarm.Swarm, error)
SwarmUpdate(ctx context.Context, version swarm.Version, swarm swarm.Spec, flags swarm.UpdateFlags) error
SwarmUpdate(ctx context.Context, version swarm.Version, swarm swarm.Spec, flags SwarmUpdateFlags) error
}
// SystemAPIClient defines API client methods for the system

View File

@@ -9,7 +9,7 @@ import (
)
// SwarmUpdate updates the swarm.
func (cli *Client) SwarmUpdate(ctx context.Context, version swarm.Version, swarm swarm.Spec, flags swarm.UpdateFlags) error {
func (cli *Client) SwarmUpdate(ctx context.Context, version swarm.Version, swarm swarm.Spec, flags SwarmUpdateFlags) error {
query := url.Values{}
query.Set("version", version.String())
query.Set("rotateWorkerToken", strconv.FormatBool(flags.RotateWorkerToken))

View File

@@ -0,0 +1,8 @@
package client
// SwarmUpdateFlags contains flags for SwarmUpdate.
type SwarmUpdateFlags struct {
RotateWorkerToken bool
RotateManagerToken bool
RotateManagerUnlockKey bool
}