Skip to content

Commit 71093a0

Browse files
authored
Merge pull request kubernetes#128244 from gnufied/fix-fsgroup-behaviour
Apply fsGroup when accessMode is ReadWriteOncePod
2 parents c73aeaf + 3c1576d commit 71093a0

File tree

5 files changed

+33
-5
lines changed

5 files changed

+33
-5
lines changed

pkg/apis/storage/types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ const (
423423
// ReadWriteOnceWithFSTypeFSGroupPolicy indicates that each volume will be examined
424424
// to determine if the volume ownership and permissions
425425
// should be modified. If a fstype is defined and the volume's access mode
426-
// contains ReadWriteOnce, then the defined fsGroup will be applied.
426+
// contains ReadWriteOnce or ReadWriteOncePod, then the defined fsGroup will be applied.
427427
// This mode should be defined if it's expected that the
428428
// fsGroup may need to be modified depending on the pod's SecurityPolicy.
429429
// This is the default behavior if no other FSGroupPolicy is defined.

pkg/volume/csi/csi_mounter_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -860,6 +860,15 @@ func TestMounterSetUpWithFSGroup(t *testing.T) {
860860
setFsGroup: true,
861861
fsGroup: 3000,
862862
},
863+
{
864+
name: "fstype, fsgroup, RWOP provided (should apply fsgroup)",
865+
accessModes: []corev1.PersistentVolumeAccessMode{
866+
corev1.ReadWriteOncePod,
867+
},
868+
fsType: "ext4",
869+
setFsGroup: true,
870+
fsGroup: 3000,
871+
},
863872
{
864873
name: "fstype, fsgroup, RWO provided, FSGroupPolicy ReadWriteOnceWithFSType (should apply fsgroup)",
865874
accessModes: []corev1.PersistentVolumeAccessMode{

pkg/volume/csi/csi_util.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,8 @@ func hasReadWriteOnce(modes []api.PersistentVolumeAccessMode) bool {
134134
return false
135135
}
136136
for _, mode := range modes {
137-
if mode == api.ReadWriteOnce {
137+
if mode == api.ReadWriteOnce ||
138+
mode == api.ReadWriteOncePod {
138139
return true
139140
}
140141
}

staging/src/k8s.io/api/storage/v1/types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ const (
433433
// ReadWriteOnceWithFSTypeFSGroupPolicy indicates that each volume will be examined
434434
// to determine if the volume ownership and permissions
435435
// should be modified. If a fstype is defined and the volume's access mode
436-
// contains ReadWriteOnce, then the defined fsGroup will be applied.
436+
// contains ReadWriteOnce or ReadWriteOncePod, then the defined fsGroup will be applied.
437437
// This mode should be defined if it's expected that the
438438
// fsGroup may need to be modified depending on the pod's SecurityPolicy.
439439
// This is the default behavior if no other FSGroupPolicy is defined.

test/e2e/storage/testsuites/fsgroupchangepolicy.go

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,6 @@ func (s *fsGroupChangePolicyTestSuite) DefineTests(driver storageframework.TestD
113113
l = local{}
114114
l.driver = driver
115115
l.config = driver.PrepareTest(ctx, f)
116-
testVolumeSizeRange := s.GetTestSuiteInfo().SupportedSizeRange
117-
l.resource = storageframework.CreateVolumeResource(ctx, l.driver, l.config, pattern, testVolumeSizeRange)
118116
}
119117

120118
cleanup := func(ctx context.Context) {
@@ -129,6 +127,8 @@ func (s *fsGroupChangePolicyTestSuite) DefineTests(driver storageframework.TestD
129127
framework.ExpectNoError(errors.NewAggregate(errs), "while cleanup resource")
130128
}
131129

130+
rwopAccessMode := v1.ReadWriteOncePod
131+
132132
tests := []struct {
133133
name string // Test case name
134134
podfsGroupChangePolicy string // 'Always' or 'OnRootMismatch'
@@ -143,6 +143,7 @@ func (s *fsGroupChangePolicyTestSuite) DefineTests(driver storageframework.TestD
143143
// * OnRootMismatch policy is not supported.
144144
// * It may not be possible to chgrp after mounting a volume.
145145
supportsVolumeMountGroup bool
146+
volumeAccessMode *v1.PersistentVolumeAccessMode
146147
}{
147148
// Test cases for 'Always' policy
148149
{
@@ -154,6 +155,16 @@ func (s *fsGroupChangePolicyTestSuite) DefineTests(driver storageframework.TestD
154155
finalExpectedSubDirFileOwnership: 2000,
155156
supportsVolumeMountGroup: true,
156157
},
158+
{
159+
name: "rwop pod created with an initial fsgroup, new pod fsgroup applied to volume contents",
160+
podfsGroupChangePolicy: "Always",
161+
initialPodFsGroup: 1000,
162+
secondPodFsGroup: 2000,
163+
finalExpectedRootDirFileOwnership: 2000,
164+
finalExpectedSubDirFileOwnership: 2000,
165+
supportsVolumeMountGroup: true,
166+
volumeAccessMode: &rwopAccessMode,
167+
},
157168
{
158169
name: "pod created with an initial fsgroup, volume contents ownership changed via chgrp in first pod, new pod with same fsgroup applied to the volume contents",
159170
podfsGroupChangePolicy: "Always",
@@ -218,6 +229,13 @@ func (s *fsGroupChangePolicyTestSuite) DefineTests(driver storageframework.TestD
218229
}
219230

220231
init(ctx)
232+
testVolumeSizeRange := s.GetTestSuiteInfo().SupportedSizeRange
233+
if test.volumeAccessMode != nil {
234+
accessModes := []v1.PersistentVolumeAccessMode{*test.volumeAccessMode}
235+
l.resource = storageframework.CreateVolumeResourceWithAccessModes(ctx, l.driver, l.config, pattern, testVolumeSizeRange, accessModes, nil)
236+
} else {
237+
l.resource = storageframework.CreateVolumeResource(ctx, l.driver, l.config, pattern, testVolumeSizeRange)
238+
}
221239
ginkgo.DeferCleanup(cleanup)
222240
podConfig := e2epod.Config{
223241
NS: f.Namespace.Name,

0 commit comments

Comments
 (0)