Skip to content

Commit

Permalink
Merge pull request #1746 from thaJeztah/carry_compose_template_driver
Browse files Browse the repository at this point in the history
[carry] Add support for `template_driver` in composefiles
  • Loading branch information
vdemeester authored Mar 19, 2019
2 parents e4aa87f + 7764101 commit 2871b72
Show file tree
Hide file tree
Showing 5 changed files with 122 additions and 46 deletions.
16 changes: 14 additions & 2 deletions cli/compose/convert/compose.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
}
Expand Down
61 changes: 61 additions & 0 deletions cli/compose/loader/loader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
74 changes: 37 additions & 37 deletions cli/compose/schema/bindata.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions cli/compose/schema/data/config_schema_v3.8.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
11 changes: 6 additions & 5 deletions cli/compose/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 2871b72

Please sign in to comment.