mirror of
https://github.com/komodorio/helm-dashboard.git
synced 2026-03-24 11:48:04 +00:00
Repo version info and upgrade (#10)
* Repo block shows * repository update * API progress * Fix problem of stopping after uninstall * Upgrade preview backend * Upgrade preview displays fine * Install flow works * Weird check for updates * Update action * Fix action * Still trying * Fix lint error * Refactor out helm handlers * refactor out kube handlers * save * Change icon collection * Reworked upgrade check
This commit is contained in:
@@ -5,8 +5,6 @@ import (
|
||||
"errors"
|
||||
"github.com/gin-gonic/gin"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
v12 "k8s.io/apimachinery/pkg/apis/testapigroup/v1"
|
||||
"net/http"
|
||||
"os"
|
||||
"path"
|
||||
@@ -44,12 +42,14 @@ func NewRouter(abortWeb ControlChan, data *DataLayer) *gin.Engine {
|
||||
api = gin.Default()
|
||||
}
|
||||
|
||||
api.Use(noCache)
|
||||
api.Use(contextSetter(data))
|
||||
api.Use(errorHandler)
|
||||
configureStatic(api)
|
||||
|
||||
configureStatic(api)
|
||||
configureRoutes(abortWeb, data, api)
|
||||
|
||||
api.Use(noCache)
|
||||
api.Use(errorHandler)
|
||||
|
||||
return api
|
||||
}
|
||||
|
||||
@@ -59,191 +59,29 @@ func configureRoutes(abortWeb ControlChan, data *DataLayer, api *gin.Engine) {
|
||||
abortWeb <- struct{}{}
|
||||
})
|
||||
|
||||
configureHelms(api, data)
|
||||
configureKubectls(api, data)
|
||||
configureHelms(api.Group("/api/helm"), data)
|
||||
configureKubectls(api.Group("/api/kube"), data)
|
||||
}
|
||||
|
||||
func configureHelms(api *gin.Engine, data *DataLayer) {
|
||||
api.GET("/api/helm/charts", func(c *gin.Context) {
|
||||
res, err := data.ListInstalled()
|
||||
if err != nil {
|
||||
_ = c.AbortWithError(http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
c.IndentedJSON(http.StatusOK, res)
|
||||
})
|
||||
|
||||
api.DELETE("/api/helm/charts", func(c *gin.Context) {
|
||||
qp, err := getQueryProps(c, false)
|
||||
if err != nil {
|
||||
_ = c.AbortWithError(http.StatusBadRequest, err)
|
||||
return
|
||||
}
|
||||
err = data.UninstallChart(qp.Namespace, qp.Name)
|
||||
if err != nil {
|
||||
_ = c.AbortWithError(http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
c.Redirect(http.StatusFound, "/")
|
||||
})
|
||||
|
||||
api.POST("/api/helm/charts/rollback", func(c *gin.Context) {
|
||||
qp, err := getQueryProps(c, true)
|
||||
if err != nil {
|
||||
_ = c.AbortWithError(http.StatusBadRequest, err)
|
||||
return
|
||||
}
|
||||
|
||||
err = data.Revert(qp.Namespace, qp.Name, qp.Revision)
|
||||
if err != nil {
|
||||
_ = c.AbortWithError(http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
c.Redirect(http.StatusFound, "/")
|
||||
})
|
||||
|
||||
api.GET("/api/helm/charts/history", func(c *gin.Context) {
|
||||
qp, err := getQueryProps(c, false)
|
||||
if err != nil {
|
||||
_ = c.AbortWithError(http.StatusBadRequest, err)
|
||||
return
|
||||
}
|
||||
|
||||
res, err := data.ChartHistory(qp.Namespace, qp.Name)
|
||||
if err != nil {
|
||||
_ = c.AbortWithError(http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
c.IndentedJSON(http.StatusOK, res)
|
||||
})
|
||||
|
||||
api.GET("/api/helm/charts/resources", func(c *gin.Context) {
|
||||
qp, err := getQueryProps(c, true)
|
||||
if err != nil {
|
||||
_ = c.AbortWithError(http.StatusBadRequest, err)
|
||||
return
|
||||
}
|
||||
|
||||
res, err := data.RevisionManifestsParsed(qp.Namespace, qp.Name, qp.Revision)
|
||||
if err != nil {
|
||||
_ = c.AbortWithError(http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
c.IndentedJSON(http.StatusOK, res)
|
||||
})
|
||||
|
||||
api.GET("/api/helm/charts/:section", func(c *gin.Context) {
|
||||
qp, err := getQueryProps(c, true)
|
||||
if err != nil {
|
||||
_ = c.AbortWithError(http.StatusBadRequest, err)
|
||||
return
|
||||
}
|
||||
|
||||
flag := c.Query("flag") == "true"
|
||||
rDiff := c.Query("revisionDiff")
|
||||
res, err := handleGetSection(data, c.Param("section"), rDiff, qp, flag)
|
||||
if err != nil {
|
||||
_ = c.AbortWithError(http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
c.String(http.StatusOK, res)
|
||||
})
|
||||
func configureHelms(api *gin.RouterGroup, data *DataLayer) {
|
||||
h := HelmHandler{Data: data}
|
||||
api.GET("/charts", h.GetCharts)
|
||||
api.DELETE("/charts", h.Uninstall)
|
||||
api.POST("/charts/rollback", h.Rollback)
|
||||
api.GET("/charts/history", h.History)
|
||||
api.GET("/charts/resources", h.Resources)
|
||||
api.GET("/repo/search", h.RepoSearch)
|
||||
api.POST("/repo/update", h.RepoUpdate)
|
||||
api.GET("/charts/install", h.InstallPreview)
|
||||
api.POST("/charts/install", h.Install)
|
||||
api.GET("/charts/:section", h.GetInfoSection)
|
||||
}
|
||||
|
||||
func handleGetSection(data *DataLayer, section string, rDiff string, qp *QueryProps, flag bool) (string, error) {
|
||||
sections := map[string]SectionFn{
|
||||
"manifests": data.RevisionManifests,
|
||||
"values": data.RevisionValues,
|
||||
"notes": data.RevisionNotes,
|
||||
}
|
||||
|
||||
functor, found := sections[section]
|
||||
if !found {
|
||||
return "", errors.New("unsupported section: " + section)
|
||||
}
|
||||
|
||||
if rDiff != "" {
|
||||
cRevDiff, err := strconv.Atoi(rDiff)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
ext := ".yaml"
|
||||
if section == "notes" {
|
||||
ext = ".txt"
|
||||
}
|
||||
|
||||
res, err := RevisionDiff(functor, ext, qp.Namespace, qp.Name, cRevDiff, qp.Revision, flag)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return res, nil
|
||||
} else {
|
||||
res, err := functor(qp.Namespace, qp.Name, qp.Revision, flag)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return res, nil
|
||||
}
|
||||
}
|
||||
|
||||
func configureKubectls(api *gin.Engine, data *DataLayer) {
|
||||
api.GET("/api/kube/contexts", func(c *gin.Context) {
|
||||
res, err := data.ListContexts()
|
||||
if err != nil {
|
||||
_ = c.AbortWithError(http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
c.IndentedJSON(http.StatusOK, res)
|
||||
})
|
||||
|
||||
api.GET("/api/kube/resources/:kind", func(c *gin.Context) {
|
||||
qp, err := getQueryProps(c, false)
|
||||
if err != nil {
|
||||
_ = c.AbortWithError(http.StatusBadRequest, err)
|
||||
return
|
||||
}
|
||||
|
||||
res, err := data.GetResource(qp.Namespace, &GenericResource{
|
||||
TypeMeta: v1.TypeMeta{Kind: c.Param("kind")},
|
||||
ObjectMeta: v1.ObjectMeta{Name: qp.Name},
|
||||
})
|
||||
if err != nil {
|
||||
_ = c.AbortWithError(http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
|
||||
if res.Status.Phase == "Active" || res.Status.Phase == "Error" {
|
||||
_ = res.Name + ""
|
||||
} else if res.Status.Phase == "" && len(res.Status.Conditions) > 0 {
|
||||
res.Status.Phase = v12.CarpPhase(res.Status.Conditions[len(res.Status.Conditions)-1].Type)
|
||||
res.Status.Message = res.Status.Conditions[len(res.Status.Conditions)-1].Message
|
||||
res.Status.Reason = res.Status.Conditions[len(res.Status.Conditions)-1].Reason
|
||||
if res.Status.Conditions[len(res.Status.Conditions)-1].Status == "False" {
|
||||
res.Status.Phase = "Not" + res.Status.Phase
|
||||
}
|
||||
} else if res.Status.Phase == "" {
|
||||
res.Status.Phase = "Exists"
|
||||
}
|
||||
|
||||
c.IndentedJSON(http.StatusOK, res)
|
||||
})
|
||||
|
||||
api.GET("/api/kube/describe/:kind", func(c *gin.Context) {
|
||||
qp, err := getQueryProps(c, false)
|
||||
if err != nil {
|
||||
_ = c.AbortWithError(http.StatusBadRequest, err)
|
||||
return
|
||||
}
|
||||
|
||||
res, err := data.DescribeResource(qp.Namespace, c.Param("kind"), qp.Name)
|
||||
if err != nil {
|
||||
_ = c.AbortWithError(http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.String(http.StatusOK, res)
|
||||
})
|
||||
func configureKubectls(api *gin.RouterGroup, data *DataLayer) {
|
||||
h := KubeHandler{Data: data}
|
||||
api.GET("/contexts", h.GetContexts)
|
||||
api.GET("/resources/:kind", h.GetResourceInfo)
|
||||
api.GET("/describe/:kind", h.Describe)
|
||||
}
|
||||
|
||||
func configureStatic(api *gin.Engine) {
|
||||
|
||||
Reference in New Issue
Block a user