tests: Fixes tests for Windows (containerd, RunAsUserName)

Since we've added support for RunAsUserName, we can now run some new
tests. However, the [LinuxOnly] tag will have to remain until the
WindowsRunAsUserName feature becomes enabled by default.

Additionally, Containerd supports file mounting on Windows, and some
tests will be able to pass on Windows with Containerd instead of Docker.
This commit is contained in:
Claudiu Belu
2019-07-05 12:23:04 +00:00
parent ef479c1a6f
commit f0e6d8ed09
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
@@ -206,3 +213,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
}
}