-
Notifications
You must be signed in to change notification settings - Fork 215
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rendering initial dashboard UI with go template and sample data
- Loading branch information
Showing
7 changed files
with
267 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
resources: | ||
requests: | ||
cpu: | ||
min: 100m | ||
max: 1 | ||
memory: | ||
min: 100M | ||
max: 3G | ||
limits: | ||
cpu: | ||
min: 150m | ||
max: 2 | ||
memory: | ||
min: 150M | ||
max: 4G |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package dashboard | ||
|
||
import ( | ||
"encoding/json" | ||
"html/template" | ||
"log" | ||
"net/http" | ||
|
||
conf "github.com/reactiveops/fairwinds/pkg/config" | ||
"github.com/reactiveops/fairwinds/pkg/kube" | ||
"github.com/reactiveops/fairwinds/pkg/validator" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
type DashboardData struct { | ||
ClusterSummary *validator.ResultSummary | ||
NamespacedResults []validator.NamespacedResult | ||
} | ||
|
||
var tmpl = template.Must(template.ParseFiles("pkg/dashboard/templates/dashboard.gohtml")) | ||
|
||
func Render(w http.ResponseWriter, r *http.Request, c conf.Configuration) { | ||
dashboardData := getDashboardData() | ||
tmpl.Execute(w, dashboardData) | ||
} | ||
|
||
func RenderJSON(w http.ResponseWriter, r *http.Request, c conf.Configuration) { | ||
results := []validator.Results{} | ||
pods, err := kube.CoreV1API.Pods("").List(metav1.ListOptions{}) | ||
if err != nil { | ||
http.Error(w, "Error Fetching Pods", 500) | ||
return | ||
} | ||
log.Println("pods count:", len(pods.Items)) | ||
for _, pod := range pods.Items { | ||
result := validator.ValidatePods(c, &pod, validator.Results{}) | ||
results = append(results, result) | ||
} | ||
w.WriteHeader(http.StatusOK) | ||
w.Header().Set("Content-Type", "application/json") | ||
json.NewEncoder(w).Encode(results) | ||
} | ||
|
||
func getDashboardData() DashboardData { | ||
return DashboardData{ | ||
ClusterSummary: &validator.ResultSummary{ | ||
Successes: 46, | ||
Warnings: 8, | ||
Failures: 5, | ||
}, | ||
NamespacedResults: []validator.NamespacedResult{{ | ||
Namespace: "kube-system", | ||
Results: []validator.ResourceResult{{ | ||
Name: "tiller", | ||
Type: "Deployment", | ||
Summary: &validator.ResultSummary{ | ||
Successes: 7, | ||
Warnings: 3, | ||
Failures: 2, | ||
}, | ||
Messages: []validator.ResultMessage{{ | ||
Message: "Image Tag Specified", | ||
Type: "success", | ||
}, { | ||
Message: "Liveness Probe Specified", | ||
Type: "success", | ||
}, { | ||
Message: "Readiness Probe Specified", | ||
Type: "success", | ||
}, { | ||
Message: "Container Running As Root", | ||
Type: "warning", | ||
}, { | ||
Message: "Resource requests are not set", | ||
Type: "failure", | ||
}}, | ||
}}, | ||
}}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
<!doctype html> | ||
<html> | ||
|
||
<head> | ||
<meta charset="utf-8"> | ||
<meta http-equiv="x-ua-compatible" content="ie=edge"> | ||
<title>Fairwinds</title> | ||
<meta name="description" content=""> | ||
<meta name="viewport" content="width=device-width, initial-scale=1"> | ||
|
||
<link href="https://fonts.googleapis.com/css?family=Lobster" rel="stylesheet"> | ||
<link rel="stylesheet" href="/static/css/normalize.css"> | ||
<link rel="stylesheet" href="/static/css/main.css"> | ||
</head> | ||
|
||
<body> | ||
<div class="header"> | ||
<h1>Fairwinds</h1> | ||
</div> | ||
|
||
<div class="cluster-score"> | ||
<p>Overall Score:</p> | ||
<h2>{{ .ClusterSummary.Score }}%</h2> | ||
<div class="status"> | ||
<div class="failing"> | ||
<div class="warning" style="width: {{ .ClusterSummary.WarningWidth 400 }}px;"> | ||
<div class="passing" style="width: {{ .ClusterSummary.SuccessWidth 400 }}px;"></div> | ||
</div> | ||
</div> | ||
</div> | ||
<div class="summary"> | ||
<div class="item"> | ||
<span class="label">Successes:</span> | ||
<strong class="value">{{ .ClusterSummary.Successes }}</strong> | ||
</div> | ||
<div class="item"> | ||
<span class="label">Warnings:</span> | ||
<strong class="value">{{ .ClusterSummary.Warnings }}</strong> | ||
</div> | ||
<div class="item"> | ||
<span class="label">Failures:</span> | ||
<strong class="value">{{ .ClusterSummary.Failures }}</strong> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
{{ range .NamespacedResults }} | ||
<div class="namespace-header"> | ||
<h3>Namespace: <strong>{{ .Namespace }}</strong></h3> | ||
</div> | ||
|
||
<table class="namespace-content"> | ||
{{ range .Results }} | ||
<tr> | ||
<td> | ||
<div class="name"><span class="caret-expander expanded"></span>{{ .Type }}: <strong>{{ .Name }}</strong></div> | ||
<ul class="extra"> | ||
{{ range .Messages}} | ||
<li class="{{ .Type }}"><span>&#{{ .HTMLSpecialCharCode }};</span> {{ .Message }}</li> | ||
{{ end }} | ||
</ul> | ||
</td> | ||
<td class="status-bar"> | ||
<div class="status"> | ||
<div class="failing"> | ||
<div class="warning" style="width: {{ .Summary.WarningWidth 200 }}px;"> | ||
<div class="passing" style="width: {{ .Summary.SuccessWidth 200 }}px;"></div> | ||
</div> | ||
</div> | ||
</div> | ||
</td> | ||
</tr> | ||
{{ end }} | ||
</table> | ||
{{ end }} | ||
</body> | ||
|
||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package validator | ||
|
||
// namespaceResults: [{ | ||
// name: "kube-system", | ||
// resourceResults: [{ | ||
// name: "example-deployment", | ||
// type: "DaemonSet", | ||
// summary: { | ||
// successes: 28, | ||
// warnings: 12, | ||
// failures: 18, | ||
// }, | ||
// messages: [{ | ||
// message: "Resource requests are not set", | ||
// type: "failure", | ||
// }] | ||
// }] | ||
// }] | ||
|
||
type NamespacedResult struct { | ||
Namespace string | ||
Results []ResourceResult | ||
} | ||
|
||
type ResourceResult struct { | ||
Name string | ||
Type string | ||
Summary *ResultSummary | ||
Messages []ResultMessage | ||
} | ||
|
||
type ResultSummary struct { | ||
Successes uint | ||
Warnings uint | ||
Failures uint | ||
} | ||
|
||
type ResultMessage struct { | ||
Message string | ||
Type string | ||
} | ||
|
||
func (rs *ResultSummary) Score() uint { | ||
return uint(float64(rs.Successes) / float64(rs.Successes+rs.Warnings+rs.Failures) * 100) | ||
} | ||
|
||
func (rs *ResultSummary) WarningWidth(fullWidth uint) uint { | ||
return uint(float64(rs.Successes+rs.Warnings) / float64(rs.Successes+rs.Warnings+rs.Failures) * float64(fullWidth)) | ||
} | ||
|
||
func (rs *ResultSummary) SuccessWidth(fullWidth uint) uint { | ||
return uint(float64(rs.Successes) / float64(rs.Successes+rs.Warnings+rs.Failures) * float64(fullWidth)) | ||
} | ||
|
||
func (rm *ResultMessage) HTMLSpecialCharCode() string { | ||
switch rm.Type { | ||
case "success": | ||
return "9745" | ||
case "warning": | ||
return "9888" | ||
default: | ||
return "9746" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters