Change return value for ValidateMountMode
1. rename it from ValidateMountMode to ValidMountMode Because it's a function simply check mount mode is valid or not. 2. remove the rw check return value It's not supposed to be combined into this function, and we already have a function for that check. Signed-off-by: Qiang Huang <h.huangqiang@huawei.com>
This commit is contained in:
parent
7ead74d903
commit
c99ed5ae5d
|
@ -71,11 +71,10 @@ func parseBindMount(spec string, mountLabel string, config *runconfig.Config) (*
|
||||||
case 3:
|
case 3:
|
||||||
bind.Destination = arr[1]
|
bind.Destination = arr[1]
|
||||||
mode := arr[2]
|
mode := arr[2]
|
||||||
isValid, isRw := volume.ValidateMountMode(mode)
|
if !volume.ValidMountMode(mode) {
|
||||||
if !isValid {
|
|
||||||
return nil, fmt.Errorf("invalid mode for volumes-from: %s", mode)
|
return nil, fmt.Errorf("invalid mode for volumes-from: %s", mode)
|
||||||
}
|
}
|
||||||
bind.RW = isRw
|
bind.RW = volume.ReadWrite(mode)
|
||||||
// Mode field is used by SELinux to decide whether to apply label
|
// Mode field is used by SELinux to decide whether to apply label
|
||||||
bind.Mode = mode
|
bind.Mode = mode
|
||||||
default:
|
default:
|
||||||
|
@ -268,7 +267,7 @@ func parseVolumesFrom(spec string) (string, string, error) {
|
||||||
|
|
||||||
if len(specParts) == 2 {
|
if len(specParts) == 2 {
|
||||||
mode = specParts[1]
|
mode = specParts[1]
|
||||||
if isValid, _ := volume.ValidateMountMode(mode); !isValid {
|
if !volume.ValidMountMode(mode) {
|
||||||
return "", "", fmt.Errorf("invalid mode for volumes-from: %s", mode)
|
return "", "", fmt.Errorf("invalid mode for volumes-from: %s", mode)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -202,7 +202,7 @@ func validatePath(val string, validateMountMode bool) (string, error) {
|
||||||
containerPath = splited[0]
|
containerPath = splited[0]
|
||||||
val = path.Clean(containerPath)
|
val = path.Clean(containerPath)
|
||||||
case 2:
|
case 2:
|
||||||
if isValid, _ := volume.ValidateMountMode(splited[1]); validateMountMode && isValid {
|
if isValid := volume.ValidMountMode(splited[1]); validateMountMode && isValid {
|
||||||
containerPath = splited[0]
|
containerPath = splited[0]
|
||||||
mode = splited[1]
|
mode = splited[1]
|
||||||
val = fmt.Sprintf("%s:%s", path.Clean(containerPath), mode)
|
val = fmt.Sprintf("%s:%s", path.Clean(containerPath), mode)
|
||||||
|
@ -213,7 +213,7 @@ func validatePath(val string, validateMountMode bool) (string, error) {
|
||||||
case 3:
|
case 3:
|
||||||
containerPath = splited[1]
|
containerPath = splited[1]
|
||||||
mode = splited[2]
|
mode = splited[2]
|
||||||
if isValid, _ := volume.ValidateMountMode(splited[2]); validateMountMode && !isValid {
|
if isValid := volume.ValidMountMode(splited[2]); validateMountMode && !isValid {
|
||||||
return val, fmt.Errorf("bad mount mode specified : %s", mode)
|
return val, fmt.Errorf("bad mount mode specified : %s", mode)
|
||||||
}
|
}
|
||||||
val = fmt.Sprintf("%s:%s:%s", splited[0], containerPath, mode)
|
val = fmt.Sprintf("%s:%s:%s", splited[0], containerPath, mode)
|
||||||
|
|
|
@ -49,13 +49,13 @@ var roModes = map[string]bool{
|
||||||
"Z,ro": true,
|
"Z,ro": true,
|
||||||
}
|
}
|
||||||
|
|
||||||
// ValidateMountMode will make sure the mount mode is valid.
|
// ValidMountMode will make sure the mount mode is valid.
|
||||||
// returns if it's a valid mount mode and if it's read-write or not.
|
// returns if it's a valid mount mode or not.
|
||||||
func ValidateMountMode(mode string) (bool, bool) {
|
func ValidMountMode(mode string) bool {
|
||||||
return roModes[mode] || rwModes[mode], rwModes[mode]
|
return roModes[mode] || rwModes[mode]
|
||||||
}
|
}
|
||||||
|
|
||||||
// ReadWrite tells you if a mode string is a valid read-only mode or not.
|
// ReadWrite tells you if a mode string is a valid read-write mode or not.
|
||||||
func ReadWrite(mode string) bool {
|
func ReadWrite(mode string) bool {
|
||||||
return rwModes[mode]
|
return rwModes[mode]
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue