mirror of https://github.com/docker/cli.git
cli: Deploying a compose file must use TaskTemplate.Networks
This is the non-deprecated field, and the one that can be changed in a service update. Since old daemon versions don't allow migrating from one field to the other, make this conditional on the API version. Signed-off-by: Aaron Lehmann <aaron.lehmann@docker.com>
This commit is contained in:
parent
808ca15347
commit
f804f893b6
|
@ -9,6 +9,7 @@ import (
|
||||||
|
|
||||||
"github.com/docker/docker/api/types/container"
|
"github.com/docker/docker/api/types/container"
|
||||||
"github.com/docker/docker/api/types/swarm"
|
"github.com/docker/docker/api/types/swarm"
|
||||||
|
"github.com/docker/docker/api/types/versions"
|
||||||
servicecli "github.com/docker/docker/cli/command/service"
|
servicecli "github.com/docker/docker/cli/command/service"
|
||||||
composetypes "github.com/docker/docker/cli/compose/types"
|
composetypes "github.com/docker/docker/cli/compose/types"
|
||||||
"github.com/docker/docker/client"
|
"github.com/docker/docker/client"
|
||||||
|
@ -20,11 +21,10 @@ import (
|
||||||
const defaultNetwork = "default"
|
const defaultNetwork = "default"
|
||||||
|
|
||||||
// Services from compose-file types to engine API types
|
// Services from compose-file types to engine API types
|
||||||
// TODO: fix secrets API so that SecretAPIClient is not required here
|
|
||||||
func Services(
|
func Services(
|
||||||
namespace Namespace,
|
namespace Namespace,
|
||||||
config *composetypes.Config,
|
config *composetypes.Config,
|
||||||
client client.SecretAPIClient,
|
client client.CommonAPIClient,
|
||||||
) (map[string]swarm.ServiceSpec, error) {
|
) (map[string]swarm.ServiceSpec, error) {
|
||||||
result := make(map[string]swarm.ServiceSpec)
|
result := make(map[string]swarm.ServiceSpec)
|
||||||
|
|
||||||
|
@ -33,12 +33,11 @@ func Services(
|
||||||
networks := config.Networks
|
networks := config.Networks
|
||||||
|
|
||||||
for _, service := range services {
|
for _, service := range services {
|
||||||
|
|
||||||
secrets, err := convertServiceSecrets(client, namespace, service.Secrets, config.Secrets)
|
secrets, err := convertServiceSecrets(client, namespace, service.Secrets, config.Secrets)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrapf(err, "service %s", service.Name)
|
return nil, errors.Wrapf(err, "service %s", service.Name)
|
||||||
}
|
}
|
||||||
serviceSpec, err := convertService(namespace, service, networks, volumes, secrets)
|
serviceSpec, err := convertService(client.ClientVersion(), namespace, service, networks, volumes, secrets)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrapf(err, "service %s", service.Name)
|
return nil, errors.Wrapf(err, "service %s", service.Name)
|
||||||
}
|
}
|
||||||
|
@ -49,6 +48,7 @@ func Services(
|
||||||
}
|
}
|
||||||
|
|
||||||
func convertService(
|
func convertService(
|
||||||
|
apiVersion string,
|
||||||
namespace Namespace,
|
namespace Namespace,
|
||||||
service composetypes.ServiceConfig,
|
service composetypes.ServiceConfig,
|
||||||
networkConfigs map[string]composetypes.NetworkConfig,
|
networkConfigs map[string]composetypes.NetworkConfig,
|
||||||
|
@ -133,10 +133,21 @@ func convertService(
|
||||||
},
|
},
|
||||||
EndpointSpec: endpoint,
|
EndpointSpec: endpoint,
|
||||||
Mode: mode,
|
Mode: mode,
|
||||||
Networks: networks,
|
|
||||||
UpdateConfig: convertUpdateConfig(service.Deploy.UpdateConfig),
|
UpdateConfig: convertUpdateConfig(service.Deploy.UpdateConfig),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ServiceSpec.Networks is deprecated and should not have been used by
|
||||||
|
// this package. It is possible to update TaskTemplate.Networks, but it
|
||||||
|
// is not possible to update ServiceSpec.Networks. Unfortunately, we
|
||||||
|
// can't unconditionally start using TaskTemplate.Networks, because that
|
||||||
|
// will break with older daemons that don't support migrating from
|
||||||
|
// ServiceSpec.Networks to TaskTemplate.Networks. So which field to use
|
||||||
|
// is conditional on daemon version.
|
||||||
|
if versions.LessThan(apiVersion, "1.29") {
|
||||||
|
serviceSpec.Networks = networks
|
||||||
|
} else {
|
||||||
|
serviceSpec.TaskTemplate.Networks = networks
|
||||||
|
}
|
||||||
return serviceSpec, nil
|
return serviceSpec, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue