Skip to content

Commit f75d062

Browse files
authored
Merge pull request #83 from daniel-hutao/bugfix
fix: #82 statemanager delete a State when uninstall failed
2 parents d921aac + f85bf4e commit f75d062

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

internal/pkg/planmanager/result.go

+9-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ import (
1010

1111
// handleResult is used to Write the latest States to Backend.
1212
func (p *Plan) handleResult(change *Change) error {
13-
if change.ActionName == statemanager.ActionUninstall {
13+
// uninstall succeeded
14+
if change.ActionName == statemanager.ActionUninstall && change.Result.Succeeded {
1415
p.smgr.DeleteState(change.Tool.Name)
1516
return p.smgr.Write(p.smgr.GetStates().Format())
1617
}
@@ -27,9 +28,15 @@ func (p *Plan) handleResult(change *Change) error {
2728
},
2829
)
2930

30-
if change.Result.Error != nil {
31+
// uninstall failed
32+
if change.ActionName == statemanager.ActionUninstall && !change.Result.Succeeded {
33+
state.Status = statemanager.StatusInstalled
34+
log.Printf("=== plugin %s process failed ===", change.Tool.Name)
35+
// install or reinstall failed
36+
} else if !change.Result.Succeeded {
3137
state.Status = statemanager.StatusFailed
3238
log.Printf("=== plugin %s process failed ===", change.Tool.Name)
39+
// install or reinstall succeeded
3340
} else {
3441
log.Printf("=== plugin %s process done ===", change.Tool.Name)
3542
}

internal/pkg/statemanager/state.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@ type ComponentAction string
1313
const (
1414
// We should delete the state of the "uninstalled" tool at States.
1515
StatusUninstalled ComponentStatus = "uninstalled"
16+
// We use StatusInstalled when a plugin is installed but we don't know its status is "running" or "failed".
17+
// For example: We try to uninstall a plugin but failed for some reason.
1618
StatusInstalled ComponentStatus = "installed"
1719
StatusRunning ComponentStatus = "running"
18-
StatusFailed ComponentStatus = "Failed"
20+
StatusFailed ComponentStatus = "failed"
1921
)
2022

2123
const (

0 commit comments

Comments
 (0)