-
Notifications
You must be signed in to change notification settings - Fork 3.2k
/
logs.go
35 lines (30 loc) · 863 Bytes
/
logs.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
package common
import (
"context"
"fmt"
"io"
"github.com/argoproj/pkg/errors"
corev1 "k8s.io/api/core/v1"
workflowpkg "github.com/argoproj/argo-workflows/v3/pkg/apiclient/workflow"
)
func LogWorkflow(ctx context.Context, serviceClient workflowpkg.WorkflowServiceClient, namespace, workflow, podName, grep, selector string, logOptions *corev1.PodLogOptions) {
// logs
stream, err := serviceClient.WorkflowLogs(ctx, &workflowpkg.WorkflowLogRequest{
Name: workflow,
Namespace: namespace,
PodName: podName,
LogOptions: logOptions,
Selector: selector,
Grep: grep,
})
errors.CheckError(err)
// loop on log lines
for {
event, err := stream.Recv()
if err == io.EOF {
return
}
errors.CheckError(err)
fmt.Println(ansiFormat(fmt.Sprintf("%s: %s", event.PodName, event.Content), ansiColorCode(event.PodName)))
}
}