|
@@ -12,9 +12,10 @@ import (
|
|
"time"
|
|
"time"
|
|
|
|
|
|
"github.com/docker/distribution/reference"
|
|
"github.com/docker/distribution/reference"
|
|
- apitypes "github.com/docker/docker/api/types"
|
|
|
|
|
|
+ "github.com/docker/docker/api/types"
|
|
"github.com/docker/docker/api/types/backend"
|
|
"github.com/docker/docker/api/types/backend"
|
|
- types "github.com/docker/docker/api/types/swarm"
|
|
|
|
|
|
+ "github.com/docker/docker/api/types/registry"
|
|
|
|
+ "github.com/docker/docker/api/types/swarm"
|
|
timetypes "github.com/docker/docker/api/types/time"
|
|
timetypes "github.com/docker/docker/api/types/time"
|
|
"github.com/docker/docker/daemon/cluster/convert"
|
|
"github.com/docker/docker/daemon/cluster/convert"
|
|
"github.com/docker/docker/errdefs"
|
|
"github.com/docker/docker/errdefs"
|
|
@@ -27,7 +28,7 @@ import (
|
|
)
|
|
)
|
|
|
|
|
|
// GetServices returns all services of a managed swarm cluster.
|
|
// GetServices returns all services of a managed swarm cluster.
|
|
-func (c *Cluster) GetServices(options apitypes.ServiceListOptions) ([]types.Service, error) {
|
|
|
|
|
|
+func (c *Cluster) GetServices(options types.ServiceListOptions) ([]swarm.Service, error) {
|
|
c.mu.RLock()
|
|
c.mu.RLock()
|
|
defer c.mu.RUnlock()
|
|
defer c.mu.RUnlock()
|
|
|
|
|
|
@@ -53,7 +54,7 @@ func (c *Cluster) GetServices(options apitypes.ServiceListOptions) ([]types.Serv
|
|
|
|
|
|
if len(options.Filters.Get("runtime")) == 0 {
|
|
if len(options.Filters.Get("runtime")) == 0 {
|
|
// Default to using the container runtime filter
|
|
// Default to using the container runtime filter
|
|
- options.Filters.Add("runtime", string(types.RuntimeContainer))
|
|
|
|
|
|
+ options.Filters.Add("runtime", string(swarm.RuntimeContainer))
|
|
}
|
|
}
|
|
|
|
|
|
filters := &swarmapi.ListServicesRequest_Filters{
|
|
filters := &swarmapi.ListServicesRequest_Filters{
|
|
@@ -75,7 +76,7 @@ func (c *Cluster) GetServices(options apitypes.ServiceListOptions) ([]types.Serv
|
|
return nil, err
|
|
return nil, err
|
|
}
|
|
}
|
|
|
|
|
|
- services := make([]types.Service, 0, len(r.Services))
|
|
|
|
|
|
+ services := make([]swarm.Service, 0, len(r.Services))
|
|
|
|
|
|
// if the user requests the service statuses, we'll store the IDs needed
|
|
// if the user requests the service statuses, we'll store the IDs needed
|
|
// in this slice
|
|
// in this slice
|
|
@@ -132,9 +133,9 @@ func (c *Cluster) GetServices(options apitypes.ServiceListOptions) ([]types.Serv
|
|
// result would be quadratic. instead, make a mapping of service IDs to
|
|
// result would be quadratic. instead, make a mapping of service IDs to
|
|
// service statuses so that this is roughly linear. additionally,
|
|
// service statuses so that this is roughly linear. additionally,
|
|
// convert the status response to an engine api service status here.
|
|
// convert the status response to an engine api service status here.
|
|
- serviceMap := map[string]*types.ServiceStatus{}
|
|
|
|
|
|
+ serviceMap := map[string]*swarm.ServiceStatus{}
|
|
for _, status := range resp.Statuses {
|
|
for _, status := range resp.Statuses {
|
|
- serviceMap[status.ServiceID] = &types.ServiceStatus{
|
|
|
|
|
|
+ serviceMap[status.ServiceID] = &swarm.ServiceStatus{
|
|
RunningTasks: status.RunningTasks,
|
|
RunningTasks: status.RunningTasks,
|
|
DesiredTasks: status.DesiredTasks,
|
|
DesiredTasks: status.DesiredTasks,
|
|
CompletedTasks: status.CompletedTasks,
|
|
CompletedTasks: status.CompletedTasks,
|
|
@@ -159,7 +160,7 @@ func (c *Cluster) GetServices(options apitypes.ServiceListOptions) ([]types.Serv
|
|
}
|
|
}
|
|
|
|
|
|
// GetService returns a service based on an ID or name.
|
|
// GetService returns a service based on an ID or name.
|
|
-func (c *Cluster) GetService(input string, insertDefaults bool) (types.Service, error) {
|
|
|
|
|
|
+func (c *Cluster) GetService(input string, insertDefaults bool) (swarm.Service, error) {
|
|
var service *swarmapi.Service
|
|
var service *swarmapi.Service
|
|
if err := c.lockedManagerAction(func(ctx context.Context, state nodeState) error {
|
|
if err := c.lockedManagerAction(func(ctx context.Context, state nodeState) error {
|
|
s, err := getService(ctx, state.controlClient, input, insertDefaults)
|
|
s, err := getService(ctx, state.controlClient, input, insertDefaults)
|
|
@@ -169,18 +170,18 @@ func (c *Cluster) GetService(input string, insertDefaults bool) (types.Service,
|
|
service = s
|
|
service = s
|
|
return nil
|
|
return nil
|
|
}); err != nil {
|
|
}); err != nil {
|
|
- return types.Service{}, err
|
|
|
|
|
|
+ return swarm.Service{}, err
|
|
}
|
|
}
|
|
svc, err := convert.ServiceFromGRPC(*service)
|
|
svc, err := convert.ServiceFromGRPC(*service)
|
|
if err != nil {
|
|
if err != nil {
|
|
- return types.Service{}, err
|
|
|
|
|
|
+ return swarm.Service{}, err
|
|
}
|
|
}
|
|
return svc, nil
|
|
return svc, nil
|
|
}
|
|
}
|
|
|
|
|
|
// CreateService creates a new service in a managed swarm cluster.
|
|
// CreateService creates a new service in a managed swarm cluster.
|
|
-func (c *Cluster) CreateService(s types.ServiceSpec, encodedAuth string, queryRegistry bool) (*apitypes.ServiceCreateResponse, error) {
|
|
|
|
- var resp *apitypes.ServiceCreateResponse
|
|
|
|
|
|
+func (c *Cluster) CreateService(s swarm.ServiceSpec, encodedAuth string, queryRegistry bool) (*types.ServiceCreateResponse, error) {
|
|
|
|
+ var resp *types.ServiceCreateResponse
|
|
err := c.lockedManagerAction(func(ctx context.Context, state nodeState) error {
|
|
err := c.lockedManagerAction(func(ctx context.Context, state nodeState) error {
|
|
err := c.populateNetworkID(ctx, state.controlClient, &s)
|
|
err := c.populateNetworkID(ctx, state.controlClient, &s)
|
|
if err != nil {
|
|
if err != nil {
|
|
@@ -192,17 +193,17 @@ func (c *Cluster) CreateService(s types.ServiceSpec, encodedAuth string, queryRe
|
|
return errdefs.InvalidParameter(err)
|
|
return errdefs.InvalidParameter(err)
|
|
}
|
|
}
|
|
|
|
|
|
- resp = &apitypes.ServiceCreateResponse{}
|
|
|
|
|
|
+ resp = &types.ServiceCreateResponse{}
|
|
|
|
|
|
switch serviceSpec.Task.Runtime.(type) {
|
|
switch serviceSpec.Task.Runtime.(type) {
|
|
case *swarmapi.TaskSpec_Attachment:
|
|
case *swarmapi.TaskSpec_Attachment:
|
|
- return fmt.Errorf("invalid task spec: spec type %q not supported", types.RuntimeNetworkAttachment)
|
|
|
|
|
|
+ return fmt.Errorf("invalid task spec: spec type %q not supported", swarm.RuntimeNetworkAttachment)
|
|
// handle other runtimes here
|
|
// handle other runtimes here
|
|
case *swarmapi.TaskSpec_Generic:
|
|
case *swarmapi.TaskSpec_Generic:
|
|
switch serviceSpec.Task.GetGeneric().Kind {
|
|
switch serviceSpec.Task.GetGeneric().Kind {
|
|
- case string(types.RuntimePlugin):
|
|
|
|
|
|
+ case string(swarm.RuntimePlugin):
|
|
if !c.config.Backend.HasExperimental() {
|
|
if !c.config.Backend.HasExperimental() {
|
|
- return fmt.Errorf("runtime type %q only supported in experimental", types.RuntimePlugin)
|
|
|
|
|
|
+ return fmt.Errorf("runtime type %q only supported in experimental", swarm.RuntimePlugin)
|
|
}
|
|
}
|
|
if s.TaskTemplate.PluginSpec == nil {
|
|
if s.TaskTemplate.PluginSpec == nil {
|
|
return errors.New("plugin spec must be set")
|
|
return errors.New("plugin spec must be set")
|
|
@@ -228,7 +229,7 @@ func (c *Cluster) CreateService(s types.ServiceSpec, encodedAuth string, queryRe
|
|
}
|
|
}
|
|
|
|
|
|
// retrieve auth config from encoded auth
|
|
// retrieve auth config from encoded auth
|
|
- authConfig := &apitypes.AuthConfig{}
|
|
|
|
|
|
+ authConfig := ®istry.AuthConfig{}
|
|
if encodedAuth != "" {
|
|
if encodedAuth != "" {
|
|
authReader := strings.NewReader(encodedAuth)
|
|
authReader := strings.NewReader(encodedAuth)
|
|
dec := json.NewDecoder(base64.NewDecoder(base64.URLEncoding, authReader))
|
|
dec := json.NewDecoder(base64.NewDecoder(base64.URLEncoding, authReader))
|
|
@@ -282,8 +283,8 @@ func (c *Cluster) CreateService(s types.ServiceSpec, encodedAuth string, queryRe
|
|
}
|
|
}
|
|
|
|
|
|
// UpdateService updates existing service to match new properties.
|
|
// UpdateService updates existing service to match new properties.
|
|
-func (c *Cluster) UpdateService(serviceIDOrName string, version uint64, spec types.ServiceSpec, flags apitypes.ServiceUpdateOptions, queryRegistry bool) (*apitypes.ServiceUpdateResponse, error) {
|
|
|
|
- var resp *apitypes.ServiceUpdateResponse
|
|
|
|
|
|
+func (c *Cluster) UpdateService(serviceIDOrName string, version uint64, spec swarm.ServiceSpec, flags types.ServiceUpdateOptions, queryRegistry bool) (*types.ServiceUpdateResponse, error) {
|
|
|
|
+ var resp *types.ServiceUpdateResponse
|
|
|
|
|
|
err := c.lockedManagerAction(func(ctx context.Context, state nodeState) error {
|
|
err := c.lockedManagerAction(func(ctx context.Context, state nodeState) error {
|
|
|
|
|
|
@@ -302,14 +303,14 @@ func (c *Cluster) UpdateService(serviceIDOrName string, version uint64, spec typ
|
|
return err
|
|
return err
|
|
}
|
|
}
|
|
|
|
|
|
- resp = &apitypes.ServiceUpdateResponse{}
|
|
|
|
|
|
+ resp = &types.ServiceUpdateResponse{}
|
|
|
|
|
|
switch serviceSpec.Task.Runtime.(type) {
|
|
switch serviceSpec.Task.Runtime.(type) {
|
|
case *swarmapi.TaskSpec_Attachment:
|
|
case *swarmapi.TaskSpec_Attachment:
|
|
- return fmt.Errorf("invalid task spec: spec type %q not supported", types.RuntimeNetworkAttachment)
|
|
|
|
|
|
+ return fmt.Errorf("invalid task spec: spec type %q not supported", swarm.RuntimeNetworkAttachment)
|
|
case *swarmapi.TaskSpec_Generic:
|
|
case *swarmapi.TaskSpec_Generic:
|
|
switch serviceSpec.Task.GetGeneric().Kind {
|
|
switch serviceSpec.Task.GetGeneric().Kind {
|
|
- case string(types.RuntimePlugin):
|
|
|
|
|
|
+ case string(swarm.RuntimePlugin):
|
|
if spec.TaskTemplate.PluginSpec == nil {
|
|
if spec.TaskTemplate.PluginSpec == nil {
|
|
return errors.New("plugin spec must be set")
|
|
return errors.New("plugin spec must be set")
|
|
}
|
|
}
|
|
@@ -328,9 +329,9 @@ func (c *Cluster) UpdateService(serviceIDOrName string, version uint64, spec typ
|
|
// shouldn't lose it, and continue to use the one that was already present
|
|
// shouldn't lose it, and continue to use the one that was already present
|
|
var ctnr *swarmapi.ContainerSpec
|
|
var ctnr *swarmapi.ContainerSpec
|
|
switch flags.RegistryAuthFrom {
|
|
switch flags.RegistryAuthFrom {
|
|
- case apitypes.RegistryAuthFromSpec, "":
|
|
|
|
|
|
+ case types.RegistryAuthFromSpec, "":
|
|
ctnr = currentService.Spec.Task.GetContainer()
|
|
ctnr = currentService.Spec.Task.GetContainer()
|
|
- case apitypes.RegistryAuthFromPreviousSpec:
|
|
|
|
|
|
+ case types.RegistryAuthFromPreviousSpec:
|
|
if currentService.PreviousSpec == nil {
|
|
if currentService.PreviousSpec == nil {
|
|
return errors.New("service does not have a previous spec")
|
|
return errors.New("service does not have a previous spec")
|
|
}
|
|
}
|
|
@@ -349,7 +350,7 @@ func (c *Cluster) UpdateService(serviceIDOrName string, version uint64, spec typ
|
|
}
|
|
}
|
|
|
|
|
|
// retrieve auth config from encoded auth
|
|
// retrieve auth config from encoded auth
|
|
- authConfig := &apitypes.AuthConfig{}
|
|
|
|
|
|
+ authConfig := ®istry.AuthConfig{}
|
|
if encodedAuth != "" {
|
|
if encodedAuth != "" {
|
|
if err := json.NewDecoder(base64.NewDecoder(base64.URLEncoding, strings.NewReader(encodedAuth))).Decode(authConfig); err != nil {
|
|
if err := json.NewDecoder(base64.NewDecoder(base64.URLEncoding, strings.NewReader(encodedAuth))).Decode(authConfig); err != nil {
|
|
logrus.Warnf("invalid authconfig: %v", err)
|
|
logrus.Warnf("invalid authconfig: %v", err)
|
|
@@ -425,7 +426,7 @@ func (c *Cluster) RemoveService(input string) error {
|
|
}
|
|
}
|
|
|
|
|
|
// ServiceLogs collects service logs and writes them back to `config.OutStream`
|
|
// ServiceLogs collects service logs and writes them back to `config.OutStream`
|
|
-func (c *Cluster) ServiceLogs(ctx context.Context, selector *backend.LogSelector, config *apitypes.ContainerLogsOptions) (<-chan *backend.LogMessage, error) {
|
|
|
|
|
|
+func (c *Cluster) ServiceLogs(ctx context.Context, selector *backend.LogSelector, config *types.ContainerLogsOptions) (<-chan *backend.LogMessage, error) {
|
|
c.mu.RLock()
|
|
c.mu.RLock()
|
|
defer c.mu.RUnlock()
|
|
defer c.mu.RUnlock()
|
|
|
|
|
|
@@ -612,7 +613,7 @@ func convertSelector(ctx context.Context, cc swarmapi.ControlClient, selector *b
|
|
|
|
|
|
// imageWithDigestString takes an image such as name or name:tag
|
|
// imageWithDigestString takes an image such as name or name:tag
|
|
// and returns the image pinned to a digest, such as name@sha256:34234
|
|
// and returns the image pinned to a digest, such as name@sha256:34234
|
|
-func (c *Cluster) imageWithDigestString(ctx context.Context, image string, authConfig *apitypes.AuthConfig) (string, error) {
|
|
|
|
|
|
+func (c *Cluster) imageWithDigestString(ctx context.Context, image string, authConfig *registry.AuthConfig) (string, error) {
|
|
ref, err := reference.ParseAnyReference(image)
|
|
ref, err := reference.ParseAnyReference(image)
|
|
if err != nil {
|
|
if err != nil {
|
|
return "", err
|
|
return "", err
|