volumes: only warn about possible issues and don't error out

- allows for specifying more possibilities
This commit is contained in:
iwilltry42 2020-05-29 14:26:18 +02:00
parent cf2c839b27
commit ae9be0603d
No known key found for this signature in database
GPG Key ID: 7BA57AD1CFF16110
2 changed files with 11 additions and 7 deletions

View File

@ -40,8 +40,11 @@ func ValidateVolumeMount(runtime runtimes.Runtime, volumeMount string) (string,
// validate 'SRC[:DEST]' substring // validate 'SRC[:DEST]' substring
split := strings.Split(volumeMount, ":") split := strings.Split(volumeMount, ":")
if len(split) < 1 || len(split) > 2 { if len(split) < 1 {
return "", fmt.Errorf("Invalid volume mount '%s': only one ':' allowed", volumeMount) return "", fmt.Errorf("No volume/path specified")
}
if len(split) > 3 {
return "", fmt.Errorf("Invalid volume mount '%s': maximal 2 ':' allowed", volumeMount)
} }
// we only have SRC specified -> DEST = SRC // we only have SRC specified -> DEST = SRC
@ -58,12 +61,11 @@ func ValidateVolumeMount(runtime runtimes.Runtime, volumeMount string) (string,
// a) named volume // a) named volume
isNamedVolume := true isNamedVolume := true
if err := verifyNamedVolume(runtime, src); err != nil { if err := verifyNamedVolume(runtime, src); err != nil {
log.Debugf("Source '%s' is not a named volume, assuming it's a path...\n%+v", src, err)
isNamedVolume = false isNamedVolume = false
} }
if !isNamedVolume { if !isNamedVolume {
if _, err := os.Stat(src); err != nil { if _, err := os.Stat(src); err != nil {
return "", fmt.Errorf("Failed to stat file/dir that you're trying to mount: '%s' in '%s'", src, volumeMount) log.Warnf("Failed to stat file/directory/named volume that you're trying to mount: '%s' in '%s' -> Please make sure it exists", src, volumeMount)
} }
} }
} }
@ -73,7 +75,7 @@ func ValidateVolumeMount(runtime runtimes.Runtime, volumeMount string) (string,
return "", fmt.Errorf("Volume mount destination doesn't appear to be an absolute path: '%s' in '%s'", dest, volumeMount) return "", fmt.Errorf("Volume mount destination doesn't appear to be an absolute path: '%s' in '%s'", dest, volumeMount)
} }
return fmt.Sprintf("%s:%s", src, dest), nil return volumeMount, nil
} }
// verifyNamedVolume checks whether a named volume exists in the runtime // verifyNamedVolume checks whether a named volume exists in the runtime

View File

@ -39,7 +39,9 @@ func TranslateNodeToContainer(node *k3d.Node) (*NodeInDocker, error) {
/* initialize everything that we need */ /* initialize everything that we need */
containerConfig := docker.Config{} containerConfig := docker.Config{}
hostConfig := docker.HostConfig{} hostConfig := docker.HostConfig{
Init: &[]bool{true}[0],
}
networkingConfig := network.NetworkingConfig{} networkingConfig := network.NetworkingConfig{}
/* Name & Image */ /* Name & Image */
@ -76,7 +78,7 @@ func TranslateNodeToContainer(node *k3d.Node) (*NodeInDocker, error) {
hostConfig.Privileged = true hostConfig.Privileged = true
/* Volumes */ /* Volumes */
// TODO: image volume log.Debugf("Volumes: %+v", node.Volumes)
hostConfig.Binds = node.Volumes hostConfig.Binds = node.Volumes
// containerConfig.Volumes = map[string]struct{}{} // TODO: do we need this? We only used binds before // containerConfig.Volumes = map[string]struct{}{} // TODO: do we need this? We only used binds before