Make use of driver and driver_opts fields in secrets

Signed-off-by: Sune Keller <absukl@almbrand.dk>
This commit is contained in:
Sune Keller 2019-03-28 16:16:54 +01:00 committed by Sune Keller
parent 89f9d806ff
commit c662ba03de
3 changed files with 38 additions and 3 deletions

View File

@ -106,11 +106,23 @@ func Secrets(namespace Namespace, secrets map[string]composetypes.SecretConfig)
continue 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 { if err != nil {
return nil, err return nil, err
} }
spec := swarm.SecretSpec{Annotations: obj.Annotations, Data: obj.Data} 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 != "" { if secret.TemplateDriver != "" {
spec.Templating = &swarm.Driver{ spec.Templating = &swarm.Driver{
Name: secret.TemplateDriver, Name: secret.TemplateDriver,
@ -149,6 +161,22 @@ type swarmFileObject struct {
Data []byte 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) { func fileObjectConfig(namespace Namespace, name string, obj composetypes.FileObjectConfig) (swarmFileObject, error) {
data, err := ioutil.ReadFile(obj.File) data, err := ioutil.ReadFile(obj.File)
if err != nil { if err != nil {

View File

@ -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) { func loadFileObjectConfig(name string, objType string, obj types.FileObjectConfig, details types.ConfigDetails) (types.FileObjectConfig, error) {
// if "external: true" // if "external: true"
if obj.External.External { switch {
case obj.External.External:
// handle deprecated external.name // handle deprecated external.name
if obj.External.Name != "" { if obj.External.Name != "" {
if obj.Name != "" { if obj.Name != "" {
@ -651,7 +652,11 @@ func loadFileObjectConfig(name string, objType string, obj types.FileObjectConfi
} }
} }
// if not "external: true" // 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) obj.File = absPath(details.WorkingDir, obj.File)
} }

View File

@ -513,6 +513,8 @@ type FileObjectConfig struct {
External External `yaml:",omitempty" json:"external,omitempty"` External External `yaml:",omitempty" json:"external,omitempty"`
Labels Labels `yaml:",omitempty" json:"labels,omitempty"` Labels Labels `yaml:",omitempty" json:"labels,omitempty"`
Extras map[string]interface{} `yaml:",inline" json:"-"` 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"` TemplateDriver string `mapstructure:"template_driver" yaml:"template_driver,omitempty" json:"template_driver,omitempty"`
} }