Skip to content

Commit 60f0d83

Browse files
authored
Merge pull request #95 from daniel-hutao/dev-2
fix: #49 #93 - argocdapp installation failed & logs improved
2 parents c522b5a + ad54855 commit 60f0d83

File tree

5 files changed

+20
-14
lines changed

5 files changed

+20
-14
lines changed

cmd/devstream/install.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,16 @@ func installCMDFunc(cmd *cobra.Command, args []string) {
4242
return
4343
}
4444

45-
errs := p.Execute()
46-
if len(errs) == 0 {
45+
errsMap := p.Execute()
46+
if len(errsMap) == 0 {
4747
log.Println("=== all plugins' Install/Uninstall/Reinstall process are succeeded ===")
4848
log.Println("=== END ===")
4949
return
5050
}
5151

5252
log.Println("=== some errors occurred during plugins Install/Uninstall/Reinstall process ===")
53-
for _, err := range errs {
54-
log.Println(err)
53+
for k, err := range errsMap {
54+
log.Printf("%s -> %s", k, err)
5555
}
5656
log.Println("=== END ===")
5757
}

internal/pkg/argocdapp/argocdapp.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,15 @@ type Action string
2020

2121
func kubectlAction(action Action, filename string) error {
2222
cmd := exec.Command("kubectl", string(action), "-f", filename)
23-
stdout, err := cmd.Output()
23+
cOut, err := cmd.CombinedOutput()
2424
if err != nil {
25+
// TODO(Daniel Hu): Handle the Error below:
26+
// Error from server (NotFound): error when deleting "./app.yaml": applications.argoproj.io "hello" not found
27+
log.Printf("failed to exec: < %s >", cmd.String())
28+
log.Printf("exec logs: < %s >. got error: %s", string(cOut), err)
2529
return err
2630
}
27-
log.Println(strings.TrimSuffix(string(stdout), "\n"))
31+
log.Println(strings.TrimSuffix(string(cOut), "\n"))
2832
return nil
2933
}
3034

internal/pkg/argocdapp/install.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ func Install(options *map[string]interface{}) (bool, error) {
1818
return false, err
1919
}
2020

21-
err = kubectlAction(ActionDelete, file)
21+
err = kubectlAction(ActionApply, file)
2222
if err != nil {
2323
return false, err
2424
}

internal/pkg/planmanager/plan.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package planmanager
22

33
import (
4+
"fmt"
45
"log"
56
"time"
67

@@ -50,8 +51,8 @@ func NewPlan(smgr statemanager.Manager, cfg *configloader.Config) *Plan {
5051

5152
// Execute will execute all changes included in the Plan and record results.
5253
// All errors will be return.
53-
func (p *Plan) Execute() []error {
54-
errors := make([]error, 0)
54+
func (p *Plan) Execute() map[string]error {
55+
errorsMap := make(map[string]error)
5556
log.Printf("changes count: %d", len(p.Changes))
5657
for i, c := range p.Changes {
5758
log.Printf("processing progress: %d/%d", i+1, len(p.Changes))
@@ -60,7 +61,8 @@ func (p *Plan) Execute() []error {
6061
// It involves dependency management.
6162
succeeded, err := c.Action(c.Tool)
6263
if err != nil {
63-
errors = append(errors, err)
64+
key := fmt.Sprintf("%s-%s", c.Tool.Name, c.ActionName)
65+
errorsMap[key] = err
6466
}
6567

6668
c.Result = &ChangeResult{
@@ -71,8 +73,8 @@ func (p *Plan) Execute() []error {
7173

7274
err = p.handleResult(c)
7375
if err != nil {
74-
errors = append(errors, err)
76+
errorsMap["handle-result"] = err
7577
}
7678
}
77-
return errors
79+
return errorsMap
7880
}

internal/pkg/planmanager/result.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ func (p *Plan) handleResult(change *Change) error {
3131
// uninstall failed
3232
if change.ActionName == statemanager.ActionUninstall && !change.Result.Succeeded {
3333
state.Status = statemanager.StatusInstalled
34-
log.Printf("=== plugin %s process failed ===", change.Tool.Name)
34+
log.Printf("=== plugin %s uninstall failed ===", change.Tool.Name)
3535
// install or reinstall failed
3636
} else if !change.Result.Succeeded {
3737
state.Status = statemanager.StatusFailed
38-
log.Printf("=== plugin %s process failed ===", change.Tool.Name)
38+
log.Printf("=== plugin %s (re)install failed ===", change.Tool.Name)
3939
// install or reinstall succeeded
4040
} else {
4141
log.Printf("=== plugin %s process done ===", change.Tool.Name)

0 commit comments

Comments
 (0)