mirror of https://github.com/k3s-io/k3s
tests: Checks for Windows permissions as well
Some mounttest related tests are checking the file permissions set on the container files, but the default file permissions on Windows is 775 instead of 644, causing some tests to fail. Keep in mind that file permissions work differently on Windows, and setting file permissions via Kubernetes is not currently supported on Windows.pull/564/head
parent
99811e2540
commit
0df9c0adf6
|
@ -18,7 +18,6 @@ package common
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path"
|
||||
|
||||
. "github.com/onsi/ginkgo"
|
||||
|
@ -622,17 +621,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) {
|
||||
|
@ -708,9 +704,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
|
||||
|
@ -719,8 +712,8 @@ 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)
|
||||
}
|
||||
|
|
|
@ -18,7 +18,6 @@ package common
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path"
|
||||
|
||||
"k8s.io/api/core/v1"
|
||||
|
@ -554,17 +553,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) {
|
||||
|
@ -645,9 +641,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
|
||||
|
@ -656,8 +649,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)
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
})
|
||||
})
|
||||
|
||||
|
@ -461,9 +461,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 {
|
||||
|
@ -473,13 +470,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) {
|
||||
|
@ -547,16 +544,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)
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
})
|
||||
})
|
||||
|
||||
|
@ -431,9 +431,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 {
|
||||
|
@ -443,13 +440,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) {
|
||||
|
@ -508,16 +505,13 @@ 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)
|
||||
}
|
||||
|
|
|
@ -5252,3 +5252,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)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue