Skip to content
Open
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
1 change: 0 additions & 1 deletion pkg/microservice/aslan/core/plugin/handler/lark.go
Original file line number Diff line number Diff line change
Expand Up @@ -654,4 +654,3 @@ func CheckLarkAuth(c *gin.Context, ctx *internalhandler.Context) (err error) {

return nil
}

71 changes: 71 additions & 0 deletions pkg/microservice/aslan/core/plugin/service/lark.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,20 @@ type UpdateLarkWorkflowConfigRequest struct {
}

func UpdateLarkWorkflowConfig(ctx *internalhandler.Context, req *UpdateLarkWorkflowConfigRequest) error {
validatedWorkflows := sets.New[string]()
updateWorkitemTypeKeySet := sets.Set[string]{}
for _, config := range req.Configs {
config.WorkspaceID = req.WorkspaceID
updateWorkitemTypeKeySet.Insert(config.WorkItemTypeKey)
for _, node := range config.Nodes {
if node == nil || node.WorkflowName == "" || validatedWorkflows.Has(node.WorkflowName) {
continue
}
if err := validateWorkflowForLarkPlugin(node.WorkflowName); err != nil {
return err
}
validatedWorkflows.Insert(node.WorkflowName)
}
}

origConfigs, err := mongodb.NewLarkPluginWorkflowConfigColl().Get(req.WorkspaceID)
Expand Down Expand Up @@ -713,6 +723,46 @@ func ListLarkWorkitemWorkflowTask(ctx *internalhandler.Context, workItemTypeKey,
EnvAlias: commonutil.GetEnvAlias(commonutil.GetEnvInfoNoErr(task.ProjectName, deploy.Env, envMap)),
}
updateDeployEnvs(env)
case aslanconfig.JobZadigVMDeploy:
deploy := new(commonmodels.ZadigVMDeployJobSpec)
if err := commonmodels.IToi(job.Spec, deploy); err != nil {
return nil, fmt.Errorf("failed to convert job spec to vm deploy job spec: %w", err)
}

for _, svc := range deploy.ServiceAndVMDeploys {
sm := &commonmodels.ServiceWithModule{
ServiceName: svc.ServiceName,
ServiceModule: svc.ServiceModule,
}
updateServiceModules(sm)

for _, repo := range svc.Repos {
updateRepos(repo)
}
}
env := &commonmodels.WorkflowEnv{
EnvName: deploy.Env,
Production: deploy.Production,
EnvAlias: commonutil.GetEnvAlias(commonutil.GetEnvInfoNoErr(task.ProjectName, deploy.Env, envMap)),
}
updateDeployEnvs(env)
case aslanconfig.JobZadigTesting:
test := new(commonmodels.ZadigTestingJobSpec)
if err := commonmodels.IToi(job.Spec, test); err != nil {
return nil, fmt.Errorf("failed to convert job spec to test job spec: %w", err)
}

for _, serviceAndTest := range test.ServiceAndTests {
sm := &commonmodels.ServiceWithModule{
ServiceName: serviceAndTest.ServiceName,
ServiceModule: serviceAndTest.ServiceModule,
}
updateServiceModules(sm)

for _, repo := range serviceAndTest.Repos {
updateRepos(repo)
}
}
}
}
}
Expand Down Expand Up @@ -752,6 +802,27 @@ func ListLarkWorkitemWorkflowTask(ctx *internalhandler.Context, workItemTypeKey,
imageSet.Insert(serviceAndImage.Image)
images = append(images, serviceAndImage.Image)
}
case string(aslanconfig.JobZadigVMDeploy):
taskSpec := new(commonmodels.JobTaskFreestyleSpec)
if err := commonmodels.IToi(jobTask.Spec, taskSpec); err != nil {
return nil, fmt.Errorf("failed to convert job spec to vm deploy job spec: %w", err)
}

image := ""
for _, env := range taskSpec.Properties.Envs {
if env.Key == "IMAGE" {
image = env.Value
break
}
}

if jobTask.Status == aslanconfig.StatusPassed && image != "" && !strings.HasPrefix(image, "{{.") && !strings.Contains(image, "}}") {
if imageSet.Has(image) {
continue
}
imageSet.Insert(image)
images = append(images, image)
}
}
}
}
Expand Down
9 changes: 5 additions & 4 deletions pkg/microservice/aslan/core/plugin/service/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ func validateWorkflowForLarkPlugin(workflowName string) error {
if err != nil {
return fmt.Errorf("failed to find workflow %s: %w", workflowName, err)
}

var buildCount, deployCount, testCount, meegoCount int
var buildCount, deployCount, testCount, apolloCount, meegoCount int
buildIdx, deployIdx := -1, -1
jobIdx := 0

Expand All @@ -55,15 +54,17 @@ func validateWorkflowForLarkPlugin(workflowName string) error {
case aslanconfig.JobZadigBuild:
buildCount++
buildIdx = jobIdx
case aslanconfig.JobZadigDeploy:
case aslanconfig.JobZadigDeploy, aslanconfig.JobZadigVMDeploy:
deployCount++
deployIdx = jobIdx
case aslanconfig.JobZadigTesting:
testCount++
case aslanconfig.JobApollo:
apolloCount++
case aslanconfig.JobMeegoTransition:
meegoCount++
default:
return fmt.Errorf("workflow %s contains unsupported job type %s, only build, deploy, and test jobs are allowed", workflowName, job.JobType)
return fmt.Errorf("workflow %s contains unsupported job type %s, only build, kubernetes deploy, host deploy, apollo, meego transition, and test jobs are allowed", workflowName, job.JobType)
}
jobIdx++
}
Expand Down
Loading