-
Notifications
You must be signed in to change notification settings - Fork 1
/
render.go
84 lines (73 loc) · 2.5 KB
/
render.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
package render
import (
"fmt"
"github.com/ca-gip/kotaplan/internal/services/aggregate"
"github.com/ca-gip/kotaplan/internal/types"
"github.com/ca-gip/kotaplan/internal/utils"
"github.com/jedib0t/go-pretty/table"
"math"
"os"
"text/template"
)
func NamespaceTable(cluster types.ClusterStat) {
t := table.NewWriter()
t.SetTitle("Namespaces Details")
t.SetStyle(table.StyleLight)
t.SetOutputMirror(os.Stdout)
t.AppendHeader(table.Row{"namespace", "pods", "mem req", "current mem use", "mem req usage", "cpu req", "current cpu use", "cpu req usage", "fit default", "respect max allocation ns", "spec"})
for _, ns := range cluster.NamespacesStat {
t.AppendRow(table.Row{
ns.Name,
ns.PodCount,
utils.ByteToString(ns.MemReq),
utils.ByteToString(ns.MemUse),
ns.MemReqUse,
ns.CpuReq,
ns.CpuUse,
ns.CpuReqUse,
ns.ClaimFit,
ns.RespectMaxNS,
utils.ResourceListToString(ns.Spec),
})
}
t.AppendFooter(table.Row{
cluster.NamespacesCount,
aggregate.PodsSum(cluster),
"", "", "", "", "", "", "", "",
utils.SpecFromIntToString(aggregate.ClaimMemSum(cluster), aggregate.ClaimCpuSum(cluster)),
})
t.Render()
return
}
func SummaryTable(cluster types.ClusterStat, settings *types.Parameters) {
t := table.NewWriter()
t.Style().Options.SeparateColumns = false
t.SetTitle("Summary")
t.SetStyle(table.StyleLight)
t.SetOutputMirror(os.Stdout)
t.AppendRow(table.Row{"Number of nodes", cluster.NodesCount})
t.AppendRow(table.Row{"Available resources (real)", utils.SpecFromIntToString(cluster.MemAvailable, cluster.CpuAvailable)})
t.AppendRow(table.Row{"Available resources (commit)", utils.SpecFromIntToString(int64(math.Round(float64(cluster.MemAvailable)*settings.OverCommitMemory)), int64(float64(cluster.CpuAvailable)*settings.OverCommitCpu))})
t.AppendRow(table.Row{"Max per NS", utils.SpecFromIntToString(int64(float64(cluster.MemAvailable)*settings.RatioNsMemory), int64(float64(cluster.CpuAvailable)*settings.RatioNsCpu))})
t.AppendFooter(table.Row{"Result", utils.Result(cluster, settings)})
t.Render()
}
const ResourceQuotaClaimTmpl = `# Generated by kotaplan
{{- range .NamespacesStat }}
---
apiVersion: ca-gip.github.com/v1
kind: ResourceQuotaClaim
metadata:
name: {{ .Name }}
namespace: {{ .Name }}
spec:
memory: {{ .Spec.Memory.String }}
cpu: {{ .Spec.Cpu.MilliValue }}
{{- end }}`
func Manifest(stat types.ClusterStat) {
tmpl, _ := template.New("manifest").Parse(ResourceQuotaClaimTmpl)
err := tmpl.Execute(os.Stdout, stat)
if err != nil {
_ = fmt.Errorf("%s", err)
}
}