mirror of
https://github.com/komodorio/helm-dashboard.git
synced 2026-03-24 11:48:04 +00:00
Check for newer version available (#47)
* Add helm version requirement notes * Check for newer version and offer upgrade * fix lint
This commit is contained in:
@@ -2,13 +2,16 @@ package dashboard
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/hashicorp/go-version"
|
||||
"github.com/komodorio/helm-dashboard/pkg/dashboard/scanners"
|
||||
"github.com/komodorio/helm-dashboard/pkg/dashboard/subproc"
|
||||
"github.com/komodorio/helm-dashboard/pkg/dashboard/utils"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"net/http"
|
||||
"os"
|
||||
"time"
|
||||
)
|
||||
|
||||
func StartServer(version string) (string, utils.ControlChan) {
|
||||
@@ -19,6 +22,9 @@ func StartServer(version string) (string, utils.ControlChan) {
|
||||
os.Exit(1) // TODO: propagate error instead?
|
||||
}
|
||||
|
||||
data.VersionInfo = &subproc.VersionInfo{CurVer: version}
|
||||
go checkUpgrade(data.VersionInfo)
|
||||
|
||||
discoverScanners(&data)
|
||||
|
||||
address := os.Getenv("HD_BIND")
|
||||
@@ -33,7 +39,7 @@ func StartServer(version string) (string, utils.ControlChan) {
|
||||
}
|
||||
|
||||
abort := make(utils.ControlChan)
|
||||
api := NewRouter(abort, &data, version)
|
||||
api := NewRouter(abort, &data)
|
||||
done := startBackgroundServer(address, api, abort)
|
||||
|
||||
return "http://" + address, done
|
||||
@@ -75,3 +81,44 @@ func discoverScanners(data *subproc.DataLayer) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func checkUpgrade(d *subproc.VersionInfo) {
|
||||
url := "https://api.github.com/repos/komodorio/helm-dashboard/releases/latest"
|
||||
type GHRelease struct {
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
var myClient = &http.Client{Timeout: 5 * time.Second}
|
||||
r, err := myClient.Get(url)
|
||||
if err != nil {
|
||||
log.Warnf("Failed to check for new version: %s", err)
|
||||
return
|
||||
}
|
||||
defer r.Body.Close()
|
||||
|
||||
target := new(GHRelease)
|
||||
err = json.NewDecoder(r.Body).Decode(target)
|
||||
if err != nil {
|
||||
log.Warnf("Failed to decode new release version: %s", err)
|
||||
return
|
||||
}
|
||||
d.LatestVer = target.Name
|
||||
|
||||
v1, err := version.NewVersion(d.CurVer)
|
||||
if err != nil {
|
||||
log.Warnf("Failed to parse version: %s", err)
|
||||
v1 = &version.Version{}
|
||||
}
|
||||
|
||||
v2, err := version.NewVersion(d.LatestVer)
|
||||
if err != nil {
|
||||
log.Warnf("Failed to parse version: %s", err)
|
||||
} else {
|
||||
if v1.LessThan(v2) {
|
||||
log.Warnf("Newer Helm Dashboard version is available: %s", d.LatestVer)
|
||||
log.Warnf("Upgrade instructions: https://github.com/komodorio/helm-dashboard#installing")
|
||||
} else {
|
||||
log.Debugf("Got latest version from GH: %s", d.LatestVer)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user