Skip to content

Commit 0b1c7a8

Browse files
committed
api/types: move ServiceUpdateOptions to api/types/swarm
Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent 31d6293 commit 0b1c7a8

13 files changed

Lines changed: 72 additions & 71 deletions

File tree

api/server/router/swarm/backend.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package swarm // import "github.com/docker/docker/api/server/router/swarm"
33
import (
44
"context"
55

6-
"github.com/docker/docker/api/types"
76
"github.com/docker/docker/api/types/backend"
87
"github.com/docker/docker/api/types/container"
98
"github.com/docker/docker/api/types/swarm"
@@ -21,7 +20,7 @@ type Backend interface {
2120
GetServices(swarm.ServiceListOptions) ([]swarm.Service, error)
2221
GetService(idOrName string, insertDefaults bool) (swarm.Service, error)
2322
CreateService(swarm.ServiceSpec, string, bool) (*swarm.ServiceCreateResponse, error)
24-
UpdateService(string, uint64, swarm.ServiceSpec, types.ServiceUpdateOptions, bool) (*swarm.ServiceUpdateResponse, error)
23+
UpdateService(string, uint64, swarm.ServiceSpec, swarm.ServiceUpdateOptions, bool) (*swarm.ServiceUpdateResponse, error)
2524
RemoveService(string) error
2625
ServiceLogs(context.Context, *backend.LogSelector, *container.LogsOptions) (<-chan *backend.LogMessage, error)
2726
GetNodes(swarm.NodeListOptions) ([]swarm.Node, error)

api/server/router/swarm/cluster_routes.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88

99
"github.com/containerd/log"
1010
"github.com/docker/docker/api/server/httputils"
11-
basictypes "github.com/docker/docker/api/types"
1211
"github.com/docker/docker/api/types/backend"
1312
"github.com/docker/docker/api/types/filters"
1413
"github.com/docker/docker/api/types/registry"
@@ -245,7 +244,7 @@ func (sr *swarmRouter) updateService(ctx context.Context, w http.ResponseWriter,
245244
return errdefs.InvalidParameter(err)
246245
}
247246

248-
var flags basictypes.ServiceUpdateOptions
247+
var flags types.ServiceUpdateOptions
249248

250249
// Get returns "" if the header does not exist
251250
flags.EncodedRegistryAuth = r.Header.Get(registry.AuthHeader)

api/types/client.go

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -46,42 +46,6 @@ func (h *HijackedResponse) CloseWrite() error {
4646
return nil
4747
}
4848

49-
// Values for RegistryAuthFrom in ServiceUpdateOptions
50-
const (
51-
RegistryAuthFromSpec = "spec"
52-
RegistryAuthFromPreviousSpec = "previous-spec"
53-
)
54-
55-
// ServiceUpdateOptions contains the options to be used for updating services.
56-
type ServiceUpdateOptions struct {
57-
// EncodedRegistryAuth is the encoded registry authorization credentials to
58-
// use when updating the service.
59-
//
60-
// This field follows the format of the X-Registry-Auth header.
61-
EncodedRegistryAuth string
62-
63-
// TODO(stevvooe): Consider moving the version parameter of ServiceUpdate
64-
// into this field. While it does open API users up to racy writes, most
65-
// users may not need that level of consistency in practice.
66-
67-
// RegistryAuthFrom specifies where to find the registry authorization
68-
// credentials if they are not given in EncodedRegistryAuth. Valid
69-
// values are "spec" and "previous-spec".
70-
RegistryAuthFrom string
71-
72-
// Rollback indicates whether a server-side rollback should be
73-
// performed. When this is set, the provided spec will be ignored.
74-
// The valid values are "previous" and "none". An empty value is the
75-
// same as "none".
76-
Rollback string
77-
78-
// QueryRegistry indicates whether the service update requires
79-
// contacting a registry. A registry may be contacted to retrieve
80-
// the image digest and manifest, which in turn can be used to update
81-
// platform or other information about the service.
82-
QueryRegistry bool
83-
}
84-
8549
// PluginRemoveOptions holds parameters to remove plugins.
8650
type PluginRemoveOptions struct {
8751
Force bool

api/types/swarm/service.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,42 @@ type ServiceCreateOptions struct {
220220
QueryRegistry bool
221221
}
222222

223+
// Values for RegistryAuthFrom in ServiceUpdateOptions
224+
const (
225+
RegistryAuthFromSpec = "spec"
226+
RegistryAuthFromPreviousSpec = "previous-spec"
227+
)
228+
229+
// ServiceUpdateOptions contains the options to be used for updating services.
230+
type ServiceUpdateOptions struct {
231+
// EncodedRegistryAuth is the encoded registry authorization credentials to
232+
// use when updating the service.
233+
//
234+
// This field follows the format of the X-Registry-Auth header.
235+
EncodedRegistryAuth string
236+
237+
// TODO(stevvooe): Consider moving the version parameter of ServiceUpdate
238+
// into this field. While it does open API users up to racy writes, most
239+
// users may not need that level of consistency in practice.
240+
241+
// RegistryAuthFrom specifies where to find the registry authorization
242+
// credentials if they are not given in EncodedRegistryAuth. Valid
243+
// values are "spec" and "previous-spec".
244+
RegistryAuthFrom string
245+
246+
// Rollback indicates whether a server-side rollback should be
247+
// performed. When this is set, the provided spec will be ignored.
248+
// The valid values are "previous" and "none". An empty value is the
249+
// same as "none".
250+
Rollback string
251+
252+
// QueryRegistry indicates whether the service update requires
253+
// contacting a registry. A registry may be contacted to retrieve
254+
// the image digest and manifest, which in turn can be used to update
255+
// platform or other information about the service.
256+
QueryRegistry bool
257+
}
258+
223259
// ServiceListOptions holds parameters to list services with.
224260
type ServiceListOptions struct {
225261
Filters filters.Args

api/types/types_deprecated.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,16 @@ type TaskListOptions = swarm.TaskListOptions
158158
// Deprecated: use [swarm.ServiceCreateOptions].
159159
type ServiceCreateOptions = swarm.ServiceCreateOptions
160160

161+
// ServiceUpdateOptions contains the options to be used for updating services.
162+
//
163+
// Deprecated: use [swarm.ServiceCreateOptions].
164+
type ServiceUpdateOptions = swarm.ServiceUpdateOptions
165+
166+
const (
167+
RegistryAuthFromSpec = swarm.RegistryAuthFromSpec // Deprecated: use [swarm.RegistryAuthFromSpec].
168+
RegistryAuthFromPreviousSpec = swarm.RegistryAuthFromPreviousSpec // Deprecated: use [swarm.RegistryAuthFromPreviousSpec].
169+
)
170+
161171
// ServiceListOptions holds parameters to list services with.
162172
//
163173
// Deprecated: use [swarm.ServiceListOptions].

client/client_interfaces.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ type ServiceAPIClient interface {
180180
ServiceInspectWithRaw(ctx context.Context, serviceID string, options swarm.ServiceInspectOptions) (swarm.Service, []byte, error)
181181
ServiceList(ctx context.Context, options swarm.ServiceListOptions) ([]swarm.Service, error)
182182
ServiceRemove(ctx context.Context, serviceID string) error
183-
ServiceUpdate(ctx context.Context, serviceID string, version swarm.Version, service swarm.ServiceSpec, options types.ServiceUpdateOptions) (swarm.ServiceUpdateResponse, error)
183+
ServiceUpdate(ctx context.Context, serviceID string, version swarm.Version, service swarm.ServiceSpec, options swarm.ServiceUpdateOptions) (swarm.ServiceUpdateResponse, error)
184184
ServiceLogs(ctx context.Context, serviceID string, options container.LogsOptions) (io.ReadCloser, error)
185185
TaskLogs(ctx context.Context, taskID string, options container.LogsOptions) (io.ReadCloser, error)
186186
TaskInspectWithRaw(ctx context.Context, taskID string) (swarm.Task, []byte, error)

client/service_update.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"net/http"
77
"net/url"
88

9-
"github.com/docker/docker/api/types"
109
"github.com/docker/docker/api/types/registry"
1110
"github.com/docker/docker/api/types/swarm"
1211
"github.com/docker/docker/api/types/versions"
@@ -15,7 +14,7 @@ import (
1514
// ServiceUpdate updates a Service. The version number is required to avoid conflicting writes.
1615
// It should be the value as set *before* the update. You can find this value in the Meta field
1716
// of swarm.Service, which can be found using ServiceInspectWithRaw.
18-
func (cli *Client) ServiceUpdate(ctx context.Context, serviceID string, version swarm.Version, service swarm.ServiceSpec, options types.ServiceUpdateOptions) (swarm.ServiceUpdateResponse, error) {
17+
func (cli *Client) ServiceUpdate(ctx context.Context, serviceID string, version swarm.Version, service swarm.ServiceSpec, options swarm.ServiceUpdateOptions) (swarm.ServiceUpdateResponse, error) {
1918
serviceID, err := trimID("service", serviceID)
2019
if err != nil {
2120
return swarm.ServiceUpdateResponse{}, err

client/service_update_test.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"strings"
1010
"testing"
1111

12-
"github.com/docker/docker/api/types"
1312
"github.com/docker/docker/api/types/swarm"
1413
"github.com/docker/docker/errdefs"
1514
"gotest.tools/v3/assert"
@@ -21,14 +20,14 @@ func TestServiceUpdateError(t *testing.T) {
2120
client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")),
2221
}
2322

24-
_, err := client.ServiceUpdate(context.Background(), "service_id", swarm.Version{}, swarm.ServiceSpec{}, types.ServiceUpdateOptions{})
23+
_, err := client.ServiceUpdate(context.Background(), "service_id", swarm.Version{}, swarm.ServiceSpec{}, swarm.ServiceUpdateOptions{})
2524
assert.Check(t, is.ErrorType(err, errdefs.IsSystem))
2625

27-
_, err = client.ServiceUpdate(context.Background(), "", swarm.Version{}, swarm.ServiceSpec{}, types.ServiceUpdateOptions{})
26+
_, err = client.ServiceUpdate(context.Background(), "", swarm.Version{}, swarm.ServiceSpec{}, swarm.ServiceUpdateOptions{})
2827
assert.Check(t, is.ErrorType(err, errdefs.IsInvalidParameter))
2928
assert.Check(t, is.ErrorContains(err, "value is empty"))
3029

31-
_, err = client.ServiceUpdate(context.Background(), " ", swarm.Version{}, swarm.ServiceSpec{}, types.ServiceUpdateOptions{})
30+
_, err = client.ServiceUpdate(context.Background(), " ", swarm.Version{}, swarm.ServiceSpec{}, swarm.ServiceUpdateOptions{})
3231
assert.Check(t, is.ErrorType(err, errdefs.IsInvalidParameter))
3332
assert.Check(t, is.ErrorContains(err, "value is empty"))
3433
}
@@ -41,7 +40,7 @@ func TestServiceUpdateConnectionError(t *testing.T) {
4140
client, err := NewClientWithOpts(WithAPIVersionNegotiation(), WithHost("tcp://no-such-host.invalid"))
4241
assert.NilError(t, err)
4342

44-
_, err = client.ServiceUpdate(context.Background(), "service_id", swarm.Version{}, swarm.ServiceSpec{}, types.ServiceUpdateOptions{})
43+
_, err = client.ServiceUpdate(context.Background(), "service_id", swarm.Version{}, swarm.ServiceSpec{}, swarm.ServiceUpdateOptions{})
4544
assert.Check(t, is.ErrorType(err, IsErrConnectionFailed))
4645
}
4746

@@ -89,7 +88,7 @@ func TestServiceUpdate(t *testing.T) {
8988
}),
9089
}
9190

92-
_, err := client.ServiceUpdate(context.Background(), "service_id", updateCase.swarmVersion, swarm.ServiceSpec{}, types.ServiceUpdateOptions{})
91+
_, err := client.ServiceUpdate(context.Background(), "service_id", updateCase.swarmVersion, swarm.ServiceSpec{}, swarm.ServiceUpdateOptions{})
9392
assert.NilError(t, err)
9493
}
9594
}

daemon/cluster/services.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import (
1313

1414
"github.com/containerd/log"
1515
"github.com/distribution/reference"
16-
"github.com/docker/docker/api/types"
1716
"github.com/docker/docker/api/types/backend"
1817
"github.com/docker/docker/api/types/container"
1918
"github.com/docker/docker/api/types/registry"
@@ -283,7 +282,7 @@ func (c *Cluster) CreateService(s swarm.ServiceSpec, encodedAuth string, queryRe
283282
}
284283

285284
// UpdateService updates existing service to match new properties.
286-
func (c *Cluster) UpdateService(serviceIDOrName string, version uint64, spec swarm.ServiceSpec, flags types.ServiceUpdateOptions, queryRegistry bool) (*swarm.ServiceUpdateResponse, error) {
285+
func (c *Cluster) UpdateService(serviceIDOrName string, version uint64, spec swarm.ServiceSpec, flags swarm.ServiceUpdateOptions, queryRegistry bool) (*swarm.ServiceUpdateResponse, error) {
287286
var resp *swarm.ServiceUpdateResponse
288287

289288
err := c.lockedManagerAction(func(ctx context.Context, state nodeState) error {
@@ -328,9 +327,9 @@ func (c *Cluster) UpdateService(serviceIDOrName string, version uint64, spec swa
328327
// shouldn't lose it, and continue to use the one that was already present
329328
var ctnr *swarmapi.ContainerSpec
330329
switch flags.RegistryAuthFrom {
331-
case types.RegistryAuthFromSpec, "":
330+
case swarm.RegistryAuthFromSpec, "":
332331
ctnr = currentService.Spec.Task.GetContainer()
333-
case types.RegistryAuthFromPreviousSpec:
332+
case swarm.RegistryAuthFromPreviousSpec:
334333
if currentService.PreviousSpec == nil {
335334
return errors.New("service does not have a previous spec")
336335
}

integration-cli/docker_api_swarm_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import (
1818
"github.com/cloudflare/cfssl/csr"
1919
"github.com/cloudflare/cfssl/helpers"
2020
"github.com/cloudflare/cfssl/initca"
21-
"github.com/docker/docker/api/types"
2221
"github.com/docker/docker/api/types/container"
2322
"github.com/docker/docker/api/types/network"
2423
"github.com/docker/docker/api/types/swarm"
@@ -890,7 +889,7 @@ func (s *DockerSwarmSuite) TestAPISwarmServicesUpdateWithName(c *testing.T) {
890889
setInstances(instances)(service)
891890
cli := d.NewClientT(c)
892891
defer cli.Close()
893-
_, err := cli.ServiceUpdate(ctx, service.Spec.Name, service.Version, service.Spec, types.ServiceUpdateOptions{})
892+
_, err := cli.ServiceUpdate(ctx, service.Spec.Name, service.Version, service.Spec, swarm.ServiceUpdateOptions{})
894893
assert.NilError(c, err)
895894
poll.WaitOn(c, pollCheck(c, d.CheckActiveContainerCount(ctx), checker.Equals(instances)), poll.WithTimeout(defaultReconciliationTimeout))
896895
}

0 commit comments

Comments
 (0)