Skip to content

Commit

Permalink
fix: not supported to restart freed cluster
Browse files Browse the repository at this point in the history
Signed-off-by: xu.zhu <[email protected]>
  • Loading branch information
xuzhu-591 committed Dec 11, 2023
1 parent 9356c81 commit f831bdb
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 7 deletions.
9 changes: 6 additions & 3 deletions core/controller/cluster/controller_basic_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -688,9 +688,6 @@ func (c *controller) createPipelineRun(ctx context.Context, clusterID uint,
if err != nil {
return nil, err
}
if r.Action == prmodels.ActionBuildDeploy && cluster.GitURL == "" {
return nil, herrors.ErrBuildDeployNotSupported
}

var (
title = r.Title
Expand Down Expand Up @@ -723,6 +720,9 @@ func (c *controller) createPipelineRun(ctx context.Context, clusterID uint,
switch r.Action {
case prmodels.ActionBuildDeploy:
action = prmodels.ActionBuildDeploy
if cluster.GitURL == "" {
return nil, herrors.ErrBuildDeployNotSupported
}

if r.Git != nil {
if r.Git.Commit != "" {
Expand Down Expand Up @@ -805,6 +805,9 @@ func (c *controller) createPipelineRun(ctx context.Context, clusterID uint,
case prmodels.ActionRestart:
title = prmodels.ActionRestart
action = prmodels.ActionRestart
if cluster.Status == common.ClusterStatusFreed {
return nil, herrors.ErrFreedClusterNotSupportedRestart
}
configCommitSHA = configCommit.Master

default:
Expand Down
5 changes: 5 additions & 0 deletions core/controller/cluster/controller_operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ func (c *controller) Restart(ctx context.Context, clusterID uint) (_ *Pipelineru
return nil, err
}

// freed cluster can not be restarted
if cluster.Status == common.ClusterStatusFreed {
return nil, herrors.ErrFreedClusterNotSupportedRestart
}

// 1. get config commit now
lastConfigCommit, err := c.clusterGitRepo.GetConfigCommit(ctx, application.Name, cluster.Name)
if err != nil {
Expand Down
7 changes: 4 additions & 3 deletions core/errors/horizonerrors.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,9 +219,10 @@ var (
ErrHTTPRequestFailed = errors.New("http request failed")

// cluster
ErrClusterNoChange = errors.New("no change to cluster")
ErrShouldBuildDeployFirst = errors.New("clusters with build config should build and deploy first")
ErrBuildDeployNotSupported = errors.New("builddeploy is not supported for this cluster")
ErrClusterNoChange = errors.New("no change to cluster")
ErrShouldBuildDeployFirst = errors.New("clusters with build config should build and deploy first")
ErrBuildDeployNotSupported = errors.New("builddeploy is not supported for this cluster")
ErrFreedClusterNotSupportedRestart = errors.New("freed cluster is not supported to restart")

// pipelinerun

Expand Down
4 changes: 4 additions & 0 deletions core/http/api/v1/cluster/apis_operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,10 @@ func (a *API) Restart(c *gin.Context) {

resp, err := a.clusterCtl.Restart(c, uint(clusterID))
if err != nil {
if perror.Cause(err) == herrors.ErrFreedClusterNotSupportedRestart {
response.AbortWithRPCError(c, rpcerror.BadRequestError.WithErrMsg(err.Error()))
return
}
if e, ok := perror.Cause(err).(*herrors.HorizonErrNotFound); ok && e.Source == herrors.ClusterInDB {
response.AbortWithRPCError(c, rpcerror.NotFoundError.WithErrMsg(err.Error()))
return
Expand Down
2 changes: 1 addition & 1 deletion core/http/api/v2/application/routers.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"github.com/gin-gonic/gin"
)

// RegisterRoutes register routes
// RegisterRoute registers routes
func (api *API) RegisterRoute(engine *gin.Engine) {
apiV2Group := engine.Group("/apis/core/v2")
apiV2Routes := route.Routes{
Expand Down
4 changes: 4 additions & 0 deletions core/http/api/v2/cluster/apis_operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,10 @@ func (a *API) Restart(c *gin.Context) {

resp, err := a.clusterCtl.Restart(c, uint(clusterID))
if err != nil {
if perror.Cause(err) == herrors.ErrFreedClusterNotSupportedRestart {
response.AbortWithRPCError(c, rpcerror.BadRequestError.WithErrMsg(err.Error()))
return
}
if e, ok := perror.Cause(err).(*herrors.HorizonErrNotFound); ok && e.Source == herrors.ClusterInDB {
response.AbortWithRPCError(c, rpcerror.NotFoundError.WithErrMsg(err.Error()))
return
Expand Down

0 comments on commit f831bdb

Please sign in to comment.