Skip to content

Commit a04c098

Browse files
authored
Merge pull request kubernetes#89386 from oomichi/GetFileModeRegex
Move GetFileModeRegex to e2e/common
2 parents 907d4c1 + 5f81f5b commit a04c098

File tree

6 files changed

+32
-31
lines changed

6 files changed

+32
-31
lines changed

test/e2e/common/configmap_volume.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -700,7 +700,7 @@ func doConfigMapE2EWithoutMappings(f *framework.Framework, asUser bool, fsGroup
700700
pod.Spec.Volumes[0].VolumeSource.ConfigMap.DefaultMode = defaultMode
701701
}
702702

703-
fileModeRegexp := framework.GetFileModeRegex("/etc/configmap-volume/data-1", defaultMode)
703+
fileModeRegexp := getFileModeRegex("/etc/configmap-volume/data-1", defaultMode)
704704
output := []string{
705705
"content of file \"/etc/configmap-volume/data-1\": value-1",
706706
fileModeRegexp,
@@ -788,7 +788,7 @@ func doConfigMapE2EWithMappings(f *framework.Framework, asUser bool, fsGroup int
788788
"content of file \"/etc/configmap-volume/path/to/data-2\": value-2",
789789
}
790790
if fsGroup == 0 {
791-
fileModeRegexp := framework.GetFileModeRegex("/etc/configmap-volume/path/to/data-2", itemMode)
791+
fileModeRegexp := getFileModeRegex("/etc/configmap-volume/path/to/data-2", itemMode)
792792
output = append(output, fileModeRegexp)
793793
}
794794
f.TestContainerOutputRegexp("consume configMaps", pod, 0, output)

test/e2e/common/projected_configmap.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -585,7 +585,7 @@ func doProjectedConfigMapE2EWithoutMappings(f *framework.Framework, asUser bool,
585585
pod.Spec.Volumes[0].VolumeSource.Projected.DefaultMode = defaultMode
586586
}
587587

588-
fileModeRegexp := framework.GetFileModeRegex("/etc/projected-configmap-volume/data-1", defaultMode)
588+
fileModeRegexp := getFileModeRegex("/etc/projected-configmap-volume/data-1", defaultMode)
589589
output := []string{
590590
"content of file \"/etc/projected-configmap-volume/data-1\": value-1",
591591
fileModeRegexp,
@@ -678,7 +678,7 @@ func doProjectedConfigMapE2EWithMappings(f *framework.Framework, asUser bool, fs
678678
"content of file \"/etc/projected-configmap-volume/path/to/data-2\": value-2",
679679
}
680680
if fsGroup == 0 {
681-
fileModeRegexp := framework.GetFileModeRegex("/etc/projected-configmap-volume/path/to/data-2", itemMode)
681+
fileModeRegexp := getFileModeRegex("/etc/projected-configmap-volume/path/to/data-2", itemMode)
682682
output = append(output, fileModeRegexp)
683683
}
684684
f.TestContainerOutputRegexp("consume configMaps", pod, 0, output)

test/e2e/common/projected_secret.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ var _ = ginkgo.Describe("[sig-storage] Projected secret", func() {
196196
},
197197
}
198198

199-
fileModeRegexp := framework.GetFileModeRegex("/etc/projected-secret-volume/data-1", nil)
199+
fileModeRegexp := getFileModeRegex("/etc/projected-secret-volume/data-1", nil)
200200
f.TestContainerOutputRegexp("consume secrets", pod, 0, []string{
201201
"content of file \"/etc/projected-secret-volume/data-1\": value-1",
202202
fileModeRegexp,
@@ -494,7 +494,7 @@ func doProjectedSecretE2EWithoutMapping(f *framework.Framework, defaultMode *int
494494
}
495495
}
496496

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

573-
fileModeRegexp := framework.GetFileModeRegex("/etc/projected-secret-volume/new-path-data-1", mode)
573+
fileModeRegexp := getFileModeRegex("/etc/projected-secret-volume/new-path-data-1", mode)
574574
expectedOutput := []string{
575575
"content of file \"/etc/projected-secret-volume/new-path-data-1\": value-1",
576576
fileModeRegexp,

test/e2e/common/secrets_volume.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ var _ = ginkgo.Describe("[sig-storage] Secrets", func() {
186186
},
187187
}
188188

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

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

581-
fileModeRegexp := framework.GetFileModeRegex("/etc/secret-volume/new-path-data-1", mode)
581+
fileModeRegexp := getFileModeRegex("/etc/secret-volume/new-path-data-1", mode)
582582
expectedOutput := []string{
583583
"content of file \"/etc/secret-volume/new-path-data-1\": value-1",
584584
fileModeRegexp,

test/e2e/common/util.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"bytes"
2121
"context"
2222
"fmt"
23+
"os"
2324
"text/template"
2425
"time"
2526

@@ -222,3 +223,24 @@ func setPodNonRootUser(pod *v1.Pod) {
222223
pod.Spec.SecurityContext.RunAsUser = &nonRootTestUserID
223224
}
224225
}
226+
227+
// getFileModeRegex returns a file mode related regex which should be matched by the mounttest pods' output.
228+
// 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.
229+
func getFileModeRegex(filePath string, mask *int32) string {
230+
var (
231+
linuxMask int32
232+
windowsMask int32
233+
)
234+
if mask == nil {
235+
linuxMask = int32(0644)
236+
windowsMask = int32(0775)
237+
} else {
238+
linuxMask = *mask
239+
windowsMask = *mask
240+
}
241+
242+
linuxOutput := fmt.Sprintf("mode of file \"%s\": %v", filePath, os.FileMode(linuxMask))
243+
windowsOutput := fmt.Sprintf("mode of Windows file \"%v\": %s", filePath, os.FileMode(windowsMask))
244+
245+
return fmt.Sprintf("(%s|%s)", linuxOutput, windowsOutput)
246+
}

test/e2e/framework/util.go

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1687,27 +1687,6 @@ func DsFromData(data []byte) (*appsv1.DaemonSet, error) {
16871687
return &ds, nil
16881688
}
16891689

1690-
// GetFileModeRegex returns a file mode related regex which should be matched by the mounttest pods' output.
1691-
// 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.
1692-
func GetFileModeRegex(filePath string, mask *int32) string {
1693-
var (
1694-
linuxMask int32
1695-
windowsMask int32
1696-
)
1697-
if mask == nil {
1698-
linuxMask = int32(0644)
1699-
windowsMask = int32(0775)
1700-
} else {
1701-
linuxMask = *mask
1702-
windowsMask = *mask
1703-
}
1704-
1705-
linuxOutput := fmt.Sprintf("mode of file \"%s\": %v", filePath, os.FileMode(linuxMask))
1706-
windowsOutput := fmt.Sprintf("mode of Windows file \"%v\": %s", filePath, os.FileMode(windowsMask))
1707-
1708-
return fmt.Sprintf("(%s|%s)", linuxOutput, windowsOutput)
1709-
}
1710-
17111690
// PrettyPrintJSON converts metrics to JSON format.
17121691
func PrettyPrintJSON(metrics interface{}) string {
17131692
output := &bytes.Buffer{}

0 commit comments

Comments
 (0)