mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-11 13:02:14 +00:00
Merge pull request #53444 from msau42/make-mounts
Automatic merge from submit-queue (batch tested with PRs 53444, 52067, 53571, 53182). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. Don't skip mounts if we can't find the volume **What this PR does / why we need it**: Return an error instead of skipping the volume while constructing the list of volume mounts for the container runtime. This prevents the scenario of a container writing data to an ephemeral volume when it expects the volume to be persistent. **Which issue this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close that issue when PR gets merged)*: fixes #53421 **Release note**: NONE @kubernetes/sig-storage-pr-reviews
This commit is contained in:
commit
d6cabc7e99
@ -127,8 +127,8 @@ func makeMounts(pod *v1.Pod, podDir string, container *v1.Container, hostName, h
|
|||||||
mountEtcHostsFile = mountEtcHostsFile && (mount.MountPath != etcHostsPath)
|
mountEtcHostsFile = mountEtcHostsFile && (mount.MountPath != etcHostsPath)
|
||||||
vol, ok := podVolumes[mount.Name]
|
vol, ok := podVolumes[mount.Name]
|
||||||
if !ok || vol.Mounter == nil {
|
if !ok || vol.Mounter == nil {
|
||||||
glog.Warningf("Mount cannot be satisfied for container %q, because the volume is missing or the volume mounter is nil: %q", container.Name, mount)
|
glog.Errorf("Mount cannot be satisfied for container %q, because the volume is missing or the volume mounter is nil: %+v", container.Name, mount)
|
||||||
continue
|
return nil, fmt.Errorf("cannot find volume %q to mount into container %q", mount.Name, container.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
relabelVolume := false
|
relabelVolume := false
|
||||||
|
@ -223,6 +223,36 @@ func TestMakeMounts(t *testing.T) {
|
|||||||
expectErr: true,
|
expectErr: true,
|
||||||
expectedErrMsg: "unable to provision SubPath `no/backsteps/../allowed`: must not contain '..'",
|
expectedErrMsg: "unable to provision SubPath `no/backsteps/../allowed`: must not contain '..'",
|
||||||
},
|
},
|
||||||
|
"volume doesn't exist": {
|
||||||
|
podVolumes: kubecontainer.VolumeMap{},
|
||||||
|
container: v1.Container{
|
||||||
|
VolumeMounts: []v1.VolumeMount{
|
||||||
|
{
|
||||||
|
MountPath: "/mnt/path3",
|
||||||
|
Name: "disk",
|
||||||
|
ReadOnly: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
expectErr: true,
|
||||||
|
expectedErrMsg: "cannot find volume \"disk\" to mount into container \"\"",
|
||||||
|
},
|
||||||
|
"volume mounter is nil": {
|
||||||
|
podVolumes: kubecontainer.VolumeMap{
|
||||||
|
"disk": kubecontainer.VolumeInfo{},
|
||||||
|
},
|
||||||
|
container: v1.Container{
|
||||||
|
VolumeMounts: []v1.VolumeMount{
|
||||||
|
{
|
||||||
|
MountPath: "/mnt/path3",
|
||||||
|
Name: "disk",
|
||||||
|
ReadOnly: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
expectErr: true,
|
||||||
|
expectedErrMsg: "cannot find volume \"disk\" to mount into container \"\"",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for name, tc := range testCases {
|
for name, tc := range testCases {
|
||||||
|
Loading…
Reference in New Issue
Block a user