diff --git a/pkg/dashboard/api.go b/pkg/dashboard/api.go index 06b2c21..638ee30 100644 --- a/pkg/dashboard/api.go +++ b/pkg/dashboard/api.go @@ -59,6 +59,11 @@ func configureRoutes(abortWeb ControlChan, data *DataLayer, api *gin.Engine) { abortWeb <- struct{}{} }) + configureHelms(api, data) + configureKubectls(api, data) +} + +func configureHelms(api *gin.Engine, data *DataLayer) { api.GET("/api/helm/charts", func(c *gin.Context) { res, err := data.ListInstalled() if err != nil { @@ -68,6 +73,21 @@ func configureRoutes(abortWeb ControlChan, data *DataLayer, api *gin.Engine) { c.IndentedJSON(http.StatusOK, res) }) + api.DELETE("/api/helm/charts", 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 + } + err := data.UninstallChart(cNamespace, cName) + if err != nil { + _ = c.AbortWithError(http.StatusInternalServerError, err) + return + } + c.Redirect(http.StatusFound, "/") + }) + api.GET("/api/helm/charts/history", func(c *gin.Context) { cName := c.Query("chart") cNamespace := c.Query("namespace") @@ -105,8 +125,6 @@ func configureRoutes(abortWeb ControlChan, data *DataLayer, api *gin.Engine) { c.IndentedJSON(http.StatusOK, res) }) - configureKubectls(api, data) - sections := map[string]SectionFn{ "manifests": data.RevisionManifests, "values": data.RevisionValues, diff --git a/pkg/dashboard/data.go b/pkg/dashboard/data.go index 8bd2a4d..727c395 100644 --- a/pkg/dashboard/data.go +++ b/pkg/dashboard/data.go @@ -325,6 +325,14 @@ func (d *DataLayer) DescribeResource(namespace string, kind string, name string) return out, nil } +func (d *DataLayer) UninstallChart(namespace string, name string) error { + _, err := d.runCommandHelm("uninstall", name, "--namespace", namespace) + if err != nil { + return err + } + return nil +} + func RevisionDiff(functor SectionFn, ext string, namespace string, name string, revision1 int, revision2 int, flag bool) (string, error) { if revision1 == 0 || revision2 == 0 { log.Debugf("One of revisions is zero: %d %d", revision1, revision2) diff --git a/pkg/dashboard/static/index.html b/pkg/dashboard/static/index.html index c958593..3d9add6 100644 --- a/pkg/dashboard/static/index.html +++ b/pkg/dashboard/static/index.html @@ -58,8 +58,12 @@