Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cherry pick fix scale and update default values bug (#3163) to 2.0.0 #3164

Merged
merged 1 commit into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (
"strings"

"github.com/gin-gonic/gin"
"github.com/koderover/zadig/pkg/microservice/aslan/core/common/util"
"github.com/koderover/zadig/pkg/types"
"k8s.io/apimachinery/pkg/util/sets"

Expand Down Expand Up @@ -1004,13 +1003,6 @@ func UpdateHelmProductDefaultValues(c *gin.Context) {
return
}

// license checks
err = util.CheckZadigXLicenseStatus()
if err != nil {
ctx.Err = err
return
}

projectKey, envName, err := generalRequestValidate(c)
if err != nil {
ctx.Err = e.ErrInvalidParam.AddErr(err)
Expand Down
2 changes: 1 addition & 1 deletion pkg/microservice/aslan/core/environment/handler/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ func (*Router) Inject(router *gin.RouterGroup) {
production.POST("/environments/:name/services/:serviceName/restartNew", RestartProductionWorkload)

// k8s resources operations
production.POST("/environments/:name/services/:serviceName/scaleNew", ScaleNewService)
production.POST("/environments/:name/services/:serviceName/scaleNew", ScaleNewProductionService)
production.POST("/image/deployment/:envName", UpdateProductionDeploymentContainerImage)

production.GET("/rendersets/variables", GetProductionServiceVariables)
Expand Down
60 changes: 60 additions & 0 deletions pkg/microservice/aslan/core/environment/handler/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,66 @@ func ScaleNewService(c *gin.Context) {
}
}

internalhandler.InsertDetailedOperationLog(
c, ctx.UserName,
projectKey, setting.OperationSceneEnv,
"伸缩",
"环境-服务",
fmt.Sprintf("环境名称:%s,%s:%s", envName, resourceType, name),
"", ctx.Logger, envName)

number, err := strconv.Atoi(c.Query("number"))
if err != nil {
ctx.Err = e.ErrInvalidParam.AddDesc("invalid number format")
return
}

ctx.Err = service.Scale(&service.ScaleArgs{
Type: resourceType,
ProductName: projectKey,
EnvName: envName,
ServiceName: serviceName,
Name: name,
Number: number,
}, ctx.Logger)
}

func ScaleNewProductionService(c *gin.Context) {
ctx, err := internalhandler.NewContextWithAuthorization(c)
defer func() { internalhandler.JSONResponse(c, ctx) }()

if err != nil {

ctx.Err = fmt.Errorf("authorization Info Generation failed: err %s", err)
ctx.UnAuthorized = true
return
}

args := new(service.ScaleArgs)
args.Type = setting.Deployment

projectKey := c.Query("projectName")
serviceName := c.Param("serviceName")
envName := c.Param("name")
resourceType := c.Query("type")
name := c.Query("name")

// authorization checks
if !ctx.Resources.IsSystemAdmin {
if _, ok := ctx.Resources.ProjectAuthInfo[projectKey]; !ok {
ctx.UnAuthorized = true
return
}
if !ctx.Resources.ProjectAuthInfo[projectKey].IsProjectAdmin &&
!ctx.Resources.ProjectAuthInfo[projectKey].ProductionEnv.ManagePods {
permitted, err := internalhandler.GetCollaborationModePermission(ctx.UserID, projectKey, types.ResourceTypeEnvironment, envName, types.ProductionEnvActionManagePod)
if err != nil || !permitted {
ctx.UnAuthorized = true
return
}
}
}

if err := commonutil.CheckZadigXLicenseStatus(); err != nil {
ctx.Err = err
return
Expand Down
Loading