...
1
16
17 package storage
18
19 import (
20 "fmt"
21 "os"
22
23 v1 "k8s.io/api/core/v1"
24 "k8s.io/kubernetes/test/e2e/framework"
25 )
26
27 var (
28
29 nonAdminTestUserName = "ContainerUser"
30
31 nonRootTestUserID = int64(1000)
32 )
33
34
35
36 func setPodNonRootUser(pod *v1.Pod) {
37 if framework.NodeOSDistroIs("windows") {
38 pod.Spec.SecurityContext.WindowsOptions = &v1.WindowsSecurityContextOptions{RunAsUserName: &nonAdminTestUserName}
39 } else {
40 pod.Spec.SecurityContext.RunAsUser = &nonRootTestUserID
41 }
42 }
43
44
45
46 func getFileModeRegex(filePath string, mask *int32) string {
47 var (
48 linuxMask int32
49 windowsMask int32
50 )
51 if mask == nil {
52 linuxMask = int32(0644)
53 windowsMask = int32(0775)
54 } else {
55 linuxMask = *mask
56 windowsMask = *mask
57 }
58
59 linuxOutput := fmt.Sprintf("mode of file \"%s\": %v", filePath, os.FileMode(linuxMask))
60 windowsOutput := fmt.Sprintf("mode of Windows file \"%v\": %s", filePath, os.FileMode(windowsMask))
61
62 return fmt.Sprintf("(%s|%s)", linuxOutput, windowsOutput)
63 }
64
65
66 func createMounts(volumeName, volumeMountPath string, readOnly bool) []v1.VolumeMount {
67 return []v1.VolumeMount{
68 {
69 Name: volumeName,
70 MountPath: volumeMountPath,
71 ReadOnly: readOnly,
72 },
73 }
74 }
75
View as plain text