diff --git a/pkg/dashboard/api.go b/pkg/dashboard/api.go index 90e8784..ac93b4e 100644 --- a/pkg/dashboard/api.go +++ b/pkg/dashboard/api.go @@ -2,14 +2,15 @@ package dashboard import ( "embed" + "net/http" + "os" + "path" + "github.com/gin-gonic/gin" "github.com/komodorio/helm-dashboard/pkg/dashboard/handlers" "github.com/komodorio/helm-dashboard/pkg/dashboard/subproc" "github.com/komodorio/helm-dashboard/pkg/dashboard/utils" log "github.com/sirupsen/logrus" - "net/http" - "os" - "path" ) //go:embed static/* @@ -106,6 +107,7 @@ func configureKubectls(api *gin.RouterGroup, data *subproc.DataLayer) { api.GET("/contexts", h.GetContexts) api.GET("/resources/:kind", h.GetResourceInfo) api.GET("/describe/:kind", h.Describe) + api.GET("/namespaces", h.GetNameSpaces) } func configureStatic(api *gin.Engine) { diff --git a/pkg/dashboard/handlers/kubeHandlers.go b/pkg/dashboard/handlers/kubeHandlers.go index fb0c313..377bc0e 100644 --- a/pkg/dashboard/handlers/kubeHandlers.go +++ b/pkg/dashboard/handlers/kubeHandlers.go @@ -1,12 +1,13 @@ package handlers import ( + "net/http" + "github.com/gin-gonic/gin" "github.com/komodorio/helm-dashboard/pkg/dashboard/subproc" "github.com/komodorio/helm-dashboard/pkg/dashboard/utils" - "k8s.io/apimachinery/pkg/apis/meta/v1" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" v12 "k8s.io/apimachinery/pkg/apis/testapigroup/v1" - "net/http" ) type KubeHandler struct { @@ -69,3 +70,13 @@ func (h *KubeHandler) Describe(c *gin.Context) { c.String(http.StatusOK, res) } + +func (h *KubeHandler) GetNameSpaces(c *gin.Context) { + res, err := h.Data.GetNameSpaces() + if err != nil { + _ = c.AbortWithError(http.StatusInternalServerError, err) + return + } + + c.JSON(http.StatusOK, res) +} diff --git a/pkg/dashboard/static/actions.js b/pkg/dashboard/static/actions.js index e8980e0..f6ba7aa 100644 --- a/pkg/dashboard/static/actions.js +++ b/pkg/dashboard/static/actions.js @@ -71,6 +71,18 @@ function popUpUpgrade(elm, ns, name, verCur, lastRev) { $("#upgradeModal .rel-ns").prop("disabled", false).val("") } + $.getJSON("/api/kube/namespaces").fail(function (xhr) { + reportError("Failed to get namespaces", xhr) + }).done(function(res) { + const ns = res.items.map(i => i.metadata.name) + $.each(ns, function(i, item) { + $("#upgradeModal #ns-datalist").append($("