-
Notifications
You must be signed in to change notification settings - Fork 14
/
environments_view.go
74 lines (61 loc) · 2.12 KB
/
environments_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
package views // import "github.com/jenkins-x/octant-jx/pkg/plugin/views"
import (
"github.com/jenkins-x/jx-logging/pkg/log"
v1 "github.com/jenkins-x/jx-api/pkg/apis/jenkins.io/v1"
"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/store"
"github.com/vmware-tanzu/octant/pkg/view/component"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
)
func BuildEnvironmentsView(request service.Request, pluginContext pluginctx.Context) (component.Component, error) {
ctx := request.Context()
client := request.DashboardClient()
dl, err := client.List(ctx, store.Key{
APIVersion: "jenkins.io/v1",
Kind: "Environment",
Namespace: pluginContext.Namespace,
})
if err != nil {
log.Logger().Infof("failed: %s", err.Error())
return nil, err
}
log.Logger().Infof("got list of Environment %d\n", len(dl.Items))
header := component.NewMarkdownText(viewhelpers.ToBreadcrumbMarkdown(plugin.RootBreadcrumb, "Environments"))
table := component.NewTableWithRows(
"Environments", "There are no Environments!",
component.NewTableCols("Name", "Namespace", "Promote", "Source"),
[]component.TableRow{})
for _, pa := range dl.Items {
tr, err := toEnvironmentTableRow(pa)
if err != nil {
log.Logger().Infof("failed to create Table Row: %s", err.Error())
continue
}
if tr != nil {
table.Add(*tr)
}
}
table.Sort("Name", false)
flexLayout := component.NewFlexLayout("")
flexLayout.AddSections(component.FlexLayoutSection{
{Width: component.WidthFull, View: header},
{Width: component.WidthFull, View: table},
})
return flexLayout, nil
}
func toEnvironmentTableRow(u unstructured.Unstructured) (*component.TableRow, error) {
r := &v1.Environment{}
err := viewhelpers.ToStructured(&u, r)
if err != nil {
return nil, err
}
return &component.TableRow{
"Name": ToEnvironmentNameLink(r),
"Source": ToEnvironmentSource(r),
"Namespace": ToEnvironmentNamespace(r),
"Promote": ToEnvironmentPromote(r),
}, nil
}