Skip to content

Commit

Permalink
fix env version displayed wrong system user after update env
Browse files Browse the repository at this point in the history
Signed-off-by: Patrick Zhao <[email protected]>
  • Loading branch information
PetrusZ committed Jun 19, 2024
1 parent f0277d4 commit ba15dd6
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1234,7 +1234,7 @@ func updateMultiK8sEnv(c *gin.Context, request *service.UpdateEnvRequest, produc
return
}

ctx.Resp, ctx.Err = service.UpdateMultipleK8sEnv(args, envNames, request.ProjectName, ctx.RequestID, request.Force, production, ctx.Logger)
ctx.Resp, ctx.Err = service.UpdateMultipleK8sEnv(args, envNames, request.ProjectName, ctx.RequestID, request.Force, production, ctx.UserName, ctx.Logger)
}

func updateMultiHelmEnv(c *gin.Context, request *service.UpdateEnvRequest, production bool, ctx *internalhandler.Context) {
Expand Down
4 changes: 2 additions & 2 deletions pkg/microservice/aslan/core/environment/handler/openapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ func OpenAPIApplyYamlService(c *gin.Context) {
}
}

_, err = service.OpenAPIApplyYamlService(projectKey, req, false, ctx.RequestID, ctx.Logger)
_, err = service.OpenAPIApplyYamlService(projectKey, req, false, ctx.RequestID, ctx.UserName, ctx.Logger)

ctx.Err = err
}
Expand Down Expand Up @@ -368,7 +368,7 @@ func OpenAPIApplyProductionYamlService(c *gin.Context) {
return
}

_, err = service.OpenAPIApplyYamlService(projectKey, req, true, ctx.RequestID, ctx.Logger)
_, err = service.OpenAPIApplyYamlService(projectKey, req, true, ctx.RequestID, ctx.UserName, ctx.Logger)
ctx.Err = err
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ type UpdateEnv struct {
Services []*UpdateServiceArg `json:"services"`
}

func UpdateMultipleK8sEnv(args []*UpdateEnv, envNames []string, productName, requestID string, force, production bool, log *zap.SugaredLogger) ([]*EnvStatus, error) {
func UpdateMultipleK8sEnv(args []*UpdateEnv, envNames []string, productName, requestID string, force, production bool, username string, log *zap.SugaredLogger) ([]*EnvStatus, error) {
mutexAutoUpdate := cache.NewRedisLock(fmt.Sprintf("update_multiple_product:%s", productName))
err := mutexAutoUpdate.Lock()
if err != nil {
Expand Down Expand Up @@ -497,7 +497,7 @@ func UpdateMultipleK8sEnv(args []*UpdateEnv, envNames []string, productName, req

// update env default variable, particular svcs from client are involved
// svc revision will not be updated
err = updateK8sProduct(exitedProd, setting.SystemUser, requestID, updateRevisionSvcs, filter, updateSvcs, strategyMap, force, exitedProd.GlobalVariables, log)
err = updateK8sProduct(exitedProd, username, requestID, updateRevisionSvcs, filter, updateSvcs, strategyMap, force, exitedProd.GlobalVariables, log)
if err != nil {
log.Errorf("UpdateMultipleK8sEnv UpdateProductV2 err:%v", err)
errList = multierror.Append(errList, err)
Expand All @@ -506,7 +506,7 @@ func UpdateMultipleK8sEnv(args []*UpdateEnv, envNames []string, productName, req

productResps := make([]*ProductResp, 0)
for _, envName := range envNames {
productResp, err := GetProduct(setting.SystemUser, envName, productName, log)
productResp, err := GetProduct(username, envName, productName, log)
if err == nil && productResp != nil {
productResps = append(productResps, productResp)
}
Expand Down Expand Up @@ -807,7 +807,7 @@ func UpdateMultiCVMProducts(envNames []string, productName, user, requestID stri

productResps := make([]*ProductResp, 0)
for _, envName := range envNames {
productResp, err := GetProduct(setting.SystemUser, envName, productName, log)
productResp, err := GetProduct(user, envName, productName, log)
if err == nil && productResp != nil {
productResps = append(productResps, productResp)
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/microservice/aslan/core/environment/service/openapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,11 +210,11 @@ func OpenAPIUpdateYamlService(req *OpenAPIServiceVariablesReq, userName, request
if len(args) == 0 {
return nil
}
_, err = UpdateMultipleK8sEnv(args, []string{envName}, projectName, requestID, true, production, logger)
_, err = UpdateMultipleK8sEnv(args, []string{envName}, projectName, requestID, true, production, userName, logger)
return err
}

func OpenAPIApplyYamlService(projectKey string, req *OpenAPIApplyYamlServiceReq, production bool, requestID string, logger *zap.SugaredLogger) ([]*EnvStatus, error) {
func OpenAPIApplyYamlService(projectKey string, req *OpenAPIApplyYamlServiceReq, production bool, requestID, userName string, logger *zap.SugaredLogger) ([]*EnvStatus, error) {
env, err := commonrepo.NewProductColl().Find(&commonrepo.ProductFindOptions{Name: projectKey, EnvName: req.EnvName})
if err != nil {
logger.Errorf("failed to find env:%s from db, project:%s", req.EnvName, projectKey)
Expand Down Expand Up @@ -255,7 +255,7 @@ func OpenAPIApplyYamlService(projectKey string, req *OpenAPIApplyYamlServiceReq,
Services: svcList,
})

return UpdateMultipleK8sEnv(args, []string{req.EnvName}, projectKey, requestID, false, false, logger)
return UpdateMultipleK8sEnv(args, []string{req.EnvName}, projectKey, requestID, false, false, userName, logger)
}

func checkServiceInEnv(envServices [][]*commonmodels.ProductService, services []*YamlServiceWithKV) error {
Expand Down

0 comments on commit ba15dd6

Please sign in to comment.