Skip to content
This repository has been archived by the owner on Sep 16, 2023. It is now read-only.

Commit

Permalink
feat: add basic html styling
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Kotzbauer <christian.kotzbauer@gmail.com>
  • Loading branch information
ckotzbauer committed May 16, 2021
1 parent 6877c57 commit d5c17bb
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 59 deletions.
62 changes: 32 additions & 30 deletions pkg/ha/html.go
Original file line number Diff line number Diff line change
@@ -1,32 +1,34 @@
package ha

var HtmlPage = `<html>
<body>
<table>
<thead>
<tr>
<td>Name</td>
<td>Type</td>
<td>Replicas</td>
<td>Rollout Strategy</td>
<td>Anti-Affinity</td>
<td>PVCs</td>
<td>Rank</td>
</tr>
</thead>
<tbody>
{{range .Items}}
<tr>
<td>{{.Name}}</td>
<td>{{.Type}}</td>
<td>{{.Replicas}}</td>
<td>{{.RolloutStrategy}}</td>
<td>{{.PodAntiAffinity}}</td>
<td>{{.PVC}}</td>
<td>{{.Rank}}</td>
</tr>
{{end}}
</tbody>
</table>
</body>
</html>`
var HtmlPage = `
<h2>High Availability</h2>
<table class="responsive-table highlight">
<thead>
<tr>
<th>Namespace</th>
<th>Name</th>
<th>Type</th>
<th>Replicas</th>
<th>Rollout Strategy</th>
<th>Anti-Affinity</th>
<th>PVCs</th>
<th>Rank</th>
</tr>
</thead>
<tbody>
{{range .Items}}
<tr>
<td>{{.Namespace}}</td>
<td>{{.Name}}</td>
<td>{{.Type}}</td>
<td>{{.Replicas}}</td>
<td>{{.RolloutStrategy}}</td>
<td>{{.PodAntiAffinity}}</td>
<td>{{.PVC}}</td>
<td>{{.Rank}}</td>
</tr>
{{end}}
</tbody>
</table>
<br/>
<div style="white-space: pre-wrap;">%s</div>`
23 changes: 21 additions & 2 deletions pkg/ha/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,22 @@ import (
"k8s.io/client-go/tools/clientcmd"
)

var description = `
Ranks
0: Undefined (detection was not possible)
1: High-available (failure-resilient, zero-downtime-deployment capable)
2: Zero-downtime-deployment capable: (non failure-resilient)
3: Single-point-of-failure
4: Standalone pod
Definitions
Failure resilient: If a single pod or node crashes, the availability of the workload is not affected.
Zero-downtime-deployment: The workload can be updated without downtime
Single-point-of-failure: If a single pod or the node crashes, the availability of the workload is degraded.
Standalone pod: If the pod is removed or crashes, it disappears without replacement.
`

type HighAvailability struct {
KubeOverrides *clientcmd.ConfigOverrides
KubeClient *kubernetes.KubeClient
Expand Down Expand Up @@ -40,7 +56,7 @@ func (p PodAvailabilityList) ToJson() (string, error) {
}

func (p PodAvailabilityList) ToHtml() (string, error) {
return printer.ToHtml(HtmlPage, p)
return printer.ToHtml(fmt.Sprintf(HtmlPage, description), p)
}

func (p PodAvailabilityList) ToTable() (string, error) {
Expand All @@ -51,6 +67,7 @@ func (p PodAvailabilityList) ToTable() (string, error) {
table.SetAlignment(tablewriter.ALIGN_LEFT)

table.SetHeader([]string{
"Namespace",
"Name",
"Type",
"Replicas",
Expand All @@ -62,6 +79,7 @@ func (p PodAvailabilityList) ToTable() (string, error) {

for _, v := range p.Items {
table.Append([]string{
v.Namespace,
v.Name,
v.Type,
fmt.Sprint(v.Replicas),
Expand All @@ -73,5 +91,6 @@ func (p PodAvailabilityList) ToTable() (string, error) {
}

table.Render()
return buf.String(), nil
content := buf.String()
return fmt.Sprintf("%s %s", content, description), nil
}
17 changes: 17 additions & 0 deletions pkg/printer/html_container.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package printer

var HtmlContainer = `<html>
<head>
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<link type="text/css" rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css"
media="screen,projection" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
</head>
<body>
<div class="container">
%s
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js"></script>
</body>
</html>`
3 changes: 2 additions & 1 deletion pkg/printer/printer.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,6 @@ func ToHtml(html string, v interface{}) (string, error) {
}

err = tpl.Execute(buf, v)
return buf.String(), err
content := buf.String()
return fmt.Sprintf(HtmlContainer, content), err
}
52 changes: 26 additions & 26 deletions pkg/resources/html.go
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
package resources

var HtmlPage = `<html>
<body>
<table>
<thead>
<tr>
<td>Pod</td>
<td>Memory Requests</td>
<td>Memory Limits</td>
<td>CPU Requests</td>
<td>CPU Limits</td>
</tr>
</thead>
<tbody>
{{range .Items}}
<tr>
<td>{{.Pod}}</td>
<td>{{.MemoryRequests.Min.FormatMemory}}<br>{{.MemoryRequests.Avg.FormatMemory}}<br>{{.MemoryRequests.Max.FormatMemory}}</td>
<td>{{.MemoryLimits.Min.FormatMemory}}<br>{{.MemoryLimits.Avg.FormatMemory}}<br>{{.MemoryLimits.Max.FormatMemory}}</td>
<td>{{.CPURequests.Min.FormatCPU}}<br>{{.CPURequests.Avg.FormatCPU}}<br>{{.CPURequests.Max.FormatCPU}}</td>
<td>{{.CPULimits.Min.FormatCPU}}<br>{{.CPULimits.Avg.FormatCPU}}<br>{{.CPULimits.Max.FormatCPU}}</td>
</tr>
{{end}}
</tbody>
</table>
</body>
</html>`
var HtmlPage = `
<h2>Resource usage</h2>
<table class="responsive-table highlight">
<thead>
<tr>
<th>Namespace</th>
<th>Pod</th>
<th>Memory Requests</th>
<th>Memory Limits</th>
<th>CPU Requests</th>
<th>CPU Limits</th>
</tr>
</thead>
<tbody>
{{range .Items}}
<tr>
<td>{{.Namespace}}</td>
<td>{{.Pod}}</td>
<td>{{.MemoryRequests.Min.FormatMemory}}<br>{{.MemoryRequests.Avg.FormatMemory}}<br>{{.MemoryRequests.Max.FormatMemory}}</td>
<td>{{.MemoryLimits.Min.FormatMemory}}<br>{{.MemoryLimits.Avg.FormatMemory}}<br>{{.MemoryLimits.Max.FormatMemory}}</td>
<td>{{.CPURequests.Min.FormatCPU}}<br>{{.CPURequests.Avg.FormatCPU}}<br>{{.CPURequests.Max.FormatCPU}}</td>
<td>{{.CPULimits.Min.FormatCPU}}<br>{{.CPULimits.Avg.FormatCPU}}<br>{{.CPULimits.Max.FormatCPU}}</td>
</tr>
{{end}}
</tbody>
</table>`
2 changes: 2 additions & 0 deletions pkg/resources/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ func (p PodValuesList) ToTable() (string, error) {
table.SetAlignment(tablewriter.ALIGN_LEFT)

table.SetHeader([]string{
"Namespace",
"Pod",
"Memory Requests",
"Memory Limits",
Expand All @@ -65,6 +66,7 @@ func (p PodValuesList) ToTable() (string, error) {

for _, v := range p.Items {
table.Append([]string{
v.Namespace,
v.Pod,
v.MemoryRequests.Min.FormatMemory() + "\n" + v.MemoryRequests.Avg.FormatMemory() + "\n" + v.MemoryRequests.Max.FormatMemory(),
v.MemoryLimits.Min.FormatMemory() + "\n" + v.MemoryLimits.Avg.FormatMemory() + "\n" + v.MemoryLimits.Max.FormatMemory(),
Expand Down

0 comments on commit d5c17bb

Please sign in to comment.