Skip to content

Add support for template_driver in composefiles #1100

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -1463,3 +1463,64 @@ services:
})
}
}

func TestLoadTemplateDriver(t *testing.T) {
config, err := loadYAML(`
version: '3.7'
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.7",
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())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can simplify the test:

assert.Assert(t, is.Equal(config.Configs["config"].TemplateDriver, "config-driver"))
assert.Assert(t, is.Equal(config.Secrets["secret"].TemplateDriver, "secret-driver"))

}
73 changes: 37 additions & 36 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.7.json
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,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 @@ -550,7 +551,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 @@ -414,11 +414,12 @@ type CredentialSpecConfig struct {

// FileObjectConfig is a config type for a file used by a service
type FileObjectConfig struct {
Name string `yaml:",omitempty"`
File string `yaml:",omitempty"`
External External `yaml:",omitempty"`
Labels Labels `yaml:",omitempty"`
Extras map[string]interface{} `yaml:",inline"`
Name string `yaml:",omitempty"`
File string `yaml:",omitempty"`
External External `yaml:",omitempty"`
Labels Labels `yaml:",omitempty"`
Extras map[string]interface{} `yaml:",inline"`
TemplateDriver string `mapstructure:"template_driver" yaml:"template_driver,omitempty"`
}

// SecretConfig for a secret
Expand Down