diff --git a/internal/api/v1/cluster/cluster.go b/internal/api/v1/cluster/cluster.go index 5ae32ef6b..21a5392ac 100644 --- a/internal/api/v1/cluster/cluster.go +++ b/internal/api/v1/cluster/cluster.go @@ -111,6 +111,7 @@ func (h *Handler) CreateCluster() iris.Handler { txOptions := common.DBOptions{DB: tx} req.Cluster.Status.Phase = clusterStatusSaved if err := h.clusterService.Create(&req.Cluster, txOptions); err != nil { + tx.Rollback() ctx.StatusCode(iris.StatusInternalServerError) ctx.Values().Set("message", err.Error()) return @@ -125,11 +126,13 @@ func (h *Handler) CreateCluster() iris.Handler { } notAllowed, err := checkRequiredPermissions(client, requiredPermissions) if err != nil { + tx.Rollback() ctx.StatusCode(iris.StatusInternalServerError) ctx.Values().Set("message", err.Error()) return } if notAllowed != "" { + tx.Rollback() ctx.StatusCode(iris.StatusInternalServerError) ctx.Values().Set("message", []string{"permission %s required", notAllowed}) return