-
Notifications
You must be signed in to change notification settings - Fork 127
/
common.go
85 lines (68 loc) · 1.93 KB
/
common.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package scripts
import (
"fmt"
"os"
"time"
"github.com/kubeshop/testkube/pkg/api/v1/client"
"github.com/kubeshop/testkube/pkg/api/v1/testkube"
"github.com/kubeshop/testkube/pkg/runner/output"
"github.com/kubeshop/testkube/pkg/ui"
)
func printExecutionDetails(execution testkube.Execution) {
ui.Warn("Type :", execution.ScriptType)
ui.Warn("Name :", execution.ScriptName)
ui.Warn("Execution ID :", execution.Id)
ui.Warn("Execution name:", execution.Name)
ui.NL()
ui.NL()
}
func DownloadArtifacts(id, dir string, client client.Client) {
artifacts, err := client.GetExecutionArtifacts(id)
ui.ExitOnError("getting artifacts ", err)
err = os.MkdirAll(dir, os.ModePerm)
ui.ExitOnError("creating dir "+dir, err)
if len(artifacts) > 0 {
ui.Info("Getting artifacts", fmt.Sprintf("count = %d", len(artifacts)), "\n")
}
for _, artifact := range artifacts {
f, err := client.DownloadFile(id, artifact.Name, dir)
ui.ExitOnError("downloading file: "+f, err)
ui.Warn(" - downloading file ", f)
}
ui.NL()
ui.NL()
}
func watchLogs(id string, client client.Client) {
ui.Info("Getting pod logs")
logs, err := client.Logs(id)
ui.ExitOnError("getting logs from executor", err)
for l := range logs {
switch l.Type_ {
case output.TypeError:
ui.Errf(l.Content)
if l.Result != nil {
ui.Errf("Error: %s", l.Result.ErrorMessage)
ui.Debug("Output: %s", l.Result.Output)
}
os.Exit(1)
return
case output.TypeResult:
ui.Info("Execution completed", l.Result.Output)
default:
ui.LogLine(l.String())
}
}
ui.NL()
// TODO watch for success | error status - in case of connection error on logs watch need fix in 0.8
for range time.Tick(time.Second) {
execution, err := client.GetExecution(id)
ui.ExitOnError("get script execution details", err)
fmt.Print(".")
if execution.ExecutionResult.IsCompleted() {
fmt.Println()
uiShellCommandBlock(id)
return
}
}
uiShellCommandBlock(id)
}