mirror of
https://github.com/komodorio/helm-dashboard.git
synced 2026-03-24 11:48:04 +00:00
Add namespace dropdown (#67)
* add get namespace endpoint * add namespace dropdown * misc fix
This commit is contained in:
@@ -2,14 +2,15 @@ package dashboard
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"embed"
|
"embed"
|
||||||
|
"net/http"
|
||||||
|
"os"
|
||||||
|
"path"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/komodorio/helm-dashboard/pkg/dashboard/handlers"
|
"github.com/komodorio/helm-dashboard/pkg/dashboard/handlers"
|
||||||
"github.com/komodorio/helm-dashboard/pkg/dashboard/subproc"
|
"github.com/komodorio/helm-dashboard/pkg/dashboard/subproc"
|
||||||
"github.com/komodorio/helm-dashboard/pkg/dashboard/utils"
|
"github.com/komodorio/helm-dashboard/pkg/dashboard/utils"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
"net/http"
|
|
||||||
"os"
|
|
||||||
"path"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
//go:embed static/*
|
//go:embed static/*
|
||||||
@@ -106,6 +107,7 @@ func configureKubectls(api *gin.RouterGroup, data *subproc.DataLayer) {
|
|||||||
api.GET("/contexts", h.GetContexts)
|
api.GET("/contexts", h.GetContexts)
|
||||||
api.GET("/resources/:kind", h.GetResourceInfo)
|
api.GET("/resources/:kind", h.GetResourceInfo)
|
||||||
api.GET("/describe/:kind", h.Describe)
|
api.GET("/describe/:kind", h.Describe)
|
||||||
|
api.GET("/namespaces", h.GetNameSpaces)
|
||||||
}
|
}
|
||||||
|
|
||||||
func configureStatic(api *gin.Engine) {
|
func configureStatic(api *gin.Engine) {
|
||||||
|
|||||||
@@ -1,12 +1,13 @@
|
|||||||
package handlers
|
package handlers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"net/http"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/komodorio/helm-dashboard/pkg/dashboard/subproc"
|
"github.com/komodorio/helm-dashboard/pkg/dashboard/subproc"
|
||||||
"github.com/komodorio/helm-dashboard/pkg/dashboard/utils"
|
"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"
|
v12 "k8s.io/apimachinery/pkg/apis/testapigroup/v1"
|
||||||
"net/http"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type KubeHandler struct {
|
type KubeHandler struct {
|
||||||
@@ -69,3 +70,13 @@ func (h *KubeHandler) Describe(c *gin.Context) {
|
|||||||
|
|
||||||
c.String(http.StatusOK, res)
|
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)
|
||||||
|
}
|
||||||
|
|||||||
@@ -71,6 +71,18 @@ function popUpUpgrade(elm, ns, name, verCur, lastRev) {
|
|||||||
$("#upgradeModal .rel-ns").prop("disabled", false).val("")
|
$("#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($("<option>", {
|
||||||
|
value: item,
|
||||||
|
text: item
|
||||||
|
}))
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
$.getJSON("/api/helm/repo/search?name=" + elm.name).fail(function (xhr) {
|
$.getJSON("/api/helm/repo/search?name=" + elm.name).fail(function (xhr) {
|
||||||
reportError("Failed to find chart in repo", xhr)
|
reportError("Failed to find chart in repo", xhr)
|
||||||
}).done(function (vers) {
|
}).done(function (vers) {
|
||||||
|
|||||||
@@ -355,7 +355,9 @@
|
|||||||
Release Name: <input class="form-control rel-name">
|
Release Name: <input class="form-control rel-name">
|
||||||
</label>
|
</label>
|
||||||
<label class="form-label me-4 text-dark">
|
<label class="form-label me-4 text-dark">
|
||||||
Namespace (optional): <input class="form-control rel-ns">
|
Namespace (optional):
|
||||||
|
<input type="text" class="form-control rel-ns" list="ns-datalist"/>
|
||||||
|
<datalist id="ns-datalist"></datalist>
|
||||||
</label>
|
</label>
|
||||||
<label class="form-label me-4 text-dark">
|
<label class="form-label me-4 text-dark">
|
||||||
Cluster: <span class="form-label rel-cluster"></span>
|
Cluster: <span class="form-label rel-cluster"></span>
|
||||||
|
|||||||
@@ -5,6 +5,12 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"regexp"
|
||||||
|
"sort"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/hexops/gotextdiff"
|
"github.com/hexops/gotextdiff"
|
||||||
"github.com/hexops/gotextdiff/myers"
|
"github.com/hexops/gotextdiff/myers"
|
||||||
"github.com/hexops/gotextdiff/span"
|
"github.com/hexops/gotextdiff/span"
|
||||||
@@ -13,11 +19,6 @@ import (
|
|||||||
"gopkg.in/yaml.v3"
|
"gopkg.in/yaml.v3"
|
||||||
"helm.sh/helm/v3/pkg/release"
|
"helm.sh/helm/v3/pkg/release"
|
||||||
v1 "k8s.io/apimachinery/pkg/apis/testapigroup/v1"
|
v1 "k8s.io/apimachinery/pkg/apis/testapigroup/v1"
|
||||||
"regexp"
|
|
||||||
"sort"
|
|
||||||
"strconv"
|
|
||||||
"strings"
|
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type DataLayer struct {
|
type DataLayer struct {
|
||||||
@@ -478,6 +479,20 @@ func (d *DataLayer) ChartRepoDelete(name string) (string, error) {
|
|||||||
return out, nil
|
return out, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (d *DataLayer) GetNameSpaces() (res *NamespaceElement, err error) {
|
||||||
|
out, err := d.runCommandKubectl("get", "namespaces", "-o", "json")
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = json.Unmarshal([]byte(out), &res)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return res, nil
|
||||||
|
}
|
||||||
|
|
||||||
func RevisionDiff(functor SectionFn, ext string, namespace string, name string, revision1 int, revision2 int, flag bool) (string, error) {
|
func RevisionDiff(functor SectionFn, ext string, namespace string, name string, revision1 int, revision2 int, flag bool) (string, error) {
|
||||||
if revision1 == 0 || revision2 == 0 {
|
if revision1 == 0 || revision2 == 0 {
|
||||||
log.Debugf("One of revisions is zero: %d %d", revision1, revision2)
|
log.Debugf("One of revisions is zero: %d %d", revision1, revision2)
|
||||||
|
|||||||
@@ -42,3 +42,11 @@ type RepositoryElement struct {
|
|||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
URL string `json:"url"`
|
URL string `json:"url"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type NamespaceElement struct {
|
||||||
|
Items []struct {
|
||||||
|
Metadata struct {
|
||||||
|
Name string `json:"name"`
|
||||||
|
} `json:"metadata"`
|
||||||
|
} `json:"items"`
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user