Windows: Fixes /etc/hosts file mounting support for containerd

If Containerd is used on Windows, then we can also mount individual
files into containers (e.g.: /etc/hosts), which was not possible with Docker.

Checks if the container runtime is containerd, and if it is, then also
mount /etc/hosts file (to C:\Windows\System32\drivers\etc\hosts).
This commit is contained in:
Claudiu Belu
2019-09-04 09:16:21 -07:00
parent b36afa5509
commit de4602995b
5 changed files with 23 additions and 9 deletions

View File

@@ -144,7 +144,8 @@ const (
evictionMonitoringPeriod = time.Second * 10
// The path in containers' filesystems where the hosts file is mounted.
etcHostsPath = "/etc/hosts"
linuxEtcHostsPath = "/etc/hosts"
windowsEtcHostsPath = "C:\\Windows\\System32\\drivers\\etc\\hosts"
// Capacity of the channel for receiving pod lifecycle events. This number
// is a bit arbitrary and may be adjusted in the future.
@@ -177,6 +178,15 @@ const (
nodeLeaseRenewIntervalFraction = 0.25
)
var etcHostsPath = getContainerEtcHostsPath()
func getContainerEtcHostsPath() string {
if sysruntime.GOOS == "windows" {
return windowsEtcHostsPath
}
return linuxEtcHostsPath
}
// SyncHandler is an interface implemented by Kubelet, for testability
type SyncHandler interface {
HandlePodAdditions(pods []*v1.Pod)