Add secret.name and config.name in compose.

Signed-off-by: Ilya Sotkov <ilya@sotkov.com>
This commit is contained in:
Ilya Sotkov 2017-11-22 13:18:05 +02:00
parent 2d0e2d22ca
commit 4f7f3d2f61
6 changed files with 73 additions and 20 deletions

View File

@ -101,6 +101,12 @@ func Secrets(namespace Namespace, secrets map[string]composetypes.SecretConfig)
continue
}
if secret.Name != "" {
name = secret.Name
} else {
name = namespace.Scope(name)
}
obj, err := fileObjectConfig(namespace, name, composetypes.FileObjectConfig(secret))
if err != nil {
return nil, err
@ -118,6 +124,12 @@ func Configs(namespace Namespace, configs map[string]composetypes.ConfigObjConfi
continue
}
if config.Name != "" {
name = config.Name
} else {
name = namespace.Scope(name)
}
obj, err := fileObjectConfig(namespace, name, composetypes.FileObjectConfig(config))
if err != nil {
return nil, err
@ -140,7 +152,7 @@ func fileObjectConfig(namespace Namespace, name string, obj composetypes.FileObj
return swarmFileObject{
Annotations: swarm.Annotations{
Name: namespace.Scope(name),
Name: name,
Labels: AddStackLabel(namespace, obj.Labels),
},
Data: data,

View File

@ -258,14 +258,14 @@ func convertServiceSecrets(
refs := []*swarm.SecretReference{}
lookup := func(key string) (composetypes.FileObjectConfig, error) {
configSpec, exists := secretSpecs[key]
secretSpec, exists := secretSpecs[key]
if !exists {
return composetypes.FileObjectConfig{}, errors.Errorf("undefined secret %q", key)
}
return composetypes.FileObjectConfig(configSpec), nil
return composetypes.FileObjectConfig(secretSpec), nil
}
for _, config := range secrets {
obj, err := convertFileObject(namespace, composetypes.FileReferenceConfig(config), lookup)
for _, secret := range secrets {
obj, err := convertFileObject(namespace, composetypes.FileReferenceConfig(secret), lookup)
if err != nil {
return nil, err
}
@ -353,8 +353,8 @@ func convertFileObject(
}
source := namespace.Scope(config.Source)
if obj.External.External {
source = obj.External.Name
if obj.Name != "" {
source = obj.Name
}
uid := config.UID

View File

@ -490,7 +490,7 @@ func LoadSecrets(source map[string]interface{}, details types.ConfigDetails) (ma
return secrets, err
}
for name, secret := range secrets {
obj, err := loadFileObjectConfig(name, types.FileObjectConfig(secret), details)
obj, err := loadFileObjectConfig(name, "secret", types.FileObjectConfig(secret), details)
if err != nil {
return nil, err
}
@ -507,7 +507,7 @@ func LoadConfigObjs(source map[string]interface{}, details types.ConfigDetails)
return configs, err
}
for name, config := range configs {
obj, err := loadFileObjectConfig(name, types.FileObjectConfig(config), details)
obj, err := loadFileObjectConfig(name, "config", types.FileObjectConfig(config), details)
if err != nil {
return nil, err
}
@ -516,13 +516,32 @@ func LoadConfigObjs(source map[string]interface{}, details types.ConfigDetails)
return configs, nil
}
func loadFileObjectConfig(name string, obj types.FileObjectConfig, details types.ConfigDetails) (types.FileObjectConfig, error) {
if obj.External.External && obj.External.Name == "" {
obj.External.Name = name
func loadFileObjectConfig(name string, objType string, obj types.FileObjectConfig, details types.ConfigDetails) (types.FileObjectConfig, error) {
// if "external: true"
if obj.External.External {
// handle deprecated external.name
if obj.External.Name != "" {
if obj.Name != "" {
return obj, errors.Errorf("%[1]s %[2]s: %[1]s.external.name and %[1]s.name conflict; only use %[1]s.name", objType, name)
}
if versions.GreaterThanOrEqualTo(details.Version, "3.5") {
logrus.Warnf("%[1]s %[2]s: %[1]s.external.name is deprecated in favor of %[1]s.name", objType, name)
}
obj.Name = obj.External.Name
obj.External.Name = ""
} else {
if obj.Name == "" {
obj.Name = name
}
}
// if not "external: true"
} else {
if obj.File == "" {
return obj, errors.Errorf("%[1]s %[2]s: specify a file or \"external: true\"", objType, name)
}
if obj.File != "" {
obj.File = absPath(details.WorkingDir, obj.File)
}
return obj, nil
}

File diff suppressed because one or more lines are too long

View File

@ -470,6 +470,7 @@
"id": "#/definitions/secret",
"type": "object",
"properties": {
"name": {"type": "string"},
"file": {"type": "string"},
"external": {
"type": ["boolean", "object"],
@ -486,6 +487,7 @@
"id": "#/definitions/config",
"type": "object",
"properties": {
"name": {"type": "string"},
"file": {"type": "string"},
"external": {
"type": ["boolean", "object"],

View File

@ -348,6 +348,7 @@ type CredentialSpecConfig struct {
// FileObjectConfig is a config type for a file used by a service
type FileObjectConfig struct {
Name string
File string
External External
Labels Labels