From c662ba03de5201d9a03c20fc723968898bb3867e Mon Sep 17 00:00:00 2001 From: Sune Keller Date: Thu, 28 Mar 2019 16:16:54 +0100 Subject: [PATCH] Make use of driver and driver_opts fields in secrets Signed-off-by: Sune Keller --- cli/compose/convert/compose.go | 30 +++++++++++++++++++++++++++++- cli/compose/loader/loader.go | 9 +++++++-- cli/compose/types/types.go | 2 ++ 3 files changed, 38 insertions(+), 3 deletions(-) diff --git a/cli/compose/convert/compose.go b/cli/compose/convert/compose.go index 0d19ae1fdf..983e7b52ea 100644 --- a/cli/compose/convert/compose.go +++ b/cli/compose/convert/compose.go @@ -106,11 +106,23 @@ func Secrets(namespace Namespace, secrets map[string]composetypes.SecretConfig) continue } - obj, err := fileObjectConfig(namespace, name, composetypes.FileObjectConfig(secret)) + var obj swarmFileObject + var err error + if secret.Driver != "" { + obj, err = driverObjectConfig(namespace, name, composetypes.FileObjectConfig(secret)) + } else { + obj, err = fileObjectConfig(namespace, name, composetypes.FileObjectConfig(secret)) + } if err != nil { return nil, err } spec := swarm.SecretSpec{Annotations: obj.Annotations, Data: obj.Data} + if secret.Driver != "" { + spec.Driver = &swarm.Driver{ + Name: secret.Driver, + Options: secret.DriverOpts, + } + } if secret.TemplateDriver != "" { spec.Templating = &swarm.Driver{ Name: secret.TemplateDriver, @@ -149,6 +161,22 @@ type swarmFileObject struct { Data []byte } +func driverObjectConfig(namespace Namespace, name string, obj composetypes.FileObjectConfig) (swarmFileObject, error) { + if obj.Name != "" { + name = obj.Name + } else { + name = namespace.Scope(name) + } + + return swarmFileObject{ + Annotations: swarm.Annotations{ + Name: name, + Labels: AddStackLabel(namespace, obj.Labels), + }, + Data: []byte{}, + }, nil +} + func fileObjectConfig(namespace Namespace, name string, obj composetypes.FileObjectConfig) (swarmFileObject, error) { data, err := ioutil.ReadFile(obj.File) if err != nil { diff --git a/cli/compose/loader/loader.go b/cli/compose/loader/loader.go index a3df518b31..f5787126c9 100644 --- a/cli/compose/loader/loader.go +++ b/cli/compose/loader/loader.go @@ -634,7 +634,8 @@ func LoadConfigObjs(source map[string]interface{}, details types.ConfigDetails) func loadFileObjectConfig(name string, objType string, obj types.FileObjectConfig, details types.ConfigDetails) (types.FileObjectConfig, error) { // if "external: true" - if obj.External.External { + switch { + case obj.External.External: // handle deprecated external.name if obj.External.Name != "" { if obj.Name != "" { @@ -651,7 +652,11 @@ func loadFileObjectConfig(name string, objType string, obj types.FileObjectConfi } } // if not "external: true" - } else { + case obj.Driver != "": + if obj.File != "" { + return obj, errors.Errorf("%[1]s %[2]s: %[1]s.driver and %[1]s.file conflict; only use %[1]s.driver", objType, name) + } + default: obj.File = absPath(details.WorkingDir, obj.File) } diff --git a/cli/compose/types/types.go b/cli/compose/types/types.go index 8185f836c8..0895a4d04d 100644 --- a/cli/compose/types/types.go +++ b/cli/compose/types/types.go @@ -513,6 +513,8 @@ type FileObjectConfig struct { External External `yaml:",omitempty" json:"external,omitempty"` Labels Labels `yaml:",omitempty" json:"labels,omitempty"` Extras map[string]interface{} `yaml:",inline" json:"-"` + Driver string `yaml:",omitempty" json:"driver,omitempty"` + DriverOpts map[string]string `mapstructure:"driver_opts" yaml:"driver_opts,omitempty" json:"driver_opts,omitempty"` TemplateDriver string `mapstructure:"template_driver" yaml:"template_driver,omitempty" json:"template_driver,omitempty"` }