Skip to content

Commit

Permalink
Merge pull request #95 from daniel-hutao/dev-2
Browse files Browse the repository at this point in the history
fix: #49 #93 - argocdapp installation failed & logs improved
  • Loading branch information
daniel-hutao committed Dec 29, 2021
2 parents c522b5a + ad54855 commit 60f0d83
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 14 deletions.
8 changes: 4 additions & 4 deletions cmd/devstream/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,16 @@ func installCMDFunc(cmd *cobra.Command, args []string) {
return
}

errs := p.Execute()
if len(errs) == 0 {
errsMap := p.Execute()
if len(errsMap) == 0 {
log.Println("=== all plugins' Install/Uninstall/Reinstall process are succeeded ===")
log.Println("=== END ===")
return
}

log.Println("=== some errors occurred during plugins Install/Uninstall/Reinstall process ===")
for _, err := range errs {
log.Println(err)
for k, err := range errsMap {
log.Printf("%s -> %s", k, err)
}
log.Println("=== END ===")
}
8 changes: 6 additions & 2 deletions internal/pkg/argocdapp/argocdapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,15 @@ type Action string

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

Expand Down
2 changes: 1 addition & 1 deletion internal/pkg/argocdapp/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func Install(options *map[string]interface{}) (bool, error) {
return false, err
}

err = kubectlAction(ActionDelete, file)
err = kubectlAction(ActionApply, file)
if err != nil {
return false, err
}
Expand Down
12 changes: 7 additions & 5 deletions internal/pkg/planmanager/plan.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package planmanager

import (
"fmt"
"log"
"time"

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

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

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

err = p.handleResult(c)
if err != nil {
errors = append(errors, err)
errorsMap["handle-result"] = err
}
}
return errors
return errorsMap
}
4 changes: 2 additions & 2 deletions internal/pkg/planmanager/result.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ func (p *Plan) handleResult(change *Change) error {
// uninstall failed
if change.ActionName == statemanager.ActionUninstall && !change.Result.Succeeded {
state.Status = statemanager.StatusInstalled
log.Printf("=== plugin %s process failed ===", change.Tool.Name)
log.Printf("=== plugin %s uninstall failed ===", change.Tool.Name)
// install or reinstall failed
} else if !change.Result.Succeeded {
state.Status = statemanager.StatusFailed
log.Printf("=== plugin %s process failed ===", change.Tool.Name)
log.Printf("=== plugin %s (re)install failed ===", change.Tool.Name)
// install or reinstall succeeded
} else {
log.Printf("=== plugin %s process done ===", change.Tool.Name)
Expand Down

0 comments on commit 60f0d83

Please sign in to comment.