Skip to content

Commit

Permalink
Merge pull request #65 from uselagoon/fix/error_verbosity_and_name
Browse files Browse the repository at this point in the history
  • Loading branch information
shreddedbacon authored Jul 18, 2022
2 parents aef1fcc + af611e6 commit 541b877
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
7 changes: 5 additions & 2 deletions cmd/tasks_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ var tasksPreRun = &cobra.Command{
fmt.Println("Executing Pre-rollout Tasks")
err = runTasks(iterateTaskGenerator(true, runCleanTaskInEnvironment), lYAML.Tasks.Prerollout, lagoonConditionalEvaluationEnvironment)
if err != nil {
return err
fmt.Println("Pre-rollout Tasks Failed with the following error: " + err.Error())
os.Exit(1)
}
fmt.Println("Pre-rollout Tasks Complete")
return nil
Expand All @@ -62,7 +63,8 @@ var tasksPostRun = &cobra.Command{
fmt.Println("Executing Post-rollout Tasks")
err = runTasks(iterateTaskGenerator(false, runCleanTaskInEnvironment), lYAML.Tasks.Postrollout, lagoonConditionalEvaluationEnvironment)
if err != nil {
return err
fmt.Println("Post-rollout Tasks Failed with the following error: " + err.Error())
os.Exit(1)
}
fmt.Println("Post-rollout Tasks Complete")
return nil
Expand Down Expand Up @@ -206,6 +208,7 @@ func runCleanTaskInEnvironment(incoming lagoon.Task) error {
task.Service = incoming.Service
task.Shell = incoming.Shell
task.Container = incoming.Container
task.Name = incoming.Name
err := lagoon.ExecuteTaskInEnvironment(task)
return err
}
Expand Down
22 changes: 13 additions & 9 deletions internal/lagoon/tasks.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func getConfig() (*rest.Config, error) {
// ExecuteTaskInEnvironment .
func ExecuteTaskInEnvironment(task Task) error {
if debug {
fmt.Printf("Executing task '%v':'%v'", task.Name, task.Command)
fmt.Printf("Executing task '%v':'%v'\n", task.Name, task.Command)
}
command := make([]string, 0, 5)
if task.Shell != "" {
Expand All @@ -118,14 +118,18 @@ func ExecuteTaskInEnvironment(task Task) error {
command = append(command, task.Command)

stdout, stderr, err := ExecPod(task.Service, task.Namespace, command, false, task.Container)
if err == nil {
if len(stdout) > 0 {
fmt.Printf("*** Task STDOUT ***\n %v \n *** STDOUT Ends ***\n", stdout)
}
if len(stderr) > 0 {
fmt.Printf("*** Task STDERR ***\n %v \n *** STDERR Ends ***\n", stderr)
}

if err != nil {
fmt.Printf("*** Task '%v' failed - STDOUT and STDERR follows ***\n", task.Name)
}

if len(stdout) > 0 {
fmt.Printf("*** Task STDOUT ***\n %v \n *** STDOUT Ends ***\n", stdout)
}
if len(stderr) > 0 {
fmt.Printf("*** Task STDERR ***\n %v \n *** STDERR Ends ***\n", stderr)
}

return err
}

Expand Down Expand Up @@ -266,7 +270,7 @@ func ExecPod(
Tty: tty,
})
if err != nil {
return "", "", fmt.Errorf("error in Stream: %v", err)
return stdout.String(), stderr.String(), fmt.Errorf("Error returned: %v", err)
}

return stdout.String(), stderr.String(), nil
Expand Down

0 comments on commit 541b877

Please sign in to comment.