Skip to content

Commit 0c7bfa5

Browse files
committed
quality-of-life improvement
Signed-off-by: Daniel Hu <[email protected]>
1 parent 0f6e1e9 commit 0c7bfa5

File tree

7 files changed

+23
-29
lines changed

7 files changed

+23
-29
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,6 @@
2525

2626
# IDE
2727
.idea
28+
29+
# state file
30+
*.state

cmd/devstream/install.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,12 @@ func installCMDFunc(cmd *cobra.Command, args []string) {
4444

4545
errs := p.Execute()
4646
if len(errs) == 0 {
47-
log.Println("=== all plugins' installation are succeeded ===")
47+
log.Println("=== all plugins' Install/Uninstall/Reinstall process are succeeded ===")
48+
log.Println("=== END ===")
4849
return
4950
}
5051

51-
log.Println("=== some errors occurred during plugins installation ===")
52+
log.Println("=== some errors occurred during plugins Install/Uninstall/Reinstall process ===")
5253
for _, err := range errs {
5354
log.Println(err)
5455
}

devstream.state

-17
This file was deleted.

internal/pkg/argocd/argocd.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func (a *ArgoCD) addHelmRepo() error {
5151
return nil
5252
}
5353

54-
func (a *ArgoCD) installOrUpgradeChart() error {
54+
func (a *ArgoCD) installOrUpgradeHelmChart() error {
5555
log.Println("adding and updating argocd helm chart repo")
5656
if err := a.addHelmRepo(); err != nil {
5757
return err
@@ -61,7 +61,7 @@ func (a *ArgoCD) installOrUpgradeChart() error {
6161
ReleaseName: a.param.Chart.ReleaseName,
6262
ChartName: a.param.Chart.Name,
6363
Namespace: a.param.Chart.Namespace,
64-
CreateNamespace: a.param.Chart.CreateNamespace,
64+
CreateNamespace: a.param.Chart.CreateNamespace,
6565
UpgradeCRDs: true,
6666
Wait: true,
6767
Timeout: 3 * time.Minute,

internal/pkg/argocd/install.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ func Install(options *map[string]interface{}) (bool, error) {
1212
}
1313

1414
log.Println("installing or updating argocd helm chart")
15-
if err := acd.installOrUpgradeChart(); err != nil {
15+
if err := acd.installOrUpgradeHelmChart(); err != nil {
1616
return false, err
1717
}
1818

internal/pkg/argocd/reinstall.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ func Reinstall(options *map[string]interface{}) (bool, error) {
1515
return false, err
1616
}
1717

18-
log.Println("installing or updating argocd helm chart")
19-
if err := acd.installOrUpgradeChart(); err != nil {
18+
log.Println("installing argocd helm chart")
19+
if err := acd.installOrUpgradeHelmChart(); err != nil {
2020
return false, err
2121
}
2222

internal/pkg/planmanager/plan.go

+12-5
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,7 @@ func NewPlan(smgr statemanager.Manager, cfg *configloader.Config) *Plan {
5353
smgr.SetStates(states)
5454
log.Println("succeeded to initialize States")
5555
} else {
56-
log.Printf("failed to initialize States. Error: (%s)", err)
57-
log.Println("try to initialize the States.")
56+
log.Printf("failed to initialize States. Error: (%s). try to initialize the States", err)
5857
}
5958

6059
plan := &Plan{
@@ -73,7 +72,10 @@ func NewPlan(smgr statemanager.Manager, cfg *configloader.Config) *Plan {
7372
// All errors will be return.
7473
func (p *Plan) Execute() []error {
7574
errors := make([]error, 0)
76-
for _, c := range p.Changes {
75+
log.Printf("changes count: %d", len(p.Changes))
76+
for i, c := range p.Changes {
77+
log.Printf("procprocessing progress: %d/%d", i+1, len(p.Changes))
78+
log.Printf("processing: %s -> %s", c.Tool.Name, c.ActionName)
7779
// We will consider how to execute Action concurrently later.
7880
// It involves dependency management.
7981
succeeded, err := c.Action(c.Tool)
@@ -97,6 +99,11 @@ func (p *Plan) Execute() []error {
9799

98100
// handleResult is used to Write the latest States to Backend.
99101
func (p *Plan) handleResult(change *Change) error {
102+
if change.ActionName == statemanager.ActionUninstall {
103+
p.smgr.DeleteState(change.Tool.Name)
104+
return p.smgr.Write(p.smgr.GetStates().Format())
105+
}
106+
100107
var state = statemanager.NewState(
101108
change.Tool.Name,
102109
change.Tool.Version,
@@ -111,9 +118,9 @@ func (p *Plan) handleResult(change *Change) error {
111118

112119
if change.Result.Error != nil {
113120
state.Status = statemanager.StatusFailed
114-
log.Printf("=== plugin %s installation failed ===", change.Tool.Name)
121+
log.Printf("=== plugin %s process failed ===", change.Tool.Name)
115122
} else {
116-
log.Printf("=== plugin %s installation done ===", change.Tool.Name)
123+
log.Printf("=== plugin %s process done ===", change.Tool.Name)
117124
}
118125

119126
p.smgr.AddState(state)

0 commit comments

Comments
 (0)