Signed-off-by: Austin Vazquez <austin.vazquez@docker.com>
| ... | ... |
@@ -205,21 +205,6 @@ type JobStatus struct {
|
| 205 | 205 |
LastExecution time.Time `json:",omitempty"` |
| 206 | 206 |
} |
| 207 | 207 |
|
| 208 |
-// ServiceCreateOptions contains the options to use when creating a service. |
|
| 209 |
-type ServiceCreateOptions struct {
|
|
| 210 |
- // EncodedRegistryAuth is the encoded registry authorization credentials to |
|
| 211 |
- // use when updating the service. |
|
| 212 |
- // |
|
| 213 |
- // This field follows the format of the X-Registry-Auth header. |
|
| 214 |
- EncodedRegistryAuth string |
|
| 215 |
- |
|
| 216 |
- // QueryRegistry indicates whether the service update requires |
|
| 217 |
- // contacting a registry. A registry may be contacted to retrieve |
|
| 218 |
- // the image digest and manifest, which in turn can be used to update |
|
| 219 |
- // platform or other information about the service. |
|
| 220 |
- QueryRegistry bool |
|
| 221 |
-} |
|
| 222 |
- |
|
| 223 | 208 |
// Values for RegistryAuthFrom in ServiceUpdateOptions |
| 224 | 209 |
const ( |
| 225 | 210 |
RegistryAuthFromSpec = "spec" |
| ... | ... |
@@ -162,7 +162,7 @@ type PluginAPIClient interface {
|
| 162 | 162 |
|
| 163 | 163 |
// ServiceAPIClient defines API client methods for the services |
| 164 | 164 |
type ServiceAPIClient interface {
|
| 165 |
- ServiceCreate(ctx context.Context, service swarm.ServiceSpec, options swarm.ServiceCreateOptions) (swarm.ServiceCreateResponse, error) |
|
| 165 |
+ ServiceCreate(ctx context.Context, service swarm.ServiceSpec, options ServiceCreateOptions) (swarm.ServiceCreateResponse, error) |
|
| 166 | 166 |
ServiceInspectWithRaw(ctx context.Context, serviceID string, options swarm.ServiceInspectOptions) (swarm.Service, []byte, error) |
| 167 | 167 |
ServiceList(ctx context.Context, options swarm.ServiceListOptions) ([]swarm.Service, error) |
| 168 | 168 |
ServiceRemove(ctx context.Context, serviceID string) error |
| ... | ... |
@@ -16,7 +16,7 @@ import ( |
| 16 | 16 |
) |
| 17 | 17 |
|
| 18 | 18 |
// ServiceCreate creates a new service. |
| 19 |
-func (cli *Client) ServiceCreate(ctx context.Context, service swarm.ServiceSpec, options swarm.ServiceCreateOptions) (swarm.ServiceCreateResponse, error) {
|
|
| 19 |
+func (cli *Client) ServiceCreate(ctx context.Context, service swarm.ServiceSpec, options ServiceCreateOptions) (swarm.ServiceCreateResponse, error) {
|
|
| 20 | 20 |
var response swarm.ServiceCreateResponse |
| 21 | 21 |
|
| 22 | 22 |
// Make sure we negotiated (if the client is configured to do so), |
| ... | ... |
@@ -24,7 +24,7 @@ func TestServiceCreateError(t *testing.T) {
|
| 24 | 24 |
client := &Client{
|
| 25 | 25 |
client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), |
| 26 | 26 |
} |
| 27 |
- _, err := client.ServiceCreate(context.Background(), swarm.ServiceSpec{}, swarm.ServiceCreateOptions{})
|
|
| 27 |
+ _, err := client.ServiceCreate(context.Background(), swarm.ServiceSpec{}, ServiceCreateOptions{})
|
|
| 28 | 28 |
assert.Check(t, is.ErrorType(err, cerrdefs.IsInternal)) |
| 29 | 29 |
} |
| 30 | 30 |
|
| ... | ... |
@@ -36,7 +36,7 @@ func TestServiceCreateConnectionError(t *testing.T) {
|
| 36 | 36 |
client, err := NewClientWithOpts(WithAPIVersionNegotiation(), WithHost("tcp://no-such-host.invalid"))
|
| 37 | 37 |
assert.NilError(t, err) |
| 38 | 38 |
|
| 39 |
- _, err = client.ServiceCreate(context.Background(), swarm.ServiceSpec{}, swarm.ServiceCreateOptions{})
|
|
| 39 |
+ _, err = client.ServiceCreate(context.Background(), swarm.ServiceSpec{}, ServiceCreateOptions{})
|
|
| 40 | 40 |
assert.Check(t, is.ErrorType(err, IsErrConnectionFailed)) |
| 41 | 41 |
} |
| 42 | 42 |
|
| ... | ... |
@@ -63,7 +63,7 @@ func TestServiceCreate(t *testing.T) {
|
| 63 | 63 |
}), |
| 64 | 64 |
} |
| 65 | 65 |
|
| 66 |
- r, err := client.ServiceCreate(context.Background(), swarm.ServiceSpec{}, swarm.ServiceCreateOptions{})
|
|
| 66 |
+ r, err := client.ServiceCreate(context.Background(), swarm.ServiceSpec{}, ServiceCreateOptions{})
|
|
| 67 | 67 |
assert.NilError(t, err) |
| 68 | 68 |
assert.Check(t, is.Equal(r.ID, "service_id")) |
| 69 | 69 |
} |
| ... | ... |
@@ -122,7 +122,7 @@ func TestServiceCreateCompatiblePlatforms(t *testing.T) {
|
| 122 | 122 |
|
| 123 | 123 |
spec := swarm.ServiceSpec{TaskTemplate: swarm.TaskSpec{ContainerSpec: &swarm.ContainerSpec{Image: "foobar:1.0"}}}
|
| 124 | 124 |
|
| 125 |
- r, err := client.ServiceCreate(context.Background(), spec, swarm.ServiceCreateOptions{QueryRegistry: true})
|
|
| 125 |
+ r, err := client.ServiceCreate(context.Background(), spec, ServiceCreateOptions{QueryRegistry: true})
|
|
| 126 | 126 |
assert.NilError(t, err) |
| 127 | 127 |
assert.Check(t, is.Equal("service_linux_amd64", r.ID))
|
| 128 | 128 |
} |
| ... | ... |
@@ -201,7 +201,7 @@ func TestServiceCreateDigestPinning(t *testing.T) {
|
| 201 | 201 |
Image: p.img, |
| 202 | 202 |
}, |
| 203 | 203 |
}, |
| 204 |
- }, swarm.ServiceCreateOptions{QueryRegistry: true})
|
|
| 204 |
+ }, ServiceCreateOptions{QueryRegistry: true})
|
|
| 205 | 205 |
assert.NilError(t, err) |
| 206 | 206 |
|
| 207 | 207 |
assert.Check(t, is.Equal(r.ID, "service_id")) |
| 208 | 208 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,16 @@ |
| 0 |
+package client |
|
| 1 |
+ |
|
| 2 |
+// ServiceCreateOptions contains the options to use when creating a service. |
|
| 3 |
+type ServiceCreateOptions struct {
|
|
| 4 |
+ // EncodedRegistryAuth is the encoded registry authorization credentials to |
|
| 5 |
+ // use when updating the service. |
|
| 6 |
+ // |
|
| 7 |
+ // This field follows the format of the X-Registry-Auth header. |
|
| 8 |
+ EncodedRegistryAuth string |
|
| 9 |
+ |
|
| 10 |
+ // QueryRegistry indicates whether the service update requires |
|
| 11 |
+ // contacting a registry. A registry may be contacted to retrieve |
|
| 12 |
+ // the image digest and manifest, which in turn can be used to update |
|
| 13 |
+ // platform or other information about the service. |
|
| 14 |
+ QueryRegistry bool |
|
| 15 |
+} |
| ... | ... |
@@ -414,7 +414,7 @@ func (s *DockerSwarmSuite) TestAPISwarmRaftQuorum(c *testing.T) {
|
| 414 | 414 |
|
| 415 | 415 |
// d1 will eventually step down from leader because there is no longer an active quorum, wait for that to happen |
| 416 | 416 |
poll.WaitOn(c, pollCheck(c, func(t *testing.T) (any, string) {
|
| 417 |
- _, err := cli.ServiceCreate(testutil.GetContext(t), service.Spec, swarm.ServiceCreateOptions{})
|
|
| 417 |
+ _, err := cli.ServiceCreate(testutil.GetContext(t), service.Spec, client.ServiceCreateOptions{})
|
|
| 418 | 418 |
return err.Error(), "" |
| 419 | 419 |
}, checker.Contains("Make sure more than half of the managers are online.")), poll.WithTimeout(defaultReconciliationTimeout*2))
|
| 420 | 420 |
|
| ... | ... |
@@ -63,7 +63,7 @@ func CreateService(ctx context.Context, t *testing.T, d *daemon.Daemon, opts ... |
| 63 | 63 |
defer apiClient.Close() |
| 64 | 64 |
|
| 65 | 65 |
spec := CreateServiceSpec(t, opts...) |
| 66 |
- resp, err := apiClient.ServiceCreate(ctx, spec, swarmtypes.ServiceCreateOptions{})
|
|
| 66 |
+ resp, err := apiClient.ServiceCreate(ctx, spec, client.ServiceCreateOptions{})
|
|
| 67 | 67 |
assert.NilError(t, err, "error creating service") |
| 68 | 68 |
return resp.ID |
| 69 | 69 |
} |
| ... | ... |
@@ -164,7 +164,7 @@ func TestCreateServiceConflict(t *testing.T) {
|
| 164 | 164 |
swarm.CreateService(ctx, t, d, serviceSpec...) |
| 165 | 165 |
|
| 166 | 166 |
spec := swarm.CreateServiceSpec(t, serviceSpec...) |
| 167 |
- _, err := c.ServiceCreate(ctx, spec, swarmtypes.ServiceCreateOptions{})
|
|
| 167 |
+ _, err := c.ServiceCreate(ctx, spec, client.ServiceCreateOptions{})
|
|
| 168 | 168 |
assert.Check(t, cerrdefs.IsConflict(err)) |
| 169 | 169 |
assert.ErrorContains(t, err, "service "+serviceName+" already exists") |
| 170 | 170 |
} |
| ... | ... |
@@ -7,6 +7,7 @@ import ( |
| 7 | 7 |
"github.com/google/go-cmp/cmp" |
| 8 | 8 |
"github.com/moby/moby/api/types/container" |
| 9 | 9 |
swarmtypes "github.com/moby/moby/api/types/swarm" |
| 10 |
+ "github.com/moby/moby/client" |
|
| 10 | 11 |
"github.com/moby/moby/v2/integration/internal/swarm" |
| 11 | 12 |
"gotest.tools/v3/assert" |
| 12 | 13 |
is "gotest.tools/v3/assert/cmp" |
| ... | ... |
@@ -20,22 +21,22 @@ func TestInspect(t *testing.T) {
|
| 20 | 20 |
ctx := setupTest(t) |
| 21 | 21 |
d := swarm.NewSwarm(ctx, t, testEnv) |
| 22 | 22 |
defer d.Stop(t) |
| 23 |
- client := d.NewClientT(t) |
|
| 24 |
- defer client.Close() |
|
| 23 |
+ apiClient := d.NewClientT(t) |
|
| 24 |
+ defer apiClient.Close() |
|
| 25 | 25 |
|
| 26 | 26 |
now := time.Now() |
| 27 | 27 |
var instances uint64 = 2 |
| 28 | 28 |
serviceSpec := fullSwarmServiceSpec("test-service-inspect"+t.Name(), instances)
|
| 29 | 29 |
|
| 30 |
- resp, err := client.ServiceCreate(ctx, serviceSpec, swarmtypes.ServiceCreateOptions{
|
|
| 30 |
+ resp, err := apiClient.ServiceCreate(ctx, serviceSpec, client.ServiceCreateOptions{
|
|
| 31 | 31 |
QueryRegistry: false, |
| 32 | 32 |
}) |
| 33 | 33 |
assert.NilError(t, err) |
| 34 | 34 |
|
| 35 | 35 |
id := resp.ID |
| 36 |
- poll.WaitOn(t, swarm.RunningTasksCount(ctx, client, id, instances)) |
|
| 36 |
+ poll.WaitOn(t, swarm.RunningTasksCount(ctx, apiClient, id, instances)) |
|
| 37 | 37 |
|
| 38 |
- service, _, err := client.ServiceInspectWithRaw(ctx, id, swarmtypes.ServiceInspectOptions{})
|
|
| 38 |
+ service, _, err := apiClient.ServiceInspectWithRaw(ctx, id, swarmtypes.ServiceInspectOptions{})
|
|
| 39 | 39 |
assert.NilError(t, err) |
| 40 | 40 |
|
| 41 | 41 |
expected := swarmtypes.Service{
|
| ... | ... |
@@ -44,7 +44,7 @@ func TestServiceListWithStatuses(t *testing.T) {
|
| 44 | 44 |
// tasks to fail and exit. instead, we'll just pass no args, which |
| 45 | 45 |
// works. |
| 46 | 46 |
spec.TaskTemplate.ContainerSpec.Args = []string{}
|
| 47 |
- resp, err := apiClient.ServiceCreate(ctx, spec, swarmtypes.ServiceCreateOptions{
|
|
| 47 |
+ resp, err := apiClient.ServiceCreate(ctx, spec, client.ServiceCreateOptions{
|
|
| 48 | 48 |
QueryRegistry: false, |
| 49 | 49 |
}) |
| 50 | 50 |
assert.NilError(t, err) |
| ... | ... |
@@ -14,7 +14,7 @@ import ( |
| 14 | 14 |
// ServiceConstructor defines a swarm service constructor function |
| 15 | 15 |
type ServiceConstructor func(*swarm.Service) |
| 16 | 16 |
|
| 17 |
-func (d *Daemon) createServiceWithOptions(ctx context.Context, t testing.TB, opts swarm.ServiceCreateOptions, f ...ServiceConstructor) string {
|
|
| 17 |
+func (d *Daemon) createServiceWithOptions(ctx context.Context, t testing.TB, opts client.ServiceCreateOptions, f ...ServiceConstructor) string {
|
|
| 18 | 18 |
t.Helper() |
| 19 | 19 |
var service swarm.Service |
| 20 | 20 |
for _, fn := range f {
|
| ... | ... |
@@ -35,7 +35,7 @@ func (d *Daemon) createServiceWithOptions(ctx context.Context, t testing.TB, opt |
| 35 | 35 |
// CreateService creates a swarm service given the specified service constructor |
| 36 | 36 |
func (d *Daemon) CreateService(ctx context.Context, t testing.TB, f ...ServiceConstructor) string {
|
| 37 | 37 |
t.Helper() |
| 38 |
- return d.createServiceWithOptions(ctx, t, swarm.ServiceCreateOptions{}, f...)
|
|
| 38 |
+ return d.createServiceWithOptions(ctx, t, client.ServiceCreateOptions{}, f...)
|
|
| 39 | 39 |
} |
| 40 | 40 |
|
| 41 | 41 |
// GetService returns the swarm service corresponding to the specified id |
| ... | ... |
@@ -205,21 +205,6 @@ type JobStatus struct {
|
| 205 | 205 |
LastExecution time.Time `json:",omitempty"` |
| 206 | 206 |
} |
| 207 | 207 |
|
| 208 |
-// ServiceCreateOptions contains the options to use when creating a service. |
|
| 209 |
-type ServiceCreateOptions struct {
|
|
| 210 |
- // EncodedRegistryAuth is the encoded registry authorization credentials to |
|
| 211 |
- // use when updating the service. |
|
| 212 |
- // |
|
| 213 |
- // This field follows the format of the X-Registry-Auth header. |
|
| 214 |
- EncodedRegistryAuth string |
|
| 215 |
- |
|
| 216 |
- // QueryRegistry indicates whether the service update requires |
|
| 217 |
- // contacting a registry. A registry may be contacted to retrieve |
|
| 218 |
- // the image digest and manifest, which in turn can be used to update |
|
| 219 |
- // platform or other information about the service. |
|
| 220 |
- QueryRegistry bool |
|
| 221 |
-} |
|
| 222 |
- |
|
| 223 | 208 |
// Values for RegistryAuthFrom in ServiceUpdateOptions |
| 224 | 209 |
const ( |
| 225 | 210 |
RegistryAuthFromSpec = "spec" |
| ... | ... |
@@ -162,7 +162,7 @@ type PluginAPIClient interface {
|
| 162 | 162 |
|
| 163 | 163 |
// ServiceAPIClient defines API client methods for the services |
| 164 | 164 |
type ServiceAPIClient interface {
|
| 165 |
- ServiceCreate(ctx context.Context, service swarm.ServiceSpec, options swarm.ServiceCreateOptions) (swarm.ServiceCreateResponse, error) |
|
| 165 |
+ ServiceCreate(ctx context.Context, service swarm.ServiceSpec, options ServiceCreateOptions) (swarm.ServiceCreateResponse, error) |
|
| 166 | 166 |
ServiceInspectWithRaw(ctx context.Context, serviceID string, options swarm.ServiceInspectOptions) (swarm.Service, []byte, error) |
| 167 | 167 |
ServiceList(ctx context.Context, options swarm.ServiceListOptions) ([]swarm.Service, error) |
| 168 | 168 |
ServiceRemove(ctx context.Context, serviceID string) error |
| ... | ... |
@@ -16,7 +16,7 @@ import ( |
| 16 | 16 |
) |
| 17 | 17 |
|
| 18 | 18 |
// ServiceCreate creates a new service. |
| 19 |
-func (cli *Client) ServiceCreate(ctx context.Context, service swarm.ServiceSpec, options swarm.ServiceCreateOptions) (swarm.ServiceCreateResponse, error) {
|
|
| 19 |
+func (cli *Client) ServiceCreate(ctx context.Context, service swarm.ServiceSpec, options ServiceCreateOptions) (swarm.ServiceCreateResponse, error) {
|
|
| 20 | 20 |
var response swarm.ServiceCreateResponse |
| 21 | 21 |
|
| 22 | 22 |
// Make sure we negotiated (if the client is configured to do so), |
| 23 | 23 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,16 @@ |
| 0 |
+package client |
|
| 1 |
+ |
|
| 2 |
+// ServiceCreateOptions contains the options to use when creating a service. |
|
| 3 |
+type ServiceCreateOptions struct {
|
|
| 4 |
+ // EncodedRegistryAuth is the encoded registry authorization credentials to |
|
| 5 |
+ // use when updating the service. |
|
| 6 |
+ // |
|
| 7 |
+ // This field follows the format of the X-Registry-Auth header. |
|
| 8 |
+ EncodedRegistryAuth string |
|
| 9 |
+ |
|
| 10 |
+ // QueryRegistry indicates whether the service update requires |
|
| 11 |
+ // contacting a registry. A registry may be contacted to retrieve |
|
| 12 |
+ // the image digest and manifest, which in turn can be used to update |
|
| 13 |
+ // platform or other information about the service. |
|
| 14 |
+ QueryRegistry bool |
|
| 15 |
+} |