mirror of
https://github.com/komodorio/helm-dashboard.git
synced 2026-03-24 11:48:04 +00:00
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 <harshitm@nvidia.com>
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -343,3 +343,18 @@ $("#btnAddRepository").click(function () {
|
||||
setHashParam("section", "repository")
|
||||
window.location.reload()
|
||||
})
|
||||
|
||||
$("#btnTest").click(function() {
|
||||
$("#testModal .test-result").empty().prepend('<span class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span>')
|
||||
$.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", "<br>"))
|
||||
})
|
||||
|
||||
const myModal = new bootstrap.Modal(document.getElementById('testModal'), {});
|
||||
myModal.show()
|
||||
})
|
||||
@@ -194,6 +194,9 @@
|
||||
<button id="btnRollback" class="btn btn-sm btn-light bg-white border border-secondary me-2"
|
||||
title="Rollback to this revision"><i class="bi-arrow-repeat"></i> <span>Rollback</span>
|
||||
</button>
|
||||
<button id="btnTest" class="btn btn-sm btn-light bg-white border border-secondary"
|
||||
title="Run tests for this chart"><i class="bi-check-circle"></i> <span>Run tests</span>
|
||||
</button>
|
||||
<button id="btnUninstall" class="btn btn-sm btn-light bg-white border border-secondary"
|
||||
title="Uninstall the chart"><i class="bi-trash3"></i> Uninstall
|
||||
</button>
|
||||
@@ -417,6 +420,26 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="modal" id="testModal" tabindex="-1">
|
||||
<div class="modal-dialog modal-dialog modal-dialog-scrollable modal-xl">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h4 class="modal-title" id="testModalLabel">
|
||||
<span class="type">Test results</span>
|
||||
</h4>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
||||
</div>
|
||||
<div class="modal-body border-bottom fs-5">
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<span class="test-result"></span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Modal -->
|
||||
<div class="modal fade" id="PowerOffModal" tabindex="-1" aria-labelledby="ModalLabel" aria-hidden="true">
|
||||
<div class="modal-dialog">
|
||||
|
||||
@@ -295,4 +295,8 @@ nav .nav-tabs .nav-link.active {
|
||||
|
||||
#sectionRepo .repo-details ul .row:hover .btn {
|
||||
visibility: visible;
|
||||
}
|
||||
|
||||
.test-result {
|
||||
font-size: 1rem;
|
||||
}
|
||||
@@ -278,6 +278,17 @@ func (d *DataLayer) ChartInstall(namespace string, name string, repoChart string
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (d *DataLayer) RunTests(namespace string, name string) (string, error) {
|
||||
cmd := []string{"test", name, "--namespace", namespace, "--logs"}
|
||||
|
||||
out, err := d.runCommandHelm(cmd...)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return out, 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)
|
||||
|
||||
Reference in New Issue
Block a user