...
1
2
3
4
19
20 package local
21
22 import (
23 "os"
24 "syscall"
25 "testing"
26
27 "k8s.io/api/core/v1"
28 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
29 "k8s.io/apimachinery/pkg/types"
30 )
31
32 func TestFSGroupMount(t *testing.T) {
33 tmpDir, plug := getPlugin(t)
34 defer os.RemoveAll(tmpDir)
35 info, err := os.Stat(tmpDir)
36 if err != nil {
37 t.Errorf("Error getting stats for %s (%v)", tmpDir, err)
38 }
39 s := info.Sys().(*syscall.Stat_t)
40 if s == nil {
41 t.Fatalf("Error getting stats for %s (%v)", tmpDir, err)
42 }
43 fsGroup1 := int64(s.Gid)
44 fsGroup2 := fsGroup1 + 1
45 pod1 := &v1.Pod{ObjectMeta: metav1.ObjectMeta{UID: types.UID("poduid")}}
46 pod1.Spec.SecurityContext = &v1.PodSecurityContext{
47 FSGroup: &fsGroup1,
48 }
49 pod2 := &v1.Pod{ObjectMeta: metav1.ObjectMeta{UID: types.UID("poduid")}}
50 pod2.Spec.SecurityContext = &v1.PodSecurityContext{
51 FSGroup: &fsGroup2,
52 }
53 err = testFSGroupMount(plug, pod1, tmpDir, fsGroup1)
54 if err != nil {
55 t.Errorf("Failed to make a new Mounter: %v", err)
56 }
57 err = testFSGroupMount(plug, pod2, tmpDir, fsGroup2)
58 if err != nil {
59 t.Errorf("Failed to make a new Mounter: %v", err)
60 }
61
62 s = info.Sys().(*syscall.Stat_t)
63 if s == nil {
64 t.Fatalf("Error getting stats for %s (%v)", tmpDir, err)
65 }
66 if fsGroup1 != int64(s.Gid) {
67 t.Errorf("Old Gid %d for volume %s got overwritten by new Gid %d", fsGroup1, tmpDir, int64(s.Gid))
68 }
69 }
70
View as plain text