Merge pull request #71036 from bclau/test-windows-permissions

tests: Checks for Windows permissions as well
pull/564/head
k8s-ci-robot 2018-11-29 11:16:49 -08:00 committed by GitHub
commit 409a5ecae2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 51 additions and 56 deletions

View File

@ -18,7 +18,6 @@ package common
import (
"fmt"
"os"
"path"
. "github.com/onsi/ginkgo"
@ -642,17 +641,14 @@ func doConfigMapE2EWithoutMappings(f *framework.Framework, uid, fsGroup int64, d
if defaultMode != nil {
pod.Spec.Volumes[0].VolumeSource.ConfigMap.DefaultMode = defaultMode
} else {
mode := int32(0644)
defaultMode = &mode
}
modeString := fmt.Sprintf("%v", os.FileMode(*defaultMode))
fileModeRegexp := framework.GetFileModeRegex("/etc/configmap-volume/data-1", defaultMode)
output := []string{
"content of file \"/etc/configmap-volume/data-1\": value-1",
"mode of file \"/etc/configmap-volume/data-1\": " + modeString,
fileModeRegexp,
}
f.TestContainerOutput("consume configMaps", pod, 0, output)
f.TestContainerOutputRegexp("consume configMaps", pod, 0, output)
}
func doConfigMapE2EWithMappings(f *framework.Framework, uid, fsGroup int64, itemMode *int32) {
@ -728,9 +724,6 @@ func doConfigMapE2EWithMappings(f *framework.Framework, uid, fsGroup int64, item
if itemMode != nil {
pod.Spec.Volumes[0].VolumeSource.ConfigMap.Items[0].Mode = itemMode
} else {
mode := int32(0644)
itemMode = &mode
}
// Just check file mode if fsGroup is not set. If fsGroup is set, the
@ -739,10 +732,10 @@ func doConfigMapE2EWithMappings(f *framework.Framework, uid, fsGroup int64, item
"content of file \"/etc/configmap-volume/path/to/data-2\": value-2",
}
if fsGroup == 0 {
modeString := fmt.Sprintf("%v", os.FileMode(*itemMode))
output = append(output, "mode of file \"/etc/configmap-volume/path/to/data-2\": "+modeString)
fileModeRegexp := framework.GetFileModeRegex("/etc/configmap-volume/path/to/data-2", itemMode)
output = append(output, fileModeRegexp)
}
f.TestContainerOutput("consume configMaps", pod, 0, output)
f.TestContainerOutputRegexp("consume configMaps", pod, 0, output)
}
func createNonOptionalConfigMapPod(f *framework.Framework, volumeMountPath, podName string) error {

View File

@ -18,7 +18,6 @@ package common
import (
"fmt"
"os"
"path"
"k8s.io/api/core/v1"
@ -574,17 +573,14 @@ func doProjectedConfigMapE2EWithoutMappings(f *framework.Framework, uid, fsGroup
if defaultMode != nil {
//pod.Spec.Volumes[0].VolumeSource.Projected.Sources[0].ConfigMap.DefaultMode = defaultMode
pod.Spec.Volumes[0].VolumeSource.Projected.DefaultMode = defaultMode
} else {
mode := int32(0644)
defaultMode = &mode
}
modeString := fmt.Sprintf("%v", os.FileMode(*defaultMode))
fileModeRegexp := framework.GetFileModeRegex("/etc/projected-configmap-volume/data-1", defaultMode)
output := []string{
"content of file \"/etc/projected-configmap-volume/data-1\": value-1",
"mode of file \"/etc/projected-configmap-volume/data-1\": " + modeString,
fileModeRegexp,
}
f.TestContainerOutput("consume configMaps", pod, 0, output)
f.TestContainerOutputRegexp("consume configMaps", pod, 0, output)
}
func doProjectedConfigMapE2EWithMappings(f *framework.Framework, uid, fsGroup int64, itemMode *int32) {
@ -665,9 +661,6 @@ func doProjectedConfigMapE2EWithMappings(f *framework.Framework, uid, fsGroup in
if itemMode != nil {
//pod.Spec.Volumes[0].VolumeSource.ConfigMap.Items[0].Mode = itemMode
pod.Spec.Volumes[0].VolumeSource.Projected.DefaultMode = itemMode
} else {
mode := int32(0644)
itemMode = &mode
}
// Just check file mode if fsGroup is not set. If fsGroup is set, the
@ -676,8 +669,8 @@ func doProjectedConfigMapE2EWithMappings(f *framework.Framework, uid, fsGroup in
"content of file \"/etc/projected-configmap-volume/path/to/data-2\": value-2",
}
if fsGroup == 0 {
modeString := fmt.Sprintf("%v", os.FileMode(*itemMode))
output = append(output, "mode of file \"/etc/projected-configmap-volume/path/to/data-2\": "+modeString)
fileModeRegexp := framework.GetFileModeRegex("/etc/projected-configmap-volume/path/to/data-2", itemMode)
output = append(output, fileModeRegexp)
}
f.TestContainerOutput("consume configMaps", pod, 0, output)
f.TestContainerOutputRegexp("consume configMaps", pod, 0, output)
}

View File

@ -18,7 +18,6 @@ package common
import (
"fmt"
"os"
"path"
"k8s.io/api/core/v1"
@ -193,9 +192,10 @@ var _ = Describe("[sig-storage] Projected secret", func() {
},
}
f.TestContainerOutput("consume secrets", pod, 0, []string{
fileModeRegexp := framework.GetFileModeRegex("/etc/projected-secret-volume/data-1", nil)
f.TestContainerOutputRegexp("consume secrets", pod, 0, []string{
"content of file \"/etc/projected-secret-volume/data-1\": value-1",
"mode of file \"/etc/projected-secret-volume/data-1\": -rw-r--r--",
fileModeRegexp,
})
})
@ -481,9 +481,6 @@ func doProjectedSecretE2EWithoutMapping(f *framework.Framework, defaultMode *int
if defaultMode != nil {
//pod.Spec.Volumes[0].VolumeSource.Projected.Sources[0].Secret.DefaultMode = defaultMode
pod.Spec.Volumes[0].VolumeSource.Projected.DefaultMode = defaultMode
} else {
mode := int32(0644)
defaultMode = &mode
}
if fsGroup != nil || uid != nil {
@ -493,13 +490,13 @@ func doProjectedSecretE2EWithoutMapping(f *framework.Framework, defaultMode *int
}
}
modeString := fmt.Sprintf("%v", os.FileMode(*defaultMode))
fileModeRegexp := framework.GetFileModeRegex("/etc/projected-secret-volume/data-1", defaultMode)
expectedOutput := []string{
"content of file \"/etc/projected-secret-volume/data-1\": value-1",
"mode of file \"/etc/projected-secret-volume/data-1\": " + modeString,
fileModeRegexp,
}
f.TestContainerOutput("consume secrets", pod, 0, expectedOutput)
f.TestContainerOutputRegexp("consume secrets", pod, 0, expectedOutput)
}
func doProjectedSecretE2EWithMapping(f *framework.Framework, mode *int32) {
@ -567,16 +564,13 @@ func doProjectedSecretE2EWithMapping(f *framework.Framework, mode *int32) {
if mode != nil {
//pod.Spec.Volumes[0].VolumeSource.Projected.Sources[0].Secret.Items[0].Mode = mode
pod.Spec.Volumes[0].VolumeSource.Projected.DefaultMode = mode
} else {
defaultItemMode := int32(0644)
mode = &defaultItemMode
}
modeString := fmt.Sprintf("%v", os.FileMode(*mode))
fileModeRegexp := framework.GetFileModeRegex("/etc/projected-secret-volume/new-path-data-1", mode)
expectedOutput := []string{
"content of file \"/etc/projected-secret-volume/new-path-data-1\": value-1",
"mode of file \"/etc/projected-secret-volume/new-path-data-1\": " + modeString,
fileModeRegexp,
}
f.TestContainerOutput("consume secrets", pod, 0, expectedOutput)
f.TestContainerOutputRegexp("consume secrets", pod, 0, expectedOutput)
}

View File

@ -18,7 +18,6 @@ package common
import (
"fmt"
"os"
"path"
"k8s.io/api/core/v1"
@ -182,9 +181,10 @@ var _ = Describe("[sig-storage] Secrets", func() {
},
}
f.TestContainerOutput("consume secrets", pod, 0, []string{
fileModeRegexp := framework.GetFileModeRegex("/etc/secret-volume/data-1", nil)
f.TestContainerOutputRegexp("consume secrets", pod, 0, []string{
"content of file \"/etc/secret-volume/data-1\": value-1",
"mode of file \"/etc/secret-volume/data-1\": -rw-r--r--",
fileModeRegexp,
})
})
@ -451,9 +451,6 @@ func doSecretE2EWithoutMapping(f *framework.Framework, defaultMode *int32, secre
if defaultMode != nil {
pod.Spec.Volumes[0].VolumeSource.Secret.DefaultMode = defaultMode
} else {
mode := int32(0644)
defaultMode = &mode
}
if fsGroup != nil || uid != nil {
@ -463,13 +460,13 @@ func doSecretE2EWithoutMapping(f *framework.Framework, defaultMode *int32, secre
}
}
modeString := fmt.Sprintf("%v", os.FileMode(*defaultMode))
fileModeRegexp := framework.GetFileModeRegex("/etc/secret-volume/data-1", defaultMode)
expectedOutput := []string{
"content of file \"/etc/secret-volume/data-1\": value-1",
"mode of file \"/etc/secret-volume/data-1\": " + modeString,
fileModeRegexp,
}
f.TestContainerOutput("consume secrets", pod, 0, expectedOutput)
f.TestContainerOutputRegexp("consume secrets", pod, 0, expectedOutput)
}
func doSecretE2EWithMapping(f *framework.Framework, mode *int32) {
@ -528,18 +525,15 @@ func doSecretE2EWithMapping(f *framework.Framework, mode *int32) {
if mode != nil {
pod.Spec.Volumes[0].VolumeSource.Secret.Items[0].Mode = mode
} else {
defaultItemMode := int32(0644)
mode = &defaultItemMode
}
modeString := fmt.Sprintf("%v", os.FileMode(*mode))
fileModeRegexp := framework.GetFileModeRegex("/etc/secret-volume/new-path-data-1", mode)
expectedOutput := []string{
"content of file \"/etc/secret-volume/new-path-data-1\": value-1",
"mode of file \"/etc/secret-volume/new-path-data-1\": " + modeString,
fileModeRegexp,
}
f.TestContainerOutput("consume secrets", pod, 0, expectedOutput)
f.TestContainerOutputRegexp("consume secrets", pod, 0, expectedOutput)
}
func createNonOptionalSecretPod(f *framework.Framework, volumeMountPath, podName string) error {

View File

@ -5272,3 +5272,24 @@ func WaitForNodeHasTaintOrNot(c clientset.Interface, nodeName string, taint *v1.
}
return nil
}
// GetFileModeRegex returns a file mode related regex which should be matched by the mounttest pods' output.
// If the given mask is nil, then the regex will contain the default OS file modes, which are 0644 for Linux and 0775 for Windows.
func GetFileModeRegex(filePath string, mask *int32) string {
var (
linuxMask int32
windowsMask int32
)
if mask == nil {
linuxMask = int32(0644)
windowsMask = int32(0775)
} else {
linuxMask = *mask
windowsMask = *mask
}
linuxOutput := fmt.Sprintf("mode of file \"%s\": %v", filePath, os.FileMode(linuxMask))
windowsOutput := fmt.Sprintf("mode of Windows file \"%v\": %s", filePath, os.FileMode(windowsMask))
return fmt.Sprintf("(%s|%s)", linuxOutput, windowsOutput)
}