From 83e4348ace566ac50a4fc0b2cabf28adf254268a Mon Sep 17 00:00:00 2001 From: Harshit Mehta Date: Thu, 12 Jan 2023 18:05:11 +0530 Subject: [PATCH] Add option to execute Tests for release (#178) * Add button to execute tests * Create API to execute tests * Add modal for Test response * Make API call to execute tests and show response in modal * Clean up * Update docs - feature execute tests for a release * Add arg '--logs' to 'helm test' cmd * Wait for API to complete before sending back response to frontend * Add loading spinner until reponse for 'helm test' is returned from backend by API * Clean-up Co-authored-by: Harshit Mehta --- README.md | 10 ++++++++++ pkg/dashboard/api.go | 1 + pkg/dashboard/handlers/helmHandlers.go | 16 ++++++++++++++++ pkg/dashboard/static/actions.js | 15 +++++++++++++++ pkg/dashboard/static/index.html | 23 +++++++++++++++++++++++ pkg/dashboard/static/styles.css | 4 ++++ pkg/dashboard/subproc/data.go | 11 +++++++++++ screenshot_run_test.png | Bin 0 -> 49039 bytes screenshot_run_test_result.png | Bin 0 -> 61412 bytes 9 files changed, 80 insertions(+) create mode 100755 screenshot_run_test.png create mode 100755 screenshot_run_test_result.png diff --git a/README.md b/README.md index 3940ab8..cebbd2b 100644 --- a/README.md +++ b/README.md @@ -88,6 +88,16 @@ The official helm chart is [available here](https://github.com/komodorio/helm-ch Download the appropriate [release package](https://github.com/komodorio/helm-dashboard/releases) for your platform, unpack it and just run `dashboard` binary from it. +## Execute Helm tests + +For all the release(s) (istalled helm charts), you can execute helm tests for that release. For the tests to execute successfully, you need to have existing tests for that helm chart + +You can execute `helm test` for the specific release as below: +![](screenshot_run_test.png) + +The result of executed `helm test` for the release will be disapled as below: +![](screenshot_run_test_result.png) + ## Scanner Integrations Upon startup, Helm Dashboard detects the presence of [Trivy](https://github.com/aquasecurity/trivy) diff --git a/pkg/dashboard/api.go b/pkg/dashboard/api.go index e8246f0..5f2917c 100644 --- a/pkg/dashboard/api.go +++ b/pkg/dashboard/api.go @@ -112,6 +112,7 @@ func configureHelms(api *gin.RouterGroup, data *subproc.DataLayer) { api.GET("/charts/:section", h.GetInfoSection) api.GET("/charts/show", h.Show) api.POST("/charts/install", h.Install) + api.POST("/charts/tests", h.Tests) api.POST("/charts/rollback", h.Rollback) api.GET("/repo", h.RepoList) diff --git a/pkg/dashboard/handlers/helmHandlers.go b/pkg/dashboard/handlers/helmHandlers.go index 34f25c5..4a2c209 100644 --- a/pkg/dashboard/handlers/helmHandlers.go +++ b/pkg/dashboard/handlers/helmHandlers.go @@ -176,6 +176,22 @@ func (h *HelmHandler) Install(c *gin.Context) { c.String(http.StatusAccepted, out) } +func (h *HelmHandler) Tests(c *gin.Context) { + qp, err := utils.GetQueryProps(c, false) + if err != nil { + _ = c.AbortWithError(http.StatusBadRequest, err) + return + } + + out, err := h.Data.RunTests(qp.Namespace, qp.Name) + if err != nil { + _ = c.AbortWithError(http.StatusInternalServerError, err) + return + } + + c.String(http.StatusOK, out) +} + func (h *HelmHandler) GetInfoSection(c *gin.Context) { qp, err := utils.GetQueryProps(c, true) if err != nil { diff --git a/pkg/dashboard/static/actions.js b/pkg/dashboard/static/actions.js index a116475..f0492b9 100644 --- a/pkg/dashboard/static/actions.js +++ b/pkg/dashboard/static/actions.js @@ -343,3 +343,18 @@ $("#btnAddRepository").click(function () { setHashParam("section", "repository") window.location.reload() }) + +$("#btnTest").click(function() { + $("#testModal .test-result").empty().prepend('') + $.ajax({ + type: 'POST', + url: "/api/helm/charts/tests" + "?namespace=" + getHashParam("namespace") + "&name=" + getHashParam("chart") + }).fail(function (xhr) { + reportError("Failed to execute test for chart", xhr) + }).done(function (data) { + $("#testModal .test-result").empty().html(data.replaceAll("\n", "
")) + }) + + const myModal = new bootstrap.Modal(document.getElementById('testModal'), {}); + myModal.show() +}) \ No newline at end of file diff --git a/pkg/dashboard/static/index.html b/pkg/dashboard/static/index.html index 47df5ca..8448582 100644 --- a/pkg/dashboard/static/index.html +++ b/pkg/dashboard/static/index.html @@ -194,6 +194,9 @@ + @@ -417,6 +420,26 @@ + +