From 76d55f8e44b0f0df613674c9717d32cee7eebfde Mon Sep 17 00:00:00 2001 From: Harshit Mehta Date: Wed, 9 Nov 2022 13:53:44 +0530 Subject: [PATCH] Enhancement/show chart icon and description (#70) * New API to fetch chart.yaml for an installec chart * Show icon and description for installed chart list Co-authored-by: Harshit Mehta --- pkg/dashboard/api.go | 1 + pkg/dashboard/handlers/helmHandlers.go | 23 ++++++++++++++++++--- pkg/dashboard/static/list-view.js | 23 ++++++++++++++++++++- pkg/dashboard/static/styles.css | 4 ++++ pkg/dashboard/subproc/data.go | 28 ++++++++++++++++++++++++++ 5 files changed, 75 insertions(+), 4 deletions(-) diff --git a/pkg/dashboard/api.go b/pkg/dashboard/api.go index e2b2624..d16aa71 100644 --- a/pkg/dashboard/api.go +++ b/pkg/dashboard/api.go @@ -90,6 +90,7 @@ func configureHelms(api *gin.RouterGroup, data *subproc.DataLayer) { api.GET("/charts/history", h.History) api.GET("/charts/resources", h.Resources) api.GET("/charts/:section", h.GetInfoSection) + api.GET("/charts/show", h.Show) api.POST("/charts/install", h.Install) api.POST("/charts/rollback", h.Rollback) diff --git a/pkg/dashboard/handlers/helmHandlers.go b/pkg/dashboard/handlers/helmHandlers.go index 44787dd..5f63a00 100644 --- a/pkg/dashboard/handlers/helmHandlers.go +++ b/pkg/dashboard/handlers/helmHandlers.go @@ -2,12 +2,13 @@ package handlers import ( "errors" - "github.com/gin-gonic/gin" - "github.com/komodorio/helm-dashboard/pkg/dashboard/subproc" - "github.com/komodorio/helm-dashboard/pkg/dashboard/utils" "net/http" "strconv" "strings" + + "github.com/gin-gonic/gin" + "github.com/komodorio/helm-dashboard/pkg/dashboard/subproc" + "github.com/komodorio/helm-dashboard/pkg/dashboard/utils" ) type HelmHandler struct { @@ -127,6 +128,22 @@ func (h *HelmHandler) RepoUpdate(c *gin.Context) { c.Status(http.StatusNoContent) } +func (h *HelmHandler) Show(c *gin.Context) { + qp, err := utils.GetQueryProps(c, false) + if err != nil { + _ = c.AbortWithError(http.StatusBadRequest, err) + return + } + + res, err := h.Data.ShowChart(qp.Name) + if err != nil { + _ = c.AbortWithError(http.StatusInternalServerError, err) + return + } + + c.IndentedJSON(http.StatusOK, res) +} + func (h *HelmHandler) Install(c *gin.Context) { qp, err := utils.GetQueryProps(c, false) if err != nil { diff --git a/pkg/dashboard/static/list-view.js b/pkg/dashboard/static/list-view.js index e3d804f..926418d 100644 --- a/pkg/dashboard/static/list-view.js +++ b/pkg/dashboard/static/list-view.js @@ -20,7 +20,7 @@ function loadChartsList() { } function buildChartCard(elm) { - const card = $(`
+ const card = $(`
release-name
Chart Version
@@ -28,6 +28,27 @@ function buildChartCard(elm) {
default
Namespace
today
Updated
`) + + $.getJSON("/api/helm/repo/search?name=" + elm.name).fail(function (xhr) { + reportError("Failed to get repo name for charts", xhr) + }).done(function (data) { + if(data.length > 0) { + $.getJSON("/api/helm/charts/show?name=" + data[0].name).fail(function (xhr) { + reportError("Failed to get list of charts", xhr) + }).done(function (data) { + if(data) { + var res = data[0] + if(res.icon) { + card.find(".rel-name").attr("style", "background-image: url(" + res.icon + ")") + } + if(res.description) { + card.find(".rel-name div").text(res.description) + } + } + + }) + } + }) card.find(".rel-name span").text(elm.name) card.find(".rel-rev span").text("#" + elm.revision) diff --git a/pkg/dashboard/static/styles.css b/pkg/dashboard/static/styles.css index 56f1f25..96596a7 100644 --- a/pkg/dashboard/static/styles.css +++ b/pkg/dashboard/static/styles.css @@ -162,6 +162,10 @@ span.link { background-size: 3rem; } +#installedList .rel-name div { + overflow: hidden; +} + #installedList .rel-name span { font-family: Roboto Slab, sans-serif; font-weight: 700; diff --git a/pkg/dashboard/subproc/data.go b/pkg/dashboard/subproc/data.go index 7001704..7110833 100644 --- a/pkg/dashboard/subproc/data.go +++ b/pkg/dashboard/subproc/data.go @@ -17,6 +17,7 @@ import ( "github.com/komodorio/helm-dashboard/pkg/dashboard/utils" log "github.com/sirupsen/logrus" "gopkg.in/yaml.v3" + "helm.sh/helm/v3/pkg/chart" "helm.sh/helm/v3/pkg/release" v1 "k8s.io/apimachinery/pkg/apis/testapigroup/v1" ) @@ -449,6 +450,33 @@ func (d *DataLayer) ShowValues(chart string, ver string) (string, error) { return d.runCommandHelm("show", "values", chart, "--version", ver) } +func (d *DataLayer) ShowChart(chartName string) ([]*chart.Metadata, error) { + out, err := d.runCommandHelm("show", "chart", chartName) + if err != nil { + return nil, err + } + + deccoder := yaml.NewDecoder(bytes.NewReader([]byte(out))) + res := make([]*chart.Metadata, 0) + var tmp interface{} + + for deccoder.Decode(&tmp) == nil { + jsoned, err := json.Marshal(tmp) + if err != nil { + return nil, err + } + + var resjson chart.Metadata + err = json.Unmarshal(jsoned, &resjson) + if err != nil { + return nil, err + } + res = append(res, &resjson) + } + + return res, nil +} + func (d *DataLayer) ChartRepoList() (res []RepositoryElement, err error) { out, err := d.runCommandHelm("repo", "list", "--output", "json") if err != nil {