Fix non C volumes on Windows

Images may be created with a VOLUME stanza pointed to drive letters that
are not C:. Currently, an image that has such VOLUMEs defined, will
cause containerd to error out when starting a container.

This change skips copying existing contents to volumes that are not C:.
as an image can only hold files that are destined for the C: drive of a
container.

Signed-off-by: Gabriel Adrian Samfira <gsamfira@cloudbasesolutions.com>
This commit is contained in:
Gabriel Adrian Samfira 2023-04-06 16:57:32 -07:00
parent b16b0c872d
commit ec2bec6481

View File

@ -97,6 +97,12 @@ func WithVolumes(volumeMounts map[string]string) containerd.NewContainerOpts {
}()
for host, volume := range volumeMounts {
// On Windows, volumes may be defined as different drive letters than C:. For non-C: volumes
// we need to skip trying to copy existing contents, as an image can only hold files
// destined for volumes hosted on drive C:.
if len(volume) >= 2 && string(volume[1]) == ":" && !strings.EqualFold(string(volume[0]), "c") {
continue
}
// The volume may have been defined with a C: prefix, which we can't use here.
volume = strings.TrimPrefix(volume, "C:")
src, err := fs.RootPath(root, volume)