From 61b67f8bed80bf35e6bf7cfa7b222fc9d9357149 Mon Sep 17 00:00:00 2001 From: Andrey Pokhilko Date: Fri, 10 Feb 2023 12:36:40 +0000 Subject: [PATCH] Display UI indication if chart is upgradable (#211) --- pkg/dashboard/handlers/helmHandlers.go | 44 ++++++++++++++------------ pkg/dashboard/static/list-view.js | 14 ++++++++ 2 files changed, 38 insertions(+), 20 deletions(-) diff --git a/pkg/dashboard/handlers/helmHandlers.go b/pkg/dashboard/handlers/helmHandlers.go index 54325a3..2e489a3 100644 --- a/pkg/dashboard/handlers/helmHandlers.go +++ b/pkg/dashboard/handlers/helmHandlers.go @@ -527,35 +527,39 @@ type RepoChartElement struct { AppVersion string `json:"app_version"` Description string `json:"description"` - InstalledNamespace string `json:"installed_namespace"` // custom addition on top of Helm - InstalledName string `json:"installed_name"` // custom addition on top of Helm + InstalledNamespace string `json:"installed_namespace"` + InstalledName string `json:"installed_name"` Repository string `json:"repository"` } func HReleaseToJSON(o *release.Release) *ReleaseElement { return &ReleaseElement{ - Name: o.Name, - Namespace: o.Namespace, - Revision: strconv.Itoa(o.Version), - Updated: o.Info.LastDeployed, - Status: o.Info.Status, - Chart: fmt.Sprintf("%s-%s", o.Chart.Name(), o.Chart.Metadata.Version), - AppVersion: o.Chart.AppVersion(), - Icon: o.Chart.Metadata.Icon, - Description: o.Chart.Metadata.Description, + Name: o.Name, + Namespace: o.Namespace, + Revision: strconv.Itoa(o.Version), + Updated: o.Info.LastDeployed, + Status: o.Info.Status, + Chart: fmt.Sprintf("%s-%s", o.Chart.Name(), o.Chart.Metadata.Version), + ChartName: o.Chart.Name(), + ChartVersion: o.Chart.Metadata.Version, + AppVersion: o.Chart.AppVersion(), + Icon: o.Chart.Metadata.Icon, + Description: o.Chart.Metadata.Description, } } type ReleaseElement struct { - Name string `json:"name"` - Namespace string `json:"namespace"` - Revision string `json:"revision"` - Updated helmtime.Time `json:"updated"` - Status release.Status `json:"status"` - Chart string `json:"chart"` - AppVersion string `json:"app_version"` - Icon string `json:"icon"` - Description string `json:"description"` + Name string `json:"name"` + Namespace string `json:"namespace"` + Revision string `json:"revision"` + Updated helmtime.Time `json:"updated"` + Status release.Status `json:"status"` + Chart string `json:"chart"` + ChartName string `json:"chartName"` + ChartVersion string `json:"chartVersion"` + AppVersion string `json:"app_version"` + Icon string `json:"icon"` + Description string `json:"description"` } type RepositoryElement struct { diff --git a/pkg/dashboard/static/list-view.js b/pkg/dashboard/static/list-view.js index cb1b732..eb171aa 100644 --- a/pkg/dashboard/static/list-view.js +++ b/pkg/dashboard/static/list-view.js @@ -79,6 +79,20 @@ function buildChartCard(elm) { loadChartHistory(chart.namespace, chart.name, elm.chart_name) }) + + // check if upgrade is possible + $.getJSON("/api/helm/repositories/latestver?name=" + elm.chartName).fail(function (xhr) { + reportError("Failed to find chart in repo", xhr) + }).done(function (data) { + if (!data || !data.length) { + return + } + + if (isNewerVersion(elm.chartVersion, data[0].version)) { + card.find(".rel-name span").append("") + } + }) + return card; }