зеркало из https://github.com/microsoft/docker.git
Merge pull request #32087 from dnephin/check-secrets-against-defined
Cleanup compose convert error messages
This commit is contained in:
Коммит
3c22c7d5e9
|
@ -14,6 +14,7 @@ import (
|
||||||
"github.com/docker/docker/client"
|
"github.com/docker/docker/client"
|
||||||
"github.com/docker/docker/opts"
|
"github.com/docker/docker/opts"
|
||||||
runconfigopts "github.com/docker/docker/runconfig/opts"
|
runconfigopts "github.com/docker/docker/runconfig/opts"
|
||||||
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
const defaultNetwork = "default"
|
const defaultNetwork = "default"
|
||||||
|
@ -35,11 +36,11 @@ func 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, err
|
return nil, errors.Wrapf(err, "service %s", service.Name)
|
||||||
}
|
}
|
||||||
serviceSpec, err := convertService(namespace, service, networks, volumes, secrets)
|
serviceSpec, err := convertService(namespace, service, networks, volumes, secrets)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, errors.Wrapf(err, "service %s", service.Name)
|
||||||
}
|
}
|
||||||
result[service.Name] = serviceSpec
|
result[service.Name] = serviceSpec
|
||||||
}
|
}
|
||||||
|
@ -68,7 +69,6 @@ func convertService(
|
||||||
|
|
||||||
mounts, err := Volumes(service.Volumes, volumes, namespace)
|
mounts, err := Volumes(service.Volumes, volumes, namespace)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// TODO: better error message (include service name)
|
|
||||||
return swarm.ServiceSpec{}, err
|
return swarm.ServiceSpec{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -167,8 +167,7 @@ func convertServiceNetworks(
|
||||||
for networkName, network := range networks {
|
for networkName, network := range networks {
|
||||||
networkConfig, ok := networkConfigs[networkName]
|
networkConfig, ok := networkConfigs[networkName]
|
||||||
if !ok && networkName != defaultNetwork {
|
if !ok && networkName != defaultNetwork {
|
||||||
return []swarm.NetworkAttachmentConfig{}, fmt.Errorf(
|
return nil, errors.Errorf("undefined network %q", networkName)
|
||||||
"service %q references network %q, which is not declared", name, networkName)
|
|
||||||
}
|
}
|
||||||
var aliases []string
|
var aliases []string
|
||||||
if network != nil {
|
if network != nil {
|
||||||
|
@ -202,8 +201,12 @@ func convertServiceSecrets(
|
||||||
target = secret.Source
|
target = secret.Source
|
||||||
}
|
}
|
||||||
|
|
||||||
|
secretSpec, exists := secretSpecs[secret.Source]
|
||||||
|
if !exists {
|
||||||
|
return nil, errors.Errorf("undefined secret %q", secret.Source)
|
||||||
|
}
|
||||||
|
|
||||||
source := namespace.Scope(secret.Source)
|
source := namespace.Scope(secret.Source)
|
||||||
secretSpec := secretSpecs[secret.Source]
|
|
||||||
if secretSpec.External.External {
|
if secretSpec.External.External {
|
||||||
source = secretSpec.External.Name
|
source = secretSpec.External.Name
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,7 +57,7 @@ func convertVolumeToMount(
|
||||||
|
|
||||||
stackVolume, exists := stackVolumes[volume.Source]
|
stackVolume, exists := stackVolumes[volume.Source]
|
||||||
if !exists {
|
if !exists {
|
||||||
return result, errors.Errorf("undefined volume: %s", volume.Source)
|
return result, errors.Errorf("undefined volume %q", volume.Source)
|
||||||
}
|
}
|
||||||
|
|
||||||
result.Source = namespace.Scope(volume.Source)
|
result.Source = namespace.Scope(volume.Source)
|
||||||
|
|
|
@ -188,5 +188,5 @@ func TestConvertVolumeToMountVolumeDoesNotExist(t *testing.T) {
|
||||||
ReadOnly: true,
|
ReadOnly: true,
|
||||||
}
|
}
|
||||||
_, err := convertVolumeToMount(config, volumes{}, namespace)
|
_, err := convertVolumeToMount(config, volumes{}, namespace)
|
||||||
assert.Error(t, err, "undefined volume: unknown")
|
assert.Error(t, err, "undefined volume \"unknown\"")
|
||||||
}
|
}
|
||||||
|
|
Загрузка…
Ссылка в новой задаче