Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: Checks for Windows permissions as well #71036

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 6 additions & 13 deletions test/e2e/common/configmap_volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package common

import (
"fmt"
"os"
"path"

. "github.com/onsi/ginkgo"
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand All @@ -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)
}
19 changes: 6 additions & 13 deletions test/e2e/common/projected_configmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package common

import (
"fmt"
"os"
"path"

"k8s.io/api/core/v1"
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand All @@ -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)
}
24 changes: 9 additions & 15 deletions test/e2e/common/projected_secret.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package common

import (
"fmt"
"os"
"path"

"k8s.io/api/core/v1"
Expand Down Expand Up @@ -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,
})
})

Expand Down Expand Up @@ -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 {
Expand All @@ -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) {
Expand Down Expand Up @@ -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)
}
24 changes: 9 additions & 15 deletions test/e2e/common/secrets_volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package common

import (
"fmt"
"os"
"path"

"k8s.io/api/core/v1"
Expand Down Expand Up @@ -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,
})
})

Expand Down Expand Up @@ -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 {
Expand All @@ -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) {
Expand Down Expand Up @@ -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)
}
21 changes: 21 additions & 0 deletions test/e2e/framework/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
jsafrane marked this conversation as resolved.
Show resolved Hide resolved
var (
linuxMask int32
windowsMask int32
)
if mask == nil {
linuxMask = int32(0644)
windowsMask = int32(0775)
claudiubelu marked this conversation as resolved.
Show resolved Hide resolved
} 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)
}