diff --git a/pkg/dashboard/dashboard.go b/pkg/dashboard/dashboard.go index f55bd49c..f98c2df0 100644 --- a/pkg/dashboard/dashboard.go +++ b/pkg/dashboard/dashboard.go @@ -55,7 +55,7 @@ func Dashboard(opts Options) http.Handler { return } - tmpl, err := getTemplate("dashboard", + tmpl, err := getTemplate("dashboard", opts, "container", "dashboard", "filter", @@ -72,10 +72,8 @@ func Dashboard(opts Options) http.Handler { data := struct { VpaData summary.Summary - Opts Options }{ VpaData: vpaData, - Opts: opts, } writeTemplate(tmpl, opts, &data, w) diff --git a/pkg/dashboard/namespace-list.go b/pkg/dashboard/namespace-list.go index 7f73353e..c92ad8dd 100644 --- a/pkg/dashboard/namespace-list.go +++ b/pkg/dashboard/namespace-list.go @@ -34,7 +34,7 @@ func NamespaceList(opts Options) http.Handler { return } - tmpl, err := getTemplate("namespace_list", + tmpl, err := getTemplate("namespace_list", opts, "filter", "namespace_list", ) @@ -53,10 +53,7 @@ func NamespaceList(opts Options) http.Handler { Namespaces []struct { Name string } - Opts Options - }{ - Opts: opts, - } + }{} for _, ns := range namespacesList.Items { item := struct { diff --git a/pkg/dashboard/templates.go b/pkg/dashboard/templates.go index f83cb425..2e3564f0 100644 --- a/pkg/dashboard/templates.go +++ b/pkg/dashboard/templates.go @@ -59,7 +59,7 @@ func getTemplateBox() *packr.Box { } // getTemplate puts together a template. Individual pieces can be overridden before rendering. -func getTemplate(name string, includedTemplates ...string) (*template.Template, error) { +func getTemplate(name string, opts Options, includedTemplates ...string) (*template.Template, error) { tmpl := template.New(name).Funcs(template.FuncMap{ "printResource": helpers.PrintResource, "getStatus": helpers.GetStatus, @@ -67,6 +67,10 @@ func getTemplate(name string, includedTemplates ...string) (*template.Template, "resourceName": helpers.ResourceName, "getUUID": helpers.GetUUID, "hasField": helpers.HasField, + + "opts": func() Options { + return opts + }, }) // join the default templates and included templates diff --git a/pkg/dashboard/templates/container.gohtml b/pkg/dashboard/templates/container.gohtml index 687c4db4..c63bbe80 100644 --- a/pkg/dashboard/templates/container.gohtml +++ b/pkg/dashboard/templates/container.gohtml @@ -22,11 +22,13 @@
Guaranteed QoS
- {{if lt $.GuaranteedCostInt 0}} -

-${{$.GuaranteedCost}}/hour

- {{else}} -

+${{$.GuaranteedCost}}/hour

- {{end}} + {{ if opts.EnableCost }} + {{ if lt $.GuaranteedCostInt 0 }} +

-${{ $.GuaranteedCost }}/hour

+ {{ else }} +

+${{ $.GuaranteedCost }}/hour

+ {{ end }} + {{ end }}
@@ -114,11 +116,13 @@
Burstable QoS
- {{if lt $.BurstableCostInt 0}} -

-${{$.BurstableCost}}/hour

- {{else}} -

+${{$.BurstableCost}}/hour

- {{end}} + {{ if opts.EnableCost }} + {{ if lt $.BurstableCostInt 0 }} +

-${{ $.BurstableCost }}/hour

+ {{ else }} +

+${{ $.BurstableCost }}/hour

+ {{ end }} + {{ end }}
diff --git a/pkg/dashboard/templates/dashboard.gohtml b/pkg/dashboard/templates/dashboard.gohtml index 2e94c8ce..9357c8ad 100644 --- a/pkg/dashboard/templates/dashboard.gohtml +++ b/pkg/dashboard/templates/dashboard.gohtml @@ -3,10 +3,11 @@ {{ template "head" .Data }} - {{ if gt (len .Data.VpaData.Namespaces) 1 }} + {{ if gt (len .Data.VpaData.Namespaces) 1 }} - + {{ end }} + {{- if opts.EnableCost }}