Kubelet updates for Windows HostProcess Containers

This commit is contained in:
marosset
2021-02-28 23:25:41 -08:00
committed by James Sturtevant
parent 51a02fdb80
commit fd94032b21
6 changed files with 340 additions and 4 deletions

View File

@@ -31,6 +31,7 @@ import (
"k8s.io/client-go/tools/record"
runtimeapi "k8s.io/cri-api/pkg/apis/runtime/v1alpha2"
podutil "k8s.io/kubernetes/pkg/api/v1/pod"
sc "k8s.io/kubernetes/pkg/securitycontext"
hashutil "k8s.io/kubernetes/pkg/util/hash"
"k8s.io/kubernetes/third_party/forked/golang/expansion"
utilsnet "k8s.io/utils/net"
@@ -310,6 +311,34 @@ func HasPrivilegedContainer(pod *v1.Pod) bool {
return hasPrivileged
}
// HasWindowsHostProcessContainer returns true if any of the containers in a pod are HostProcess containers.
func HasWindowsHostProcessContainer(pod *v1.Pod) bool {
var hasHostProcess bool
podutil.VisitContainers(&pod.Spec, podutil.AllFeatureEnabledContainers(), func(c *v1.Container, containerType podutil.ContainerType) bool {
if sc.HasWindowsHostProcessRequest(pod, c) {
hasHostProcess = true
return false
}
return true
})
return hasHostProcess
}
// AllContainersAreWindowsHostProcess returns true if all containres in a pod are HostProcess containers.
func AllContainersAreWindowsHostProcess(pod *v1.Pod) bool {
allHostProcess := true
podutil.VisitContainers(&pod.Spec, podutil.AllFeatureEnabledContainers(), func(c *v1.Container, containerType podutil.ContainerType) bool {
if !sc.HasWindowsHostProcessRequest(pod, c) {
allHostProcess = false
return false
}
return true
})
return allHostProcess
}
// MakePortMappings creates internal port mapping from api port mapping.
func MakePortMappings(container *v1.Container) (ports []PortMapping) {
names := make(map[string]struct{})