Resource status display (#6)

* Start experiments

* Going to get resources

* Start to show resources

* Working on statuses

* Displaying statuses

* Fix complexity?
This commit is contained in:
Andrey Pokhilko
2022-09-07 22:37:50 +01:00
committed by GitHub
parent 967d499742
commit a3fb04fbae
8 changed files with 1215 additions and 68 deletions

View File

@@ -5,6 +5,8 @@ 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"
@@ -66,15 +68,6 @@ func configureRoutes(abortWeb ControlChan, data *DataLayer, api *gin.Engine) {
c.IndentedJSON(http.StatusOK, res)
})
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/helm/charts/history", func(c *gin.Context) {
cName := c.Query("chart")
cNamespace := c.Query("namespace")
@@ -91,6 +84,29 @@ func configureRoutes(abortWeb ControlChan, data *DataLayer, api *gin.Engine) {
c.IndentedJSON(http.StatusOK, res)
})
api.GET("/api/helm/charts/resources", func(c *gin.Context) {
cName := c.Query("chart")
cNamespace := c.Query("namespace")
if cName == "" {
_ = c.AbortWithError(http.StatusBadRequest, errors.New("missing required query string parameter: chart"))
return
}
cRev, err := strconv.Atoi(c.Query("revision"))
if err != nil {
_ = c.AbortWithError(http.StatusInternalServerError, err)
return
}
res, err := data.RevisionManifestsParsed(cNamespace, cName, cRev)
if err != nil {
_ = c.AbortWithError(http.StatusInternalServerError, err)
return
}
c.IndentedJSON(http.StatusOK, res)
})
configureKubectls(api, data)
sections := map[string]SectionFn{
"manifests": data.RevisionManifests,
"values": data.RevisionValues,
@@ -147,6 +163,50 @@ func configureRoutes(abortWeb ControlChan, data *DataLayer, api *gin.Engine) {
})
}
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) {
cName := c.Query("name")
cNamespace := c.Query("namespace")
if cName == "" {
_ = c.AbortWithError(http.StatusBadRequest, errors.New("missing required query string parameter: name"))
return
}
res, err := data.GetResource(cNamespace, &GenericResource{
TypeMeta: v1.TypeMeta{Kind: c.Param("kind")},
ObjectMeta: v1.ObjectMeta{Name: cName},
})
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)
})
}
func configureStatic(api *gin.Engine) {
fs := http.FS(staticFS)