Add support for `template_driver` in composefiles

This maps the `--template-driver` flag on secret and config creation.

Signed-off-by: Vincent Demeester <vincent@sbr.pm>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Vincent Demeester 2018-06-27 14:05:51 +02:00 committed by Sebastiaan van Stijn
parent 8c3a619d13
commit 7764101a54
No known key found for this signature in database
GPG Key ID: 76698F39D527CE8C
5 changed files with 122 additions and 46 deletions

View File

@ -110,7 +110,13 @@ func Secrets(namespace Namespace, secrets map[string]composetypes.SecretConfig)
if err != nil {
return nil, err
}
result = append(result, swarm.SecretSpec{Annotations: obj.Annotations, Data: obj.Data})
spec := swarm.SecretSpec{Annotations: obj.Annotations, Data: obj.Data}
if secret.TemplateDriver != "" {
spec.Templating = &swarm.Driver{
Name: secret.TemplateDriver,
}
}
result = append(result, spec)
}
return result, nil
}
@ -127,7 +133,13 @@ func Configs(namespace Namespace, configs map[string]composetypes.ConfigObjConfi
if err != nil {
return nil, err
}
result = append(result, swarm.ConfigSpec{Annotations: obj.Annotations, Data: obj.Data})
spec := swarm.ConfigSpec{Annotations: obj.Annotations, Data: obj.Data}
if config.TemplateDriver != "" {
spec.Templating = &swarm.Driver{
Name: config.TemplateDriver,
}
}
result = append(result, spec)
}
return result, nil
}

View File

@ -1484,3 +1484,64 @@ func TestTransform(t *testing.T) {
assert.Check(t, is.DeepEqual(samplePortsConfig, ports))
}
func TestLoadTemplateDriver(t *testing.T) {
config, err := loadYAML(`
version: '3.8'
services:
hello-world:
image: redis:alpine
secrets:
- secret
configs:
- config
configs:
config:
name: config
external: true
template_driver: config-driver
secrets:
secret:
name: secret
external: true
template_driver: secret-driver
`)
assert.NilError(t, err)
expected := &types.Config{
Filename: "filename.yml",
Version: "3.8",
Services: types.Services{
{
Name: "hello-world",
Image: "redis:alpine",
Configs: []types.ServiceConfigObjConfig{
{
Source: "config",
},
},
Secrets: []types.ServiceSecretConfig{
{
Source: "secret",
},
},
},
},
Configs: map[string]types.ConfigObjConfig{
"config": {
Name: "config",
External: types.External{External: true},
TemplateDriver: "config-driver",
},
},
Secrets: map[string]types.SecretConfig{
"secret": {
Name: "secret",
External: types.External{External: true},
TemplateDriver: "secret-driver",
},
},
}
assert.DeepEqual(t, config, expected, cmpopts.EquateEmpty())
}

View File

@ -510,45 +510,45 @@ bnBpPlHfjORjkTRf1wyAwiYqMXd9/G6313QfoXs6/sbZ66r6e179PwAA//8ZL3SpvkUAAA==
"/data/config_schema_v3.8.json": {
local: "data/config_schema_v3.8.json",
size: 17912,
size: 18006,
modtime: 1518458244,
compressed: `
H4sIAAAAAAAC/+xcS4/bOBK++1cImrlNPwLsYLGb2x73tHvehiPQVNnmNEVyipTTTuD/vtCzJYoUaVtO
dzAdIEi3VHzUk18VS/m+SpL0V033UJD0c5LujVGfHx//0FLcN08fJO4ecyRbc//p98fm2S/pXTWO5dUQ
KsWW7bLmTXb428M/HqrhDYk5KqiI5OYPoKZ5hvBnyRCqwU/pAVAzKdL13ap6p1AqQMNAp5+TanNJ0pN0
DwbTaoNM7NL68ameIUlSDXhgdDBDv9VfHl/nf+zJ7uxZB5utnytiDKD473Rv9esvT+T+27/u//fp/p8P
2f36t19Hryv5Imyb5XPYMsEMk6JfP+0pT+1Pp35hkuc1MeGjtbeEaxjzLMB8lfgc4rkneyOe2/UdPI/Z
OUheFkENdlRvxEyz/DL600ARTNhkG6o3s9hq+WUYbqJGiOGO6o0Ybpa/juFVx7R7j+mXl/vq31M95+x8
zSyD/dVMjGKeS5yumOOXZy9QjyRzUFwe6527ZdYQFCBM2ospSdJNyXhuS10K+E81xdPgYZJ8t8P7YJ76
/eg3v1H07z289O+pFAZeTM3U/NKNCCR9BtwyDrEjCDaW7hEZZ9pkErOcUeMcz8kG+FUzUEL3kG1RFsFZ
tlnDiXZO1EXwSM4NwR1ES1bvi0yzbyO5PqVMGNgBpnf92PXJGjuZLOyYtk9Xf9Yrx4QpJSojeT5igiCS
Y7UjZqDQbv6StBTszxL+3ZIYLMGeN0eplp94h7JUmSJY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aYPnypnS3qiKcr1mN9hDctaEmEuoN5Wi2UeM
57nS1VV+pwLihTI6yrV+ZyKX38+HWQuctuKEggXNrj1obZAwYc7uVbCPRSFsAUFQmDXLac5oJm+0XEJe
IZD8HUpGLm3rgGkF2DNhI1lXRvIStbniGweno5qLBKYDJiHlWO4Oefvl7JdvFVtSBAP9yq4eypAOzetP
+txmw4IuPj0QXkZUTy7qN/FlHSIGn5yfXIVk2pEtENrF9H9FNSC1VJlUy1dAwk1G63D+nSlSLOWbo1uy
Umeo8RG8brkRngT3jb3ucldu15vpkepTn8q6689qHS1ir2Est/86q2aXLV3pN2IMofuoTN2ZCZM3SHxO
Ev1Ol9ZSfXq0Mzzan13/P56utl+jBr94rKnCH5BeoaER34h8APkvIdZRBaBQnBjIZuzzDbRgcmc7taCl
+tSC/1EtsJqBBtowLUrNCSi6Y3k1rEH127DJHP9jhS9+827KV0K1Fm1lM8/5grfiwy8zOHnuy4IbAcwF
2jDdMrVSO6u+6dL+4N7verrxk8/vKz7FcVI0/TFuvGk+nV+Pzsciab76GcCQdVTY7/oo32776T6O93Qi
jmPjVfX3tPpvAAAA//+mJNa5VkYAAA==
`,
},

View File

@ -537,7 +537,8 @@
"name": {"type": "string"}
}
},
"labels": {"$ref": "#/definitions/list_or_dict"}
"labels": {"$ref": "#/definitions/list_or_dict"},
"template_driver": {"type": "string"}
},
"patternProperties": {"^x-": {}},
"additionalProperties": false
@ -555,7 +556,8 @@
"name": {"type": "string"}
}
},
"labels": {"$ref": "#/definitions/list_or_dict"}
"labels": {"$ref": "#/definitions/list_or_dict"},
"template_driver": {"type": "string"}
},
"patternProperties": {"^x-": {}},
"additionalProperties": false

View File

@ -503,11 +503,12 @@ type CredentialSpecConfig struct {
// FileObjectConfig is a config type for a file used by a service
type FileObjectConfig struct {
Name string `yaml:",omitempty" json:"name,omitempty"`
File string `yaml:",omitempty" json:"file,omitempty"`
External External `yaml:",omitempty" json:"external,omitempty"`
Labels Labels `yaml:",omitempty" json:"labels,omitempty"`
Extras map[string]interface{} `yaml:",inline" json:"-"`
Name string `yaml:",omitempty" json:"name,omitempty"`
File string `yaml:",omitempty" json:"file,omitempty"`
External External `yaml:",omitempty" json:"external,omitempty"`
Labels Labels `yaml:",omitempty" json:"labels,omitempty"`
Extras map[string]interface{} `yaml:",inline" json:"-"`
TemplateDriver string `mapstructure:"template_driver" yaml:"template_driver,omitempty" json:"template_driver,omitempty"`
}
// SecretConfig for a secret