-
Notifications
You must be signed in to change notification settings - Fork 14
/
logs_view.go
80 lines (69 loc) · 2.32 KB
/
logs_view.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
package views
import (
"fmt"
"strings"
"github.com/jenkins-x/jx-logging/pkg/log"
"github.com/jenkins-x/octant-jx/pkg/common/pluginctx"
"github.com/jenkins-x/octant-jx/pkg/common/viewhelpers"
"github.com/jenkins-x/octant-jx/pkg/plugin"
"github.com/vmware-tanzu/octant/pkg/plugin/service"
"github.com/vmware-tanzu/octant/pkg/view/component"
)
func BuildPipelineLog(request service.Request, pluginContext pluginctx.Context) (component.Component, error) {
path := strings.TrimPrefix(request.Path(), "/")
path = strings.TrimPrefix(path, plugin.LogsPath+"/")
paths := strings.Split(path, "/")
name := paths[0]
ctx := request.Context()
client := request.DashboardClient()
log.Logger().Infof("BuildPipelineLog querying for PipelineActivity %s\n", name)
u, err := viewhelpers.GetResourceByName(ctx, client, "jenkins.io/v1", "PipelineActivity", name, pluginContext.Namespace)
if err != nil {
return nil, err
}
if u == nil {
return component.NewText("Error: pipeline not found"), nil
}
pa, err := viewhelpers.ToPipelineActivity(u)
if err != nil {
log.Logger().Info(err)
return nil, err
}
s := &pa.Spec
header := component.NewMarkdownText(viewhelpers.ToBreadcrumbMarkdown(
plugin.RootBreadcrumb,
viewhelpers.ToMarkdownLink("Pipelines", plugin.GetPipelinesLink()),
s.GitOwner,
s.GitRepository,
viewhelpers.ToMarkdownLink(ToNameMarkdown(pa), plugin.GetPipelineLink(pa.Name)),
"Logs"))
// lets try find the pod for the pipeline
var logsView component.Component
pod, err := findPodForPipeline(ctx, client, pluginContext, pa)
if err != nil {
log.Logger().Info(err)
}
if pod != nil {
ns := pa.Namespace
podName := pod.GetName()
if len(paths) > 1 {
logsView, err = viewhelpers.ViewPipelineLogs(ns, podName, paths[1])
} else {
logsView, err = viewhelpers.ViewPipelineLogs(ns, podName)
}
if err != nil {
log.Logger().Info(err)
logsView = component.NewText(fmt.Sprintf("could not find pod: %s", err.Error()))
}
} else {
logsView = component.NewText("could not find pod")
}
notesCard := component.NewCard(component.TitleFromString("Steps"))
notesCard.SetBody(ToStepsView(pa, pod))
flexLayout := component.NewFlexLayout("")
flexLayout.AddSections(component.FlexLayoutSection{
{Width: component.WidthFull, View: header},
{Width: component.WidthFull, View: logsView},
})
return flexLayout, nil
}