Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: #49 #93 - argocdapp installation failed & logs improved #95

Merged
merged 1 commit into from
Dec 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
6 changes: 3 additions & 3 deletions internal/pkg/statemanager/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ const (
StatusUninstalled ComponentStatus = "uninstalled"
// We use StatusInstalled when a plugin is installed but we don't know its status is "running" or "failed".
// For example: We try to uninstall a plugin but failed for some reason.
StatusInstalled ComponentStatus = "installed"
StatusRunning ComponentStatus = "running"
StatusFailed ComponentStatus = "failed"
StatusInstalled ComponentStatus = "installed"
StatusRunning ComponentStatus = "running"
StatusFailed ComponentStatus = "failed"
)

const (
Expand Down