Skip to content
This repository has been archived by the owner on Mar 22, 2022. It is now read-only.

Commit

Permalink
Fix minor bugs on config&secrets
Browse files Browse the repository at this point in the history
- Fix name collision between configs and secrets
- Fix source reference by not interpreting a non existent
reference as a file

Signed-off-by: Ulysses Souza <[email protected]>
  • Loading branch information
ulyssessouza authored and ndeloof committed Feb 17, 2020
1 parent e5028f2 commit 4f1e64e
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions internal/volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,26 @@ func GetVolumesFromConfig(cli *client.Client, project string, config *compose.Co
return nil
}

var fakeBindings = make(map[string]string) // Mapping on Map[ConfigName]File
var fakeConfigBindings = make(map[string]string) // Mapping on Map[ConfigName]File
func GetConfigsFromConfig(prjDir string, config *compose.Config) error {
for k, v := range config.Configs {
name := k
if v.Name != "" {
name = v.Name
}
fakeBindings[name] = v.File
fakeConfigBindings[name] = v.File
}
return nil
}

var fakeSecretBindings = make(map[string]string) // Mapping on Map[SecretName]File
func GetSecretsFromConfig(prjDir string, config *compose.Config) error {
for k, v := range config.Secrets {
name := k
if v.Name != "" {
name = v.Name
}
fakeBindings[name] = v.File
fakeSecretBindings[name] = v.File
}
return nil
}
Expand Down Expand Up @@ -141,23 +142,23 @@ func CreateContainerConfigMounts(s compose.ServiceConfig, prjDir string) ([]moun
for _, f := range s.Configs {
fileRefs = append(fileRefs, compose.FileReferenceConfig(f))
}
return createFakeMounts(fileRefs, prjDir)
return createFakeMounts(fileRefs, fakeConfigBindings, prjDir)
}

func CreateContainerSecretMounts(s compose.ServiceConfig, prjDir string) ([]mount.Mount, error) {
var fileRefs []compose.FileReferenceConfig
for _, f := range s.Secrets {
fileRefs = append(fileRefs, compose.FileReferenceConfig(f))
}
return createFakeMounts(fileRefs, prjDir)
return createFakeMounts(fileRefs, fakeSecretBindings, prjDir)
}

func createFakeMounts(fileRefs []compose.FileReferenceConfig, prjDir string) ([]mount.Mount, error) {
func createFakeMounts(fileRefs []compose.FileReferenceConfig, fakeBindings map[string]string, prjDir string) ([]mount.Mount, error) {
var mounts []mount.Mount
for _, v := range fileRefs {
source, ok := fakeBindings[v.Source]
if !ok {
source = v.Source
return nil, fmt.Errorf("couldn't find reference %q", v.Source)
}
target := v.Target
if target == "" {
Expand Down

0 comments on commit 4f1e64e

Please sign in to comment.