mirror of
https://github.com/komodorio/helm-dashboard.git
synced 2026-03-24 11:48:04 +00:00
Attempt to reuse the application if it's already running
This commit is contained in:
@@ -71,6 +71,7 @@ func configureRoutes(abortWeb utils.ControlChan, data *subproc.DataLayer, api *g
|
|||||||
})
|
})
|
||||||
|
|
||||||
api.GET("/status", func(c *gin.Context) {
|
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)
|
c.IndentedJSON(http.StatusOK, data.VersionInfo)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -51,7 +52,12 @@ func startBackgroundServer(addr string, routes *gin.Engine, abort utils.ControlC
|
|||||||
go func() {
|
go func() {
|
||||||
err := server.ListenAndServe()
|
err := server.ListenAndServe()
|
||||||
if err != nil && err != http.ErrServerClosed {
|
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{}{}
|
done <- struct{}{}
|
||||||
}()
|
}()
|
||||||
@@ -67,6 +73,18 @@ func startBackgroundServer(addr string, routes *gin.Engine, abort utils.ControlC
|
|||||||
return done
|
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) {
|
func discoverScanners(data *subproc.DataLayer) {
|
||||||
potential := []subproc.Scanner{
|
potential := []subproc.Scanner{
|
||||||
&scanners.Checkov{Data: data},
|
&scanners.Checkov{Data: data},
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ function checkUpgradeable(name) {
|
|||||||
$("#btnUpgrade .icon").removeClass("bi-hourglass-split").addClass("bi-x-octagon")
|
$("#btnUpgrade .icon").removeClass("bi-hourglass-split").addClass("bi-x-octagon")
|
||||||
$("#btnUpgrade").prop("disabled", true)
|
$("#btnUpgrade").prop("disabled", true)
|
||||||
$("#btnUpgradeCheck").prop("disabled", true)
|
$("#btnUpgradeCheck").prop("disabled", true)
|
||||||
$("#btnAddRepository").text("Add missing repository")
|
$("#btnAddRepository").text("Add repository for it")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -332,3 +332,7 @@ $("#btnRollback").click(function () {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
$("#btnAddRepository").click(function () {
|
||||||
|
setHashParam("section", "repository")
|
||||||
|
window.location.reload()
|
||||||
|
})
|
||||||
@@ -198,10 +198,10 @@
|
|||||||
<span class="spinner-border spinner-border-sm" style="display: none" role="status"
|
<span class="spinner-border spinner-border-sm" style="display: none" role="status"
|
||||||
aria-hidden="true"></span>
|
aria-hidden="true"></span>
|
||||||
</a>
|
</a>
|
||||||
<div class="small" id="btnAddRepository">
|
<a class="link small" id="btnAddRepository">
|
||||||
<span class="spinner-border spinner-border-sm" style="display: none" role="status"
|
<span class="spinner-border spinner-border-sm" style="display: none" role="status"
|
||||||
aria-hidden="true"></span>
|
aria-hidden="true"></span>
|
||||||
</div>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
<div class="fs-2"> </div>
|
<div class="fs-2"> </div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ $(function () {
|
|||||||
$.getJSON("/api/scanners").fail(function (xhr) {
|
$.getJSON("/api/scanners").fail(function (xhr) {
|
||||||
reportError("Failed to get list of scanners", xhr)
|
reportError("Failed to get list of scanners", xhr)
|
||||||
}).done(function (data) {
|
}).done(function (data) {
|
||||||
if (!data.length) {
|
if (!data || !data.length) {
|
||||||
$("#upgradeModal .btn-scan").hide()
|
$("#upgradeModal .btn-scan").hide()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user