@@ -1008,51 +1008,65 @@ func (c *criService) linuxContainerMounts(sandboxID string, config *runtime.Cont
1008
1008
}
1009
1009
1010
1010
if ! isInCRIMounts (etcHosts , config .GetMounts ()) {
1011
- mounts = append (mounts , & runtime.Mount {
1012
- ContainerPath : etcHosts ,
1013
- HostPath : c .getSandboxHosts (sandboxID ),
1014
- Readonly : securityContext .GetReadonlyRootfs (),
1015
- SelinuxRelabel : true ,
1016
- UidMappings : uidMappings ,
1017
- GidMappings : gidMappings ,
1018
- })
1011
+ hostpath := c .getSandboxHosts (sandboxID )
1012
+ // /etc/hosts could be delegated to remote sandbox controller. That file isn't required to be existed
1013
+ // in host side for some sandbox runtimes. Skip it if we don't need it.
1014
+ if _ , err := c .os .Stat (hostpath ); err == nil {
1015
+ mounts = append (mounts , & runtime.Mount {
1016
+ ContainerPath : etcHosts ,
1017
+ HostPath : hostpath ,
1018
+ Readonly : securityContext .GetReadonlyRootfs (),
1019
+ SelinuxRelabel : true ,
1020
+ UidMappings : uidMappings ,
1021
+ GidMappings : gidMappings ,
1022
+ })
1023
+ }
1019
1024
}
1020
1025
1021
1026
// Mount sandbox resolv.config.
1022
1027
// TODO: Need to figure out whether we should always mount it as read-only
1023
1028
if ! isInCRIMounts (resolvConfPath , config .GetMounts ()) {
1024
- mounts = append (mounts , & runtime.Mount {
1025
- ContainerPath : resolvConfPath ,
1026
- HostPath : c .getResolvPath (sandboxID ),
1027
- Readonly : securityContext .GetReadonlyRootfs (),
1028
- SelinuxRelabel : true ,
1029
- UidMappings : uidMappings ,
1030
- GidMappings : gidMappings ,
1031
- })
1029
+ hostpath := c .getResolvPath (sandboxID )
1030
+ // The ownership of /etc/resolv.conf could be delegated to remote sandbox controller. That file isn't
1031
+ // required to be existed in host side for some sandbox runtimes. Skip it if we don't need it.
1032
+ if _ , err := c .os .Stat (hostpath ); err == nil {
1033
+ mounts = append (mounts , & runtime.Mount {
1034
+ ContainerPath : resolvConfPath ,
1035
+ HostPath : hostpath ,
1036
+ Readonly : securityContext .GetReadonlyRootfs (),
1037
+ SelinuxRelabel : true ,
1038
+ UidMappings : uidMappings ,
1039
+ GidMappings : gidMappings ,
1040
+ })
1041
+ }
1032
1042
}
1033
1043
1034
1044
if ! isInCRIMounts (devShm , config .GetMounts ()) {
1035
1045
sandboxDevShm := c .getSandboxDevShm (sandboxID )
1036
1046
if securityContext .GetNamespaceOptions ().GetIpc () == runtime .NamespaceMode_NODE {
1037
1047
sandboxDevShm = devShm
1038
1048
}
1039
- mounts = append (mounts , & runtime.Mount {
1040
- ContainerPath : devShm ,
1041
- HostPath : sandboxDevShm ,
1042
- Readonly : false ,
1043
- SelinuxRelabel : sandboxDevShm != devShm ,
1044
- // XXX: tmpfs support for idmap mounts got merged in
1045
- // Linux 6.3.
1046
- // Our Ubuntu 22.04 CI runs with 5.15 kernels, so
1047
- // disabling idmap mounts for this case makes the CI
1048
- // happy (the other fs used support idmap mounts in 5.15
1049
- // kernels).
1050
- // We can enable this at a later stage, but as this
1051
- // tmpfs mount is exposed empty to the container (no
1052
- // prepopulated files) and using the hostIPC with userns
1053
- // is blocked by k8s, we can just avoid using the
1054
- // mappings and it should work fine.
1055
- })
1049
+ // The ownership of /dev/shm could be delegated to remote sandbox controller. That file isn't required
1050
+ // to be existed in host side for some sandbox runtimes. Skip it if we don't need it.
1051
+ if _ , err := c .os .Stat (sandboxDevShm ); err == nil {
1052
+ mounts = append (mounts , & runtime.Mount {
1053
+ ContainerPath : devShm ,
1054
+ HostPath : sandboxDevShm ,
1055
+ Readonly : false ,
1056
+ SelinuxRelabel : sandboxDevShm != devShm ,
1057
+ // XXX: tmpfs support for idmap mounts got merged in
1058
+ // Linux 6.3.
1059
+ // Our Ubuntu 22.04 CI runs with 5.15 kernels, so
1060
+ // disabling idmap mounts for this case makes the CI
1061
+ // happy (the other fs used support idmap mounts in 5.15
1062
+ // kernels).
1063
+ // We can enable this at a later stage, but as this
1064
+ // tmpfs mount is exposed empty to the container (no
1065
+ // prepopulated files) and using the hostIPC with userns
1066
+ // is blocked by k8s, we can just avoid using the
1067
+ // mappings and it should work fine.
1068
+ })
1069
+ }
1056
1070
}
1057
1071
return mounts
1058
1072
}
0 commit comments