-
Notifications
You must be signed in to change notification settings - Fork 1
/
summarizer.go
65 lines (52 loc) · 1.92 KB
/
summarizer.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
package applications
import (
"context"
"fmt"
"github.com/pkg/errors"
"github.com/vmware/octant/pkg/store"
"github.com/vmware/octant/pkg/view/component"
)
//go:generate mockgen -destination=./fake/mock_summarizer.go -package=fake github.com/vmware/octant/internal/modules/applications Summarizer
var (
applicationListColumns = component.NewTableCols("Name", "Instance", "Version", "State", "Pods")
)
const (
appLabelName = "app.kubernetes.io/name"
appLabelInstance = "app.kubernetes.io/instance"
appLabelVersion = "app.kubernetes.io/version"
)
// SummarizerConfig is configuration for Summarize.
type SummarizerConfig interface {
ObjectStore() store.Store
}
// Summarizer summarizes applications for a namespace. Applications are a group of objects
// labeled with matching application labels. Application labels are:
// * app.kubernetes.io/name
// * app.kubernetes.io/instance
// * app.kubernetes.io/version
type Summarizer interface {
// Summarize generates a table summary.
Summarize(ctx context.Context, namespace string, config SummarizerConfig) (*component.Table, error)
}
type summarizer struct{}
// Summarize converts applications in namespace to a table.
func (s *summarizer) Summarize(ctx context.Context, namespace string, config SummarizerConfig) (*component.Table, error) {
if config == nil {
return nil, errors.Errorf("config is nil")
}
applications, err := listApplications(ctx, config.ObjectStore(), namespace)
if err != nil {
return nil, err
}
table := component.NewTable("Applications", "applications", applicationListColumns)
for _, d := range applications {
table.Add(component.TableRow{
"Name": component.NewLink("", d.Name, d.Path("applications", namespace)),
"Instance": component.NewText(d.Instance),
"Version": component.NewText(d.Version),
"State": component.NewText("state"),
"Pods": component.NewText(fmt.Sprintf("%d", d.PodCount)),
})
}
return table, nil
}