1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

volume/mounts: remove "containerOS" argument from NewParser (LCOW code)

This changes mounts.NewParser() to create a parser for the current operatingsystem,
instead of one specific to a (possibly non-matching, in case of LCOW) OS.

With the OS-specific handling being removed, the "OS" parameter is also removed
from `daemon.verifyContainerSettings()`, and various other container-related
functions.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2021-06-11 21:01:18 +02:00
parent f3d08d59aa
commit 300c11c7c9
No known key found for this signature in database
GPG key ID: 76698F39D527CE8C
19 changed files with 49 additions and 102 deletions

View file

@ -474,11 +474,7 @@ func (container *Container) ShouldRestart() bool {
// AddMountPointWithVolume adds a new mount point configured with a volume to the container. // AddMountPointWithVolume adds a new mount point configured with a volume to the container.
func (container *Container) AddMountPointWithVolume(destination string, vol volume.Volume, rw bool) { func (container *Container) AddMountPointWithVolume(destination string, vol volume.Volume, rw bool) {
operatingSystem := container.OS volumeParser := volumemounts.NewParser()
if operatingSystem == "" {
operatingSystem = runtime.GOOS
}
volumeParser := volumemounts.NewParser(operatingSystem)
container.MountPoints[destination] = &volumemounts.MountPoint{ container.MountPoints[destination] = &volumemounts.MountPoint{
Type: mounttypes.TypeVolume, Type: mounttypes.TypeVolume,
Name: vol.Name(), Name: vol.Name(),

View file

@ -64,7 +64,7 @@ func (container *Container) BuildHostnameFile() error {
func (container *Container) NetworkMounts() []Mount { func (container *Container) NetworkMounts() []Mount {
var mounts []Mount var mounts []Mount
shared := container.HostConfig.NetworkMode.IsContainer() shared := container.HostConfig.NetworkMode.IsContainer()
parser := volumemounts.NewParser(container.OS) parser := volumemounts.NewParser()
if container.ResolvConfPath != "" { if container.ResolvConfPath != "" {
if _, err := os.Stat(container.ResolvConfPath); err != nil { if _, err := os.Stat(container.ResolvConfPath); err != nil {
logrus.Warnf("ResolvConfPath set to %q, but can't stat this filename (err = %v); skipping", container.ResolvConfPath, err) logrus.Warnf("ResolvConfPath set to %q, but can't stat this filename (err = %v); skipping", container.ResolvConfPath, err)
@ -199,7 +199,7 @@ func (container *Container) UnmountIpcMount() error {
// IpcMounts returns the list of IPC mounts // IpcMounts returns the list of IPC mounts
func (container *Container) IpcMounts() []Mount { func (container *Container) IpcMounts() []Mount {
var mounts []Mount var mounts []Mount
parser := volumemounts.NewParser(container.OS) parser := volumemounts.NewParser()
if container.HasMountFor("/dev/shm") { if container.HasMountFor("/dev/shm") {
return mounts return mounts
@ -419,7 +419,6 @@ func copyExistingContents(source, destination string) error {
// TmpfsMounts returns the list of tmpfs mounts // TmpfsMounts returns the list of tmpfs mounts
func (container *Container) TmpfsMounts() ([]Mount, error) { func (container *Container) TmpfsMounts() ([]Mount, error) {
parser := volumemounts.NewParser(container.OS)
var mounts []Mount var mounts []Mount
for dest, data := range container.HostConfig.Tmpfs { for dest, data := range container.HostConfig.Tmpfs {
mounts = append(mounts, Mount{ mounts = append(mounts, Mount{
@ -428,6 +427,7 @@ func (container *Container) TmpfsMounts() ([]Mount, error) {
Data: data, Data: data,
}) })
} }
parser := volumemounts.NewParser()
for dest, mnt := range container.MountPoints { for dest, mnt := range container.MountPoints {
if mnt.Type == mounttypes.TypeTmpfs { if mnt.Type == mounttypes.TypeTmpfs {
data, err := parser.ConvertTmpfsOptions(mnt.Spec.TmpfsOptions, mnt.Spec.ReadOnly) data, err := parser.ConvertTmpfsOptions(mnt.Spec.TmpfsOptions, mnt.Spec.ReadOnly)

View file

@ -12,7 +12,7 @@ import (
// cannot be configured with a read-only rootfs. // cannot be configured with a read-only rootfs.
func checkIfPathIsInAVolume(container *container.Container, absPath string) (bool, error) { func checkIfPathIsInAVolume(container *container.Container, absPath string) (bool, error) {
var toVolume bool var toVolume bool
parser := volumemounts.NewParser(container.OS) parser := volumemounts.NewParser()
for _, mnt := range container.MountPoints { for _, mnt := range container.MountPoints {
if toVolume = parser.HasResource(mnt, absPath); toVolume { if toVolume = parser.HasResource(mnt, absPath); toVolume {
if mnt.RW { if mnt.RW {

View file

@ -3,10 +3,8 @@ package daemon // import "github.com/docker/docker/daemon"
import ( import (
"fmt" "fmt"
"os" "os"
"path"
"path/filepath" "path/filepath"
"runtime" "runtime"
"strings"
"time" "time"
containertypes "github.com/docker/docker/api/types/container" containertypes "github.com/docker/docker/api/types/container"
@ -231,12 +229,12 @@ func (daemon *Daemon) setHostConfig(container *container.Container, hostConfig *
// verifyContainerSettings performs validation of the hostconfig and config // verifyContainerSettings performs validation of the hostconfig and config
// structures. // structures.
func (daemon *Daemon) verifyContainerSettings(platform string, hostConfig *containertypes.HostConfig, config *containertypes.Config, update bool) (warnings []string, err error) { func (daemon *Daemon) verifyContainerSettings(hostConfig *containertypes.HostConfig, config *containertypes.Config, update bool) (warnings []string, err error) {
// First perform verification of settings common across all platforms. // First perform verification of settings common across all platforms.
if err = validateContainerConfig(config, platform); err != nil { if err = validateContainerConfig(config); err != nil {
return warnings, err return warnings, err
} }
if err := validateHostConfig(hostConfig, platform); err != nil { if err := validateHostConfig(hostConfig); err != nil {
return warnings, err return warnings, err
} }
@ -248,11 +246,11 @@ func (daemon *Daemon) verifyContainerSettings(platform string, hostConfig *conta
return warnings, err return warnings, err
} }
func validateContainerConfig(config *containertypes.Config, platform string) error { func validateContainerConfig(config *containertypes.Config) error {
if config == nil { if config == nil {
return nil return nil
} }
if err := translateWorkingDir(config, platform); err != nil { if err := translateWorkingDir(config); err != nil {
return err return err
} }
if len(config.StopSignal) > 0 { if len(config.StopSignal) > 0 {
@ -269,7 +267,7 @@ func validateContainerConfig(config *containertypes.Config, platform string) err
return validateHealthCheck(config.Healthcheck) return validateHealthCheck(config.Healthcheck)
} }
func validateHostConfig(hostConfig *containertypes.HostConfig, platform string) error { func validateHostConfig(hostConfig *containertypes.HostConfig) error {
if hostConfig == nil { if hostConfig == nil {
return nil return nil
} }
@ -278,7 +276,7 @@ func validateHostConfig(hostConfig *containertypes.HostConfig, platform string)
return errors.Errorf("can't create 'AutoRemove' container with restart policy") return errors.Errorf("can't create 'AutoRemove' container with restart policy")
} }
// Validate mounts; check if host directories still exist // Validate mounts; check if host directories still exist
parser := volumemounts.NewParser(platform) parser := volumemounts.NewParser()
for _, c := range hostConfig.Mounts { for _, c := range hostConfig.Mounts {
cfg := c cfg := c
if err := parser.ValidateMountConfig(&cfg); err != nil { if err := parser.ValidateMountConfig(&cfg); err != nil {
@ -373,23 +371,13 @@ func validateRestartPolicy(policy containertypes.RestartPolicy) error {
// translateWorkingDir translates the working-dir for the target platform, // translateWorkingDir translates the working-dir for the target platform,
// and returns an error if the given path is not an absolute path. // and returns an error if the given path is not an absolute path.
func translateWorkingDir(config *containertypes.Config, platform string) error { func translateWorkingDir(config *containertypes.Config) error {
if config.WorkingDir == "" { if config.WorkingDir == "" {
return nil return nil
} }
wd := config.WorkingDir wd := filepath.FromSlash(config.WorkingDir) // Ensure in platform semantics
switch { if !system.IsAbs(wd) {
case runtime.GOOS != platform: return fmt.Errorf("the working directory '%s' is invalid, it needs to be an absolute path", config.WorkingDir)
// LCOW. Force Unix semantics
wd = strings.Replace(wd, string(os.PathSeparator), "/", -1)
if !path.IsAbs(wd) {
return fmt.Errorf("the working directory '%s' is invalid, it needs to be an absolute path", config.WorkingDir)
}
default:
wd = filepath.FromSlash(wd) // Ensure in platform semantics
if !system.IsAbs(wd) {
return fmt.Errorf("the working directory '%s' is invalid, it needs to be an absolute path", config.WorkingDir)
}
} }
config.WorkingDir = wd config.WorkingDir = wd
return nil return nil

View file

@ -38,7 +38,7 @@ func TestContainerWarningHostAndPublishPorts(t *testing.T) {
}, },
} }
d := &Daemon{configStore: cs} d := &Daemon{configStore: cs}
wrns, err := d.verifyContainerSettings("", hostConfig, &containertypes.Config{}, false) wrns, err := d.verifyContainerSettings(hostConfig, &containertypes.Config{}, false)
assert.NilError(t, err) assert.NilError(t, err)
assert.DeepEqual(t, tc.warnings, wrns) assert.DeepEqual(t, tc.warnings, wrns)
} }

View file

@ -16,7 +16,6 @@ import (
"github.com/docker/docker/errdefs" "github.com/docker/docker/errdefs"
"github.com/docker/docker/image" "github.com/docker/docker/image"
"github.com/docker/docker/pkg/idtools" "github.com/docker/docker/pkg/idtools"
"github.com/docker/docker/pkg/system"
"github.com/docker/docker/runconfig" "github.com/docker/docker/runconfig"
v1 "github.com/opencontainers/image-spec/specs-go/v1" v1 "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/opencontainers/selinux/go-selinux" "github.com/opencontainers/selinux/go-selinux"
@ -61,31 +60,23 @@ func (daemon *Daemon) containerCreate(opts createOpts) (containertypes.Container
return containertypes.ContainerCreateCreatedBody{}, errdefs.InvalidParameter(errors.New("Config cannot be empty in order to create a container")) return containertypes.ContainerCreateCreatedBody{}, errdefs.InvalidParameter(errors.New("Config cannot be empty in order to create a container"))
} }
os := runtime.GOOS warnings, err := daemon.verifyContainerSettings(opts.params.HostConfig, opts.params.Config, false)
var img *image.Image
if opts.params.Config.Image != "" {
var err error
img, err = daemon.imageService.GetImage(opts.params.Config.Image, opts.params.Platform)
if err == nil {
os = img.OS
}
}
warnings, err := daemon.verifyContainerSettings(os, opts.params.HostConfig, opts.params.Config, false)
if err != nil { if err != nil {
return containertypes.ContainerCreateCreatedBody{Warnings: warnings}, errdefs.InvalidParameter(err) return containertypes.ContainerCreateCreatedBody{Warnings: warnings}, errdefs.InvalidParameter(err)
} }
if img != nil && opts.params.Platform == nil { if opts.params.Platform == nil && opts.params.Config.Image != "" {
p := platforms.DefaultSpec() if img, _ := daemon.imageService.GetImage(opts.params.Config.Image, opts.params.Platform); img != nil {
imgPlat := v1.Platform{ p := platforms.DefaultSpec()
OS: img.OS, imgPlat := v1.Platform{
Architecture: img.Architecture, OS: img.OS,
Variant: img.Variant, Architecture: img.Architecture,
} Variant: img.Variant,
}
if !images.OnlyPlatformWithFallback(p).Match(imgPlat) { if !images.OnlyPlatformWithFallback(p).Match(imgPlat) {
warnings = append(warnings, fmt.Sprintf("The requested image's platform (%s) does not match the detected host platform (%s) and no specific platform was requested", platforms.Format(imgPlat), platforms.Format(p))) warnings = append(warnings, fmt.Sprintf("The requested image's platform (%s) does not match the detected host platform (%s) and no specific platform was requested", platforms.Format(imgPlat), platforms.Format(p)))
}
} }
} }
@ -132,21 +123,13 @@ func (daemon *Daemon) create(opts createOpts) (retC *container.Container, retErr
} }
if img.OS != "" { if img.OS != "" {
os = img.OS os = img.OS
} else {
// default to the host OS except on Windows with LCOW
if isWindows && system.LCOWSupported() {
os = "linux"
}
} }
imgID = img.ID() imgID = img.ID()
if isWindows && img.OS == "linux" {
if isWindows && img.OS == "linux" && !system.LCOWSupported() {
return nil, errors.New("operating system on which parent image was created is not Windows") return nil, errors.New("operating system on which parent image was created is not Windows")
} }
} else { } else if isWindows {
if isWindows { os = "linux" // 'scratch' case.
os = "linux" // 'scratch' case.
}
} }
// On WCOW, if are not being invoked by the builder to create this container (where // On WCOW, if are not being invoked by the builder to create this container (where

View file

@ -28,7 +28,7 @@ func (daemon *Daemon) createContainerOSSpecificSettings(container *container.Con
} }
hostConfig.Isolation = "hyperv" hostConfig.Isolation = "hyperv"
} }
parser := volumemounts.NewParser(container.OS) parser := volumemounts.NewParser()
for spec := range config.Volumes { for spec := range config.Volumes {
mp, err := parser.ParseMountRaw(spec, hostConfig.VolumeDriver) mp, err := parser.ParseMountRaw(spec, hostConfig.VolumeDriver)

View file

@ -116,7 +116,7 @@ func TestNotCleanupMounts(t *testing.T) {
func TestValidateContainerIsolationLinux(t *testing.T) { func TestValidateContainerIsolationLinux(t *testing.T) {
d := Daemon{} d := Daemon{}
_, err := d.verifyContainerSettings("linux", &containertypes.HostConfig{Isolation: containertypes.IsolationHyperV}, nil, false) _, err := d.verifyContainerSettings(&containertypes.HostConfig{Isolation: containertypes.IsolationHyperV}, nil, false)
assert.Check(t, is.Error(err, "invalid isolation 'hyperv' on linux")) assert.Check(t, is.Error(err, "invalid isolation 'hyperv' on linux"))
} }

View file

@ -305,7 +305,7 @@ func TestMerge(t *testing.T) {
func TestValidateContainerIsolation(t *testing.T) { func TestValidateContainerIsolation(t *testing.T) {
d := Daemon{} d := Daemon{}
_, err := d.verifyContainerSettings(runtime.GOOS, &containertypes.HostConfig{Isolation: containertypes.Isolation("invalid")}, nil, false) _, err := d.verifyContainerSettings(&containertypes.HostConfig{Isolation: containertypes.Isolation("invalid")}, nil, false)
assert.Check(t, is.Error(err, "invalid isolation 'invalid' on "+runtime.GOOS)) assert.Check(t, is.Error(err, "invalid isolation 'invalid' on "+runtime.GOOS))
} }

View file

@ -719,7 +719,7 @@ func verifyPlatformContainerSettings(daemon *Daemon, hostConfig *containertypes.
return warnings, fmt.Errorf("Unknown runtime specified %s", hostConfig.Runtime) return warnings, fmt.Errorf("Unknown runtime specified %s", hostConfig.Runtime)
} }
parser := volumemounts.NewParser(runtime.GOOS) parser := volumemounts.NewParser()
for dest := range hostConfig.Tmpfs { for dest := range hostConfig.Tmpfs {
if err := parser.ValidateTmpfsMountDestination(dest); err != nil { if err := parser.ValidateTmpfsMountDestination(dest); err != nil {
return warnings, err return warnings, err

View file

@ -570,7 +570,7 @@ func WithMounts(daemon *Daemon, c *container.Container) coci.SpecOpts {
for _, m := range mounts { for _, m := range mounts {
if m.Source == "tmpfs" { if m.Source == "tmpfs" {
data := m.Data data := m.Data
parser := volumemounts.NewParser("linux") parser := volumemounts.NewParser()
options := []string{"noexec", "nosuid", "nodev", string(parser.DefaultPropagationMode())} options := []string{"noexec", "nosuid", "nodev", string(parser.DefaultPropagationMode())}
if data != "" { if data != "" {
options = append(options, strings.Split(data, ",")...) options = append(options, strings.Split(data, ",")...)

View file

@ -81,7 +81,7 @@ func (daemon *Daemon) ContainerStart(name string, hostConfig *containertypes.Hos
// check if hostConfig is in line with the current system settings. // check if hostConfig is in line with the current system settings.
// It may happen cgroups are umounted or the like. // It may happen cgroups are umounted or the like.
if _, err = daemon.verifyContainerSettings(ctr.OS, ctr.HostConfig, nil, false); err != nil { if _, err = daemon.verifyContainerSettings(ctr.HostConfig, nil, false); err != nil {
return errdefs.InvalidParameter(err) return errdefs.InvalidParameter(err)
} }
// Adapt for old containers in case we have updates in this function and // Adapt for old containers in case we have updates in this function and

View file

@ -13,12 +13,7 @@ import (
func (daemon *Daemon) ContainerUpdate(name string, hostConfig *container.HostConfig) (container.ContainerUpdateOKBody, error) { func (daemon *Daemon) ContainerUpdate(name string, hostConfig *container.HostConfig) (container.ContainerUpdateOKBody, error) {
var warnings []string var warnings []string
c, err := daemon.GetContainer(name) warnings, err := daemon.verifyContainerSettings(hostConfig, nil, true)
if err != nil {
return container.ContainerUpdateOKBody{Warnings: warnings}, err
}
warnings, err = daemon.verifyContainerSettings(c.OS, hostConfig, nil, true)
if err != nil { if err != nil {
return container.ContainerUpdateOKBody{Warnings: warnings}, errdefs.InvalidParameter(err) return container.ContainerUpdateOKBody{Warnings: warnings}, errdefs.InvalidParameter(err)
} }

View file

@ -62,7 +62,7 @@ func (m mounts) parts(i int) int {
func (daemon *Daemon) registerMountPoints(container *container.Container, hostConfig *containertypes.HostConfig) (retErr error) { func (daemon *Daemon) registerMountPoints(container *container.Container, hostConfig *containertypes.HostConfig) (retErr error) {
binds := map[string]bool{} binds := map[string]bool{}
mountPoints := map[string]*volumemounts.MountPoint{} mountPoints := map[string]*volumemounts.MountPoint{}
parser := volumemounts.NewParser(container.OS) parser := volumemounts.NewParser()
ctx := context.TODO() ctx := context.TODO()
defer func() { defer func() {
@ -265,8 +265,6 @@ func (daemon *Daemon) backportMountSpec(container *container.Container) {
container.Lock() container.Lock()
defer container.Unlock() defer container.Unlock()
parser := volumemounts.NewParser(container.OS)
maybeUpdate := make(map[string]bool) maybeUpdate := make(map[string]bool)
for _, mp := range container.MountPoints { for _, mp := range container.MountPoints {
if mp.Spec.Source != "" && mp.Type != "" { if mp.Spec.Source != "" && mp.Type != "" {
@ -283,6 +281,7 @@ func (daemon *Daemon) backportMountSpec(container *container.Container) {
mountSpecs[m.Target] = true mountSpecs[m.Target] = true
} }
parser := volumemounts.NewParser()
binds := make(map[string]*volumemounts.MountPoint, len(container.HostConfig.Binds)) binds := make(map[string]*volumemounts.MountPoint, len(container.HostConfig.Binds))
for _, rawSpec := range container.HostConfig.Binds { for _, rawSpec := range container.HostConfig.Binds {
mp, err := parser.ParseMountRaw(rawSpec, container.HostConfig.VolumeDriver) mp, err := parser.ParseMountRaw(rawSpec, container.HostConfig.VolumeDriver)

View file

@ -1,7 +1,6 @@
package daemon // import "github.com/docker/docker/daemon" package daemon // import "github.com/docker/docker/daemon"
import ( import (
"runtime"
"testing" "testing"
volumemounts "github.com/docker/docker/volume/mounts" volumemounts "github.com/docker/docker/volume/mounts"
@ -21,7 +20,7 @@ func TestParseVolumesFrom(t *testing.T) {
{"foobar:baz", "", "", true}, {"foobar:baz", "", "", true},
} }
parser := volumemounts.NewParser(runtime.GOOS) parser := volumemounts.NewParser()
for _, c := range cases { for _, c := range cases {
id, mode, err := parser.ParseVolumesFrom(c.spec) id, mode, err := parser.ParseVolumesFrom(c.spec)

View file

@ -7,13 +7,6 @@ import (
"github.com/docker/docker/api/types/mount" "github.com/docker/docker/api/types/mount"
) )
const (
// OSLinux is the same as runtime.GOOS on linux
OSLinux = "linux"
// OSWindows is the same as runtime.GOOS on windows
OSWindows = "windows"
)
// ErrVolumeTargetIsRoot is returned when the target destination is root. // ErrVolumeTargetIsRoot is returned when the target destination is root.
// It's used by both LCOW and Linux parsers. // It's used by both LCOW and Linux parsers.
var ErrVolumeTargetIsRoot = errors.New("invalid specification: destination can't be '/'") var ErrVolumeTargetIsRoot = errors.New("invalid specification: destination can't be '/'")
@ -40,14 +33,10 @@ type Parser interface {
ValidateMountConfig(mt *mount.Mount) error ValidateMountConfig(mt *mount.Mount) error
} }
// NewParser creates a parser for a given container OS, depending on the current host OS (linux on a windows host will resolve to an lcowParser) // NewParser creates a parser for the current host OS
func NewParser(containerOS string) Parser { func NewParser() Parser {
switch containerOS { if runtime.GOOS == "windows" {
case OSWindows:
return &windowsParser{} return &windowsParser{}
} }
if runtime.GOOS == OSWindows {
return &lcowParser{}
}
return &linuxParser{} return &linuxParser{}
} }

View file

@ -438,7 +438,7 @@ func TestParseMountSpec(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
defer os.RemoveAll(testDir) defer os.RemoveAll(testDir)
parser := NewParser(runtime.GOOS) parser := NewParser()
cases := []c{ cases := []c{
{mount.Mount{Type: mount.TypeBind, Source: testDir, Target: testDestinationPath, ReadOnly: true}, MountPoint{Type: mount.TypeBind, Source: testDir, Destination: testDestinationPath, Propagation: parser.DefaultPropagationMode()}}, {mount.Mount{Type: mount.TypeBind, Source: testDir, Target: testDestinationPath, ReadOnly: true}, MountPoint{Type: mount.TypeBind, Source: testDir, Destination: testDestinationPath, Propagation: parser.DefaultPropagationMode()}},
{mount.Mount{Type: mount.TypeBind, Source: testDir, Target: testDestinationPath}, MountPoint{Type: mount.TypeBind, Source: testDir, Destination: testDestinationPath, RW: true, Propagation: parser.DefaultPropagationMode()}}, {mount.Mount{Type: mount.TypeBind, Source: testDir, Target: testDestinationPath}, MountPoint{Type: mount.TypeBind, Source: testDir, Destination: testDestinationPath, RW: true, Propagation: parser.DefaultPropagationMode()}},
@ -519,7 +519,7 @@ func TestParseMountSpecBindWithFileinfoError(t *testing.T) {
} }
m := mount.Mount{Type: mount.TypeBind, Source: p, Target: p} m := mount.Mount{Type: mount.TypeBind, Source: p, Target: p}
parser := NewParser(runtime.GOOS) parser := NewParser()
_, err := parser.ParseMountSpec(m) _, err := parser.ParseMountSpec(m)
assert.ErrorContains(t, err, "some crazy error") assert.ErrorContains(t, err, "some crazy error")

View file

@ -48,7 +48,7 @@ func TestValidateMount(t *testing.T) {
{mount.Mount{Type: mount.TypeBind, Source: testDir, Target: "/foo"}, nil}, {mount.Mount{Type: mount.TypeBind, Source: testDir, Target: "/foo"}, nil},
{mount.Mount{Type: "invalid", Target: "/foo"}, errors.New("mount type unknown")}, {mount.Mount{Type: "invalid", Target: "/foo"}, errors.New("mount type unknown")},
} }
parser := NewParser(runtime.GOOS) parser := NewParser()
for i, x := range cases { for i, x := range cases {
err := parser.ValidateMountConfig(&x.input) err := parser.ValidateMountConfig(&x.input)
if err == nil && x.expected == nil { if err == nil && x.expected == nil {

View file

@ -6,7 +6,6 @@ import (
"net" "net"
"os" "os"
"path/filepath" "path/filepath"
"runtime"
"sync" "sync"
"time" "time"
@ -578,8 +577,7 @@ func (s *VolumeStore) create(ctx context.Context, name, driverName string, opts,
// Validate the name in a platform-specific manner // Validate the name in a platform-specific manner
// volume name validation is specific to the host os and not on container image // volume name validation is specific to the host os and not on container image
// windows/lcow should have an equivalent volumename validation logic so we create a parser for current host OS parser := volumemounts.NewParser()
parser := volumemounts.NewParser(runtime.GOOS)
err := parser.ValidateVolumeName(name) err := parser.ValidateVolumeName(name)
if err != nil { if err != nil {
return nil, false, err return nil, false, err