mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-27 13:37:30 +00:00
Move GetFileModeRegex to e2e/common
because the function is used at e2e/common tests only.
This commit is contained in:
parent
0641e0c6d8
commit
5f81f5b96c
@ -700,7 +700,7 @@ func doConfigMapE2EWithoutMappings(f *framework.Framework, asUser bool, fsGroup
|
|||||||
pod.Spec.Volumes[0].VolumeSource.ConfigMap.DefaultMode = defaultMode
|
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{
|
output := []string{
|
||||||
"content of file \"/etc/configmap-volume/data-1\": value-1",
|
"content of file \"/etc/configmap-volume/data-1\": value-1",
|
||||||
fileModeRegexp,
|
fileModeRegexp,
|
||||||
@ -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",
|
"content of file \"/etc/configmap-volume/path/to/data-2\": value-2",
|
||||||
}
|
}
|
||||||
if fsGroup == 0 {
|
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)
|
output = append(output, fileModeRegexp)
|
||||||
}
|
}
|
||||||
f.TestContainerOutputRegexp("consume configMaps", pod, 0, output)
|
f.TestContainerOutputRegexp("consume configMaps", pod, 0, output)
|
||||||
|
@ -585,7 +585,7 @@ func doProjectedConfigMapE2EWithoutMappings(f *framework.Framework, asUser bool,
|
|||||||
pod.Spec.Volumes[0].VolumeSource.Projected.DefaultMode = defaultMode
|
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{
|
output := []string{
|
||||||
"content of file \"/etc/projected-configmap-volume/data-1\": value-1",
|
"content of file \"/etc/projected-configmap-volume/data-1\": value-1",
|
||||||
fileModeRegexp,
|
fileModeRegexp,
|
||||||
@ -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",
|
"content of file \"/etc/projected-configmap-volume/path/to/data-2\": value-2",
|
||||||
}
|
}
|
||||||
if fsGroup == 0 {
|
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)
|
output = append(output, fileModeRegexp)
|
||||||
}
|
}
|
||||||
f.TestContainerOutputRegexp("consume configMaps", pod, 0, output)
|
f.TestContainerOutputRegexp("consume configMaps", pod, 0, output)
|
||||||
|
@ -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{
|
f.TestContainerOutputRegexp("consume secrets", pod, 0, []string{
|
||||||
"content of file \"/etc/projected-secret-volume/data-1\": value-1",
|
"content of file \"/etc/projected-secret-volume/data-1\": value-1",
|
||||||
fileModeRegexp,
|
fileModeRegexp,
|
||||||
@ -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{
|
expectedOutput := []string{
|
||||||
"content of file \"/etc/projected-secret-volume/data-1\": value-1",
|
"content of file \"/etc/projected-secret-volume/data-1\": value-1",
|
||||||
fileModeRegexp,
|
fileModeRegexp,
|
||||||
@ -570,7 +570,7 @@ func doProjectedSecretE2EWithMapping(f *framework.Framework, mode *int32) {
|
|||||||
pod.Spec.Volumes[0].VolumeSource.Projected.DefaultMode = mode
|
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{
|
expectedOutput := []string{
|
||||||
"content of file \"/etc/projected-secret-volume/new-path-data-1\": value-1",
|
"content of file \"/etc/projected-secret-volume/new-path-data-1\": value-1",
|
||||||
fileModeRegexp,
|
fileModeRegexp,
|
||||||
|
@ -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{
|
f.TestContainerOutputRegexp("consume secrets", pod, 0, []string{
|
||||||
"content of file \"/etc/secret-volume/data-1\": value-1",
|
"content of file \"/etc/secret-volume/data-1\": value-1",
|
||||||
fileModeRegexp,
|
fileModeRegexp,
|
||||||
@ -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{
|
expectedOutput := []string{
|
||||||
"content of file \"/etc/secret-volume/data-1\": value-1",
|
"content of file \"/etc/secret-volume/data-1\": value-1",
|
||||||
fileModeRegexp,
|
fileModeRegexp,
|
||||||
@ -578,7 +578,7 @@ func doSecretE2EWithMapping(f *framework.Framework, mode *int32) {
|
|||||||
pod.Spec.Volumes[0].VolumeSource.Secret.Items[0].Mode = mode
|
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{
|
expectedOutput := []string{
|
||||||
"content of file \"/etc/secret-volume/new-path-data-1\": value-1",
|
"content of file \"/etc/secret-volume/new-path-data-1\": value-1",
|
||||||
fileModeRegexp,
|
fileModeRegexp,
|
||||||
|
@ -20,6 +20,7 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
"text/template"
|
"text/template"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -222,3 +223,24 @@ func setPodNonRootUser(pod *v1.Pod) {
|
|||||||
pod.Spec.SecurityContext.RunAsUser = &nonRootTestUserID
|
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)
|
||||||
|
}
|
||||||
|
@ -1687,27 +1687,6 @@ func DsFromData(data []byte) (*appsv1.DaemonSet, error) {
|
|||||||
return &ds, nil
|
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.
|
// PrettyPrintJSON converts metrics to JSON format.
|
||||||
func PrettyPrintJSON(metrics interface{}) string {
|
func PrettyPrintJSON(metrics interface{}) string {
|
||||||
output := &bytes.Buffer{}
|
output := &bytes.Buffer{}
|
||||||
|
Loading…
Reference in New Issue
Block a user