Fix directory mismatch for volume.SetVolumeOwnership()
In most cases `dir` arg of `SetUpAt()` method of `volume.Mounter` interface is the same as `mounter.GetPath()` because we usually call `SetUpAt()` from `SetUp()` like this:"
```
func (ed *emptyDir) SetUp(mounterArgs volume.MounterArgs) error {
return ed.SetUpAt(ed.GetPath(), mounterArgs)
}
```
(this example is from `volume/emptydir/empty_dir.go`, but there are plenty other examples like that in `volume/*`)
However, there is currently one exception. This is from `volume/projected/projected.go`:
```
if err := wrapped.SetUpAt(dir, mounterArgs); err != nil {
return err
}
```
(see 96306f144a/pkg/volume/projected/projected.go (L203)
)
In this case `dir` is not equal to `wrapped.GetPath()` and `volume.SetVolumeOwnership()` fails when called from `SetUpAt()` of wrapped volume:
```
lstat /var/lib/kubelet/pods/a2f6e58f-7edf-4c48-a97c-ef1b8fd3caf6/volumes/kubernetes.io~empty-dir/wrapped_kube-api-access-knvkv: no such file or directory
```
To fix the issue let's pass `dir` arg to `volume.SetVolumeOwnership()` explicitly, and use it instead of `mounter.GetPath()`.
This commit is contained in:
@@ -166,7 +166,7 @@ func TestSkipPermissionChange(t *testing.T) {
|
||||
}
|
||||
|
||||
mounter := &localFakeMounter{path: tmpDir}
|
||||
ok = skipPermissionChange(mounter, &expectedGid, test.fsGroupChangePolicy)
|
||||
ok = skipPermissionChange(mounter, tmpDir, &expectedGid, test.fsGroupChangePolicy)
|
||||
if ok != test.skipPermssion {
|
||||
t.Errorf("for %s expected skipPermission to be %v got %v", test.description, test.skipPermssion, ok)
|
||||
}
|
||||
@@ -302,8 +302,8 @@ func TestSetVolumeOwnershipMode(t *testing.T) {
|
||||
t.Errorf("for %s error running setup with: %v", test.description, err)
|
||||
}
|
||||
|
||||
mounter := &localFakeMounter{path: tmpDir}
|
||||
err = SetVolumeOwnership(mounter, &expectedGid, test.fsGroupChangePolicy, nil)
|
||||
mounter := &localFakeMounter{path: "FAKE_DIR_DOESNT_EXIST"} // SetVolumeOwnership() must rely on tmpDir
|
||||
err = SetVolumeOwnership(mounter, tmpDir, &expectedGid, test.fsGroupChangePolicy, nil)
|
||||
if err != nil {
|
||||
t.Errorf("for %s error changing ownership with: %v", test.description, err)
|
||||
}
|
||||
@@ -439,7 +439,7 @@ func TestSetVolumeOwnershipOwner(t *testing.T) {
|
||||
|
||||
mounter := &localFakeMounter{path: tmpDir}
|
||||
always := v1.FSGroupChangeAlways
|
||||
err = SetVolumeOwnership(mounter, test.fsGroup, &always, nil)
|
||||
err = SetVolumeOwnership(mounter, tmpDir, test.fsGroup, &always, nil)
|
||||
if err != nil {
|
||||
t.Errorf("for %s error changing ownership with: %v", test.description, err)
|
||||
}
|
||||
|
Reference in New Issue
Block a user