Pass in imagespec.Platform to WithVolumes()
Signed-off-by: Gabriel Adrian Samfira <gsamfira@cloudbasesolutions.com>
This commit is contained in:
parent
b9dfd29b73
commit
6dd529e400
@ -24,6 +24,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/containerd/continuity/fs"
|
||||
imagespec "github.com/opencontainers/image-spec/specs-go/v1"
|
||||
|
||||
"github.com/containerd/containerd"
|
||||
"github.com/containerd/containerd/containers"
|
||||
@ -55,7 +56,7 @@ func WithNewSnapshot(id string, i containerd.Image, opts ...snapshots.Opt) conta
|
||||
// WithVolumes copies ownership of volume in rootfs to its corresponding host path.
|
||||
// It doesn't update runtime spec.
|
||||
// The passed in map is a host path to container path map for all volumes.
|
||||
func WithVolumes(volumeMounts map[string]string, targetOS string) containerd.NewContainerOpts {
|
||||
func WithVolumes(volumeMounts map[string]string, platform imagespec.Platform) containerd.NewContainerOpts {
|
||||
return func(ctx context.Context, client *containerd.Client, c *containers.Container) (err error) {
|
||||
if c.Snapshotter == "" {
|
||||
return errors.New("no snapshotter set for container")
|
||||
@ -97,7 +98,7 @@ func WithVolumes(volumeMounts map[string]string, targetOS string) containerd.New
|
||||
}()
|
||||
|
||||
for host, volume := range volumeMounts {
|
||||
if targetOS == "windows" {
|
||||
if platform.OS == "windows" {
|
||||
// Windows allows volume mounts in subfolders under C: and as any other drive letter like D:, E:, etc.
|
||||
// An image may contain files inside a folder defined as a VOLUME in a Dockerfile. On Windows, images
|
||||
// can only contain pre-existing files for volumes situated on the root filesystem, which is C:.
|
||||
|
@ -223,7 +223,7 @@ func (c *criService) CreateContainer(ctx context.Context, r *runtime.CreateConta
|
||||
for _, v := range volumeMounts {
|
||||
mountMap[filepath.Clean(v.HostPath)] = v.ContainerPath
|
||||
}
|
||||
opts = append(opts, customopts.WithVolumes(mountMap, image.ImageSpec.OS))
|
||||
opts = append(opts, customopts.WithVolumes(mountMap, platform))
|
||||
}
|
||||
meta.ImageRef = image.ID
|
||||
meta.StopSignal = image.ImageSpec.Config.StopSignal
|
||||
|
@ -203,7 +203,14 @@ func (c *criService) CreateContainer(ctx context.Context, r *runtime.CreateConta
|
||||
for _, v := range volumeMounts {
|
||||
mountMap[filepath.Clean(v.HostPath)] = v.ContainerPath
|
||||
}
|
||||
opts = append(opts, customopts.WithVolumes(mountMap, image.ImageSpec.OS))
|
||||
platform := imagespec.Platform{
|
||||
OS: image.ImageSpec.OS,
|
||||
Architecture: image.ImageSpec.Architecture,
|
||||
OSVersion: image.ImageSpec.OSVersion,
|
||||
OSFeatures: image.ImageSpec.OSFeatures,
|
||||
Variant: image.ImageSpec.Variant,
|
||||
}
|
||||
opts = append(opts, customopts.WithVolumes(mountMap, platform))
|
||||
}
|
||||
meta.ImageRef = image.ID
|
||||
meta.StopSignal = image.ImageSpec.Config.StopSignal
|
||||
|
Loading…
Reference in New Issue
Block a user