diff --git a/libpod/container_inspect.go b/libpod/container_inspect.go index b3d680bcb5..a94175407f 100644 --- a/libpod/container_inspect.go +++ b/libpod/container_inspect.go @@ -258,6 +258,7 @@ func (c *Container) GetMounts(namedVolumes []*ContainerNamedVolume, imageVolumes mountStruct.Type = "volume" mountStruct.Destination = volume.Dest mountStruct.Name = volume.Name + mountStruct.SubPath = volume.SubPath // For src and driver, we need to look up the named // volume. @@ -284,6 +285,7 @@ func (c *Container) GetMounts(namedVolumes []*ContainerNamedVolume, imageVolumes mountStruct.Destination = volume.Dest mountStruct.Source = volume.Source mountStruct.RW = volume.ReadWrite + mountStruct.SubPath = volume.SubPath inspectMounts = append(inspectMounts, mountStruct) } diff --git a/libpod/define/container_inspect.go b/libpod/define/container_inspect.go index 1f5b225c3f..b4352554b1 100644 --- a/libpod/define/container_inspect.go +++ b/libpod/define/container_inspect.go @@ -285,6 +285,9 @@ type InspectMount struct { // Mount propagation for the mount. Can be empty if not specified, but // is always printed - no omitempty. Propagation string `json:"Propagation"` + // SubPath object from the volume. Specified as a path within + // the source volume to be mounted at the Destination. + SubPath string `json:"SubPath,omitempty"` } // InspectContainerState provides a detailed record of a container's current diff --git a/pkg/specgen/generate/kube/kube.go b/pkg/specgen/generate/kube/kube.go index 9f532d3ec1..b279f7a68c 100644 --- a/pkg/specgen/generate/kube/kube.go +++ b/pkg/specgen/generate/kube/kube.go @@ -575,7 +575,7 @@ func ToSpecGen(ctx context.Context, opts *CtrSpecGenOptions) (*specgen.SpecGener Destination: volume.MountPath, ReadWrite: false, Source: volumeSource.Source, - SubPath: "", + SubPath: volume.SubPath, } s.ImageVolumes = append(s.ImageVolumes, &imageVolume) default: diff --git a/test/system/060-mount.bats b/test/system/060-mount.bats index 792c777165..ff1e326462 100644 --- a/test/system/060-mount.bats +++ b/test/system/060-mount.bats @@ -148,6 +148,14 @@ load helpers run_podman run --rm --mount "${mountopts},readwrite=true" $iname \ touch /image-mount/readwrite + tmpctr="c-$(safename)" + subpathopts="type=image,src=$iname,dst=/image-mount,subpath=/etc" + run_podman run --name $tmpctr --mount "${subpathopts}" $iname \ + ls /image-mount/shadow + run_podman inspect $tmpctr --format '{{ (index .Mounts 0).SubPath }}' + assert "$output" == "/etc" "SubPath contains /etc" + run_podman rm $tmpctr + # The rest of the tests below are meaningless under remote if is_remote; then run_podman rmi $iname