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

Move GetFileModeRegex to e2e/common #89386

Merged
merged 1 commit into from Mar 24, 2020
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
4 changes: 2 additions & 2 deletions test/e2e/common/configmap_volume.go
Expand Up @@ -700,7 +700,7 @@ func doConfigMapE2EWithoutMappings(f *framework.Framework, asUser bool, fsGroup
pod.Spec.Volumes[0].VolumeSource.ConfigMap.DefaultMode = defaultMode
}

fileModeRegexp := framework.GetFileModeRegex("/etc/configmap-volume/data-1", defaultMode)
fileModeRegexp := getFileModeRegex("/etc/configmap-volume/data-1", defaultMode)
output := []string{
"content of file \"/etc/configmap-volume/data-1\": value-1",
fileModeRegexp,
Expand Down Expand Up @@ -788,7 +788,7 @@ func doConfigMapE2EWithMappings(f *framework.Framework, asUser bool, fsGroup int
"content of file \"/etc/configmap-volume/path/to/data-2\": value-2",
}
if fsGroup == 0 {
fileModeRegexp := framework.GetFileModeRegex("/etc/configmap-volume/path/to/data-2", itemMode)
fileModeRegexp := getFileModeRegex("/etc/configmap-volume/path/to/data-2", itemMode)
output = append(output, fileModeRegexp)
}
f.TestContainerOutputRegexp("consume configMaps", pod, 0, output)
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/common/projected_configmap.go
Expand Up @@ -585,7 +585,7 @@ func doProjectedConfigMapE2EWithoutMappings(f *framework.Framework, asUser bool,
pod.Spec.Volumes[0].VolumeSource.Projected.DefaultMode = defaultMode
}

fileModeRegexp := framework.GetFileModeRegex("/etc/projected-configmap-volume/data-1", defaultMode)
fileModeRegexp := getFileModeRegex("/etc/projected-configmap-volume/data-1", defaultMode)
output := []string{
"content of file \"/etc/projected-configmap-volume/data-1\": value-1",
fileModeRegexp,
Expand Down Expand Up @@ -678,7 +678,7 @@ func doProjectedConfigMapE2EWithMappings(f *framework.Framework, asUser bool, fs
"content of file \"/etc/projected-configmap-volume/path/to/data-2\": value-2",
}
if fsGroup == 0 {
fileModeRegexp := framework.GetFileModeRegex("/etc/projected-configmap-volume/path/to/data-2", itemMode)
fileModeRegexp := getFileModeRegex("/etc/projected-configmap-volume/path/to/data-2", itemMode)
output = append(output, fileModeRegexp)
}
f.TestContainerOutputRegexp("consume configMaps", pod, 0, output)
Expand Down
6 changes: 3 additions & 3 deletions test/e2e/common/projected_secret.go
Expand Up @@ -196,7 +196,7 @@ var _ = ginkgo.Describe("[sig-storage] Projected secret", func() {
},
}

fileModeRegexp := framework.GetFileModeRegex("/etc/projected-secret-volume/data-1", nil)
fileModeRegexp := 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",
fileModeRegexp,
Expand Down Expand Up @@ -494,7 +494,7 @@ func doProjectedSecretE2EWithoutMapping(f *framework.Framework, defaultMode *int
}
}

fileModeRegexp := framework.GetFileModeRegex("/etc/projected-secret-volume/data-1", defaultMode)
fileModeRegexp := getFileModeRegex("/etc/projected-secret-volume/data-1", defaultMode)
expectedOutput := []string{
"content of file \"/etc/projected-secret-volume/data-1\": value-1",
fileModeRegexp,
Expand Down Expand Up @@ -570,7 +570,7 @@ func doProjectedSecretE2EWithMapping(f *framework.Framework, mode *int32) {
pod.Spec.Volumes[0].VolumeSource.Projected.DefaultMode = mode
}

fileModeRegexp := framework.GetFileModeRegex("/etc/projected-secret-volume/new-path-data-1", mode)
fileModeRegexp := 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",
fileModeRegexp,
Expand Down
6 changes: 3 additions & 3 deletions test/e2e/common/secrets_volume.go
Expand Up @@ -186,7 +186,7 @@ var _ = ginkgo.Describe("[sig-storage] Secrets", func() {
},
}

fileModeRegexp := framework.GetFileModeRegex("/etc/secret-volume/data-1", nil)
fileModeRegexp := getFileModeRegex("/etc/secret-volume/data-1", nil)
f.TestContainerOutputRegexp("consume secrets", pod, 0, []string{
"content of file \"/etc/secret-volume/data-1\": value-1",
fileModeRegexp,
Expand Down Expand Up @@ -511,7 +511,7 @@ func doSecretE2EWithoutMapping(f *framework.Framework, defaultMode *int32, secre
}
}

fileModeRegexp := framework.GetFileModeRegex("/etc/secret-volume/data-1", defaultMode)
fileModeRegexp := getFileModeRegex("/etc/secret-volume/data-1", defaultMode)
expectedOutput := []string{
"content of file \"/etc/secret-volume/data-1\": value-1",
fileModeRegexp,
Expand Down Expand Up @@ -578,7 +578,7 @@ func doSecretE2EWithMapping(f *framework.Framework, mode *int32) {
pod.Spec.Volumes[0].VolumeSource.Secret.Items[0].Mode = mode
}

fileModeRegexp := framework.GetFileModeRegex("/etc/secret-volume/new-path-data-1", mode)
fileModeRegexp := getFileModeRegex("/etc/secret-volume/new-path-data-1", mode)
expectedOutput := []string{
"content of file \"/etc/secret-volume/new-path-data-1\": value-1",
fileModeRegexp,
Expand Down
22 changes: 22 additions & 0 deletions test/e2e/common/util.go
Expand Up @@ -20,6 +20,7 @@ import (
"bytes"
"context"
"fmt"
"os"
"text/template"
"time"

Expand Down Expand Up @@ -222,3 +223,24 @@ func setPodNonRootUser(pod *v1.Pod) {
pod.Spec.SecurityContext.RunAsUser = &nonRootTestUserID
}
}

// 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)
}
21 changes: 0 additions & 21 deletions test/e2e/framework/util.go
Expand Up @@ -1687,27 +1687,6 @@ func DsFromData(data []byte) (*appsv1.DaemonSet, error) {
return &ds, 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)
}

// PrettyPrintJSON converts metrics to JSON format.
func PrettyPrintJSON(metrics interface{}) string {
output := &bytes.Buffer{}
Expand Down