Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove rollback from Unmount method
Browse files Browse the repository at this point in the history
amogh09 committed Dec 21, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent dd98e33 commit 7b9ebc4
Showing 2 changed files with 1 addition and 44 deletions.
12 changes: 1 addition & 11 deletions ecs-init/volumes/ecs_volume_plugin.go
Original file line number Diff line number Diff line change
@@ -306,17 +306,7 @@ func (a *AmazonECSVolumePlugin) Unmount(r *volume.UnmountRequest) error {
// Save state
if err := a.state.recordVolume(r.Name, vol); err != nil {
// State save failed, so roll back the changes made so far to make state consistent
seelog.Errorf("Error saving state of volume %s, rolling back changes: %v", r.Name, err)
if len(vol.Mounts) == 0 {
seelog.Warnf("Rolling back unmounting of volume %s", r.Name)
req := &driver.CreateRequest{Name: r.Name, Path: vol.Path, Options: vol.Options}
if err := volDriver.Create(req); err != nil {
seelog.Errorf("Failed to mount volume %s during rollback: %v", r.Name, err)
}
}
vol.AddMount(r.ID)
a.state.recordVolume(r.Name, vol)
return fmt.Errorf("unmount failed due to an error while saving state: %w", err)
seelog.Errorf("Error saving state of volume %s", r.Name, err)
}

// All good
33 changes: 0 additions & 33 deletions ecs-init/volumes/ecs_volume_plugin_test.go
Original file line number Diff line number Diff line change
@@ -1040,39 +1040,6 @@ func TestPluginUnmount(t *testing.T) {
plugin.state.VolState)
},
},
{
name: "roll back unmount if saving state fails",
setDriverExpectations: func(d *mock_driver.MockVolumeDriver) {
d.EXPECT().Remove(&driver.RemoveRequest{Name: volName}).Return(nil)
d.EXPECT().
Create(&driver.CreateRequest{Name: volName, Path: volPath, Options: volOpts}).
Return(nil)
},
pluginVolumes: map[string]*types.Volume{
volName: {
Path: volPath, Options: volOpts, Mounts: map[string]*string{reqMountID: nil},
},
},
mockSaveStateFn: func(b []byte) error { return errors.New("some error") },
req: &volume.UnmountRequest{Name: volName, ID: reqMountID},
expectedError: "unmount failed due to an error while saving state: some error",
assertPluginState: func(t *testing.T, plugin *AmazonECSVolumePlugin) {
// Mount should still exist in state
mounts := map[string]*string{reqMountID: nil}
assert.Equal(t,
map[string]*types.Volume{
volName: {Path: volPath, Mounts: mounts, Options: volOpts},
},
plugin.volumes)
assert.Equal(t,
&VolumeState{
Volumes: map[string]*VolumeInfo{
volName: {Path: volPath, Mounts: mounts, Options: volOpts},
},
},
plugin.state.VolState)
},
},
{
name: "no-op when mount not found on the volume",
pluginVolumes: map[string]*types.Volume{volName: {Path: volPath, Options: volOpts}},

0 comments on commit 7b9ebc4

Please sign in to comment.