diff --git a/pkg/microservice/aslan/core/common/repository/mongodb/workflow_v4.go b/pkg/microservice/aslan/core/common/repository/mongodb/workflow_v4.go index 3713c58c74..9b3397ae29 100644 --- a/pkg/microservice/aslan/core/common/repository/mongodb/workflow_v4.go +++ b/pkg/microservice/aslan/core/common/repository/mongodb/workflow_v4.go @@ -498,38 +498,6 @@ func (c *WorkflowV4Coll) ListByCursor(opt *ListWorkflowV4Option) (*mongo.Cursor, return c.Collection.Find(context.TODO(), query) } -// ListNamesByAITarget returns the display names of the workflows that reference the -// given AI target in an AI job, so that the target is not deleted while still in use. -func (c *WorkflowV4Coll) ListNamesByAITarget(ctx context.Context, targetType, targetID string) ([]string, error) { - query := bson.M{ - "stages.jobs": bson.M{ - "$elemMatch": bson.M{ - "type": config.JobAI, - "spec.target_type": targetType, - "spec.target_id": targetID, - }, - }, - } - cursor, err := c.Collection.Find(ctx, query, options.Find().SetProjection(bson.M{"display_name": 1, "name": 1})) - if err != nil { - return nil, err - } - workflows := make([]*models.WorkflowV4, 0) - if err := cursor.All(ctx, &workflows); err != nil { - return nil, err - } - - names := make([]string, 0, len(workflows)) - for _, workflow := range workflows { - name := workflow.DisplayName - if name == "" { - name = workflow.Name - } - names = append(names, name) - } - return names, nil -} - func (c *WorkflowV4Coll) GetJobNameList(projectName, workflowName, jobType string) ([]string, error) { workflow := new(models.WorkflowV4) query := bson.M{"project": projectName, "name": workflowName} diff --git a/pkg/microservice/aslan/core/system/service/agent_integration.go b/pkg/microservice/aslan/core/system/service/agent_integration.go index 5e0255972a..d8164683ab 100644 --- a/pkg/microservice/aslan/core/system/service/agent_integration.go +++ b/pkg/microservice/aslan/core/system/service/agent_integration.go @@ -22,7 +22,6 @@ import ( "net/url" "strings" - "github.com/koderover/zadig/v2/pkg/microservice/aslan/config" commonmodels "github.com/koderover/zadig/v2/pkg/microservice/aslan/core/common/repository/models" commonrepo "github.com/koderover/zadig/v2/pkg/microservice/aslan/core/common/repository/mongodb" templaterepo "github.com/koderover/zadig/v2/pkg/microservice/aslan/core/common/repository/mongodb/template" @@ -143,13 +142,6 @@ func DeleteAgentIntegration(ctx context.Context, projectName, id string) error { if _, err := findProjectAgentIntegration(ctx, projectName, id); err != nil { return e.ErrDeleteAgentIntegration.AddErr(err) } - workflowNames, err := commonrepo.NewWorkflowV4Coll().ListNamesByAITarget(ctx, config.AITargetTypeAgent, id) - if err != nil { - return e.ErrDeleteAgentIntegration.AddErr(fmt.Errorf("find workflows referencing the agent: %w", err)) - } - if len(workflowNames) > 0 { - return e.ErrDeleteAgentIntegration.AddErr(fmt.Errorf("agent is still used by workflow: %s", strings.Join(workflowNames, ", "))) - } if err := commonrepo.NewAgentIntegrationColl().Delete(ctx, id); err != nil { return e.ErrDeleteAgentIntegration.AddErr(err) }