Skip to content
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

Fix issue about read-only volume path and add support to absolute path at long syntax #3

Closed
wants to merge 2 commits into from
Closed
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
36 changes: 31 additions & 5 deletions pkg/transformer/kubernetes/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -566,17 +566,43 @@ func (k *Kubernetes) ConfigSecretVolumes(name string, service kobject.ServiceCon
log.Warnf("Ignore gid in secrets for service: %s", name)
}

target := secretConfig.Target
if target == "" {
target = secretConfig.Source
var itemPath string // should be the filename
var mountPath = "" // should be the directory
// if is used the short-syntax
if secretConfig.Target == "" {
// the secret path (mountPath) should be inside the default directory /run/secrets
mountPath = "/run/secrets/" + secretConfig.Source
// the itemPath should be the source itself
itemPath = secretConfig.Source
} else {
// if is the long-syntax, i should get the last part of path and consider it the filename
pathSplitted := strings.Split(secretConfig.Target, "/")
lastPart := pathSplitted[len(pathSplitted)-1]

// if the filename (lastPart) and the target is the same
if lastPart == secretConfig.Target {
// the secret path should be the source (it need to be inside a directory and only the filename was given)
mountPath = secretConfig.Source
} else {
// should then get the target without the filename (lastPart)
mountPath = mountPath + strings.TrimSuffix(secretConfig.Target, "/"+lastPart) // menos ultima parte
}

// if the target isn't absolute path
if strings.HasPrefix(secretConfig.Target, "/") == false {
// concat the default secret directory
mountPath = "/run/secrets/" + mountPath
}

itemPath = lastPart
}

volSource := api.VolumeSource{
Secret: &api.SecretVolumeSource{
SecretName: secretConfig.Source,
Items: []api.KeyToPath{{
Key: secretConfig.Source,
Path: target,
Path: itemPath,
}},
},
}
Expand All @@ -594,7 +620,7 @@ func (k *Kubernetes) ConfigSecretVolumes(name string, service kobject.ServiceCon

volMount := api.VolumeMount{
Name: vol.Name,
MountPath: "/run/secrets",
MountPath: mountPath,
}
volumeMounts = append(volumeMounts, volMount)
}
Expand Down