Merge pull request #83058 from bclau/tests/windows-tests-support

tests: Fixes tests for Windows (containerd, RunAsUserName)
This commit is contained in:
Kubernetes Prow Robot
2019-11-14 16:37:13 -08:00
committed by GitHub
10 changed files with 89 additions and 65 deletions

View File

@@ -44,6 +44,13 @@ const (
NodeE2E Suite = "node e2e"
)
var (
// non-Administrator Windows user used in tests. This is the Windows equivalent of the Linux non-root UID usage.
nonAdminTestUserName = "ContainerUser"
// non-root UID used in tests.
nonRootTestUserID = int64(1000)
)
// CurrentSuite represents current test suite.
var CurrentSuite Suite
@@ -204,3 +211,13 @@ func rcByNamePort(name string, replicas int32, image string, containerArgs []str
Ports: []v1.ContainerPort{{ContainerPort: int32(port), Protocol: protocol}},
}, gracePeriod)
}
// setPodNonRootUser configures the Pod to run as a non-root user.
// For Windows, it sets the RunAsUserName field to ContainerUser, and for Linux, it sets the RunAsUser field to 1000.
func setPodNonRootUser(pod *v1.Pod) {
if framework.NodeOSDistroIs("windows") {
pod.Spec.SecurityContext.WindowsOptions = &v1.WindowsSecurityContextOptions{RunAsUserName: &nonAdminTestUserName}
} else {
pod.Spec.SecurityContext.RunAsUser = &nonRootTestUserID
}
}