diff --git a/pkg/dashboard/api.go b/pkg/dashboard/api.go index 3fbd836..90e8784 100644 --- a/pkg/dashboard/api.go +++ b/pkg/dashboard/api.go @@ -71,6 +71,7 @@ func configureRoutes(abortWeb utils.ControlChan, data *subproc.DataLayer, api *g }) api.GET("/status", func(c *gin.Context) { + c.Header("X-Application-Name", "Helm Dashboard by Komodor.io") // to identify ourselves by ourselves c.IndentedJSON(http.StatusOK, data.VersionInfo) }) diff --git a/pkg/dashboard/server.go b/pkg/dashboard/server.go index 0fb64e6..a767476 100644 --- a/pkg/dashboard/server.go +++ b/pkg/dashboard/server.go @@ -12,6 +12,7 @@ import ( "net/http" "os" "strconv" + "strings" "time" ) @@ -51,7 +52,12 @@ func startBackgroundServer(addr string, routes *gin.Engine, abort utils.ControlC go func() { err := server.ListenAndServe() if err != nil && err != http.ErrServerClosed { - panic(err) // TODO: in case of "port busy", check that it's another instance of us and just open browser + log.Warnf("Looks like port is busy for %s, checking if it's us...", addr) + if itIsUs(addr) { + log.Infof("Yes, it's another instance of us. Just reuse it.") + } else { + panic(err) + } } done <- struct{}{} }() @@ -67,6 +73,18 @@ func startBackgroundServer(addr string, routes *gin.Engine, abort utils.ControlC return done } +func itIsUs(addr string) bool { + var myClient = &http.Client{Timeout: 5 * time.Second} + r, err := myClient.Get("http://" + addr + "/status") + if err != nil { + log.Debugf("It's not us on %s: %s", addr, err) + return false + } + defer r.Body.Close() + + return strings.HasPrefix(r.Header.Get("X-Application-Name"), "Helm Dashboard") +} + func discoverScanners(data *subproc.DataLayer) { potential := []subproc.Scanner{ &scanners.Checkov{Data: data}, diff --git a/pkg/dashboard/static/actions.js b/pkg/dashboard/static/actions.js index 1aa1508..d41561b 100644 --- a/pkg/dashboard/static/actions.js +++ b/pkg/dashboard/static/actions.js @@ -26,7 +26,7 @@ function checkUpgradeable(name) { $("#btnUpgrade .icon").removeClass("bi-hourglass-split").addClass("bi-x-octagon") $("#btnUpgrade").prop("disabled", true) $("#btnUpgradeCheck").prop("disabled", true) - $("#btnAddRepository").text("Add missing repository") + $("#btnAddRepository").text("Add repository for it") return } @@ -332,3 +332,7 @@ $("#btnRollback").click(function () { }) }) +$("#btnAddRepository").click(function () { + setHashParam("section", "repository") + window.location.reload() +}) \ No newline at end of file diff --git a/pkg/dashboard/static/index.html b/pkg/dashboard/static/index.html index 9d3ca10..655fb93 100644 --- a/pkg/dashboard/static/index.html +++ b/pkg/dashboard/static/index.html @@ -198,10 +198,10 @@ -