diff --git a/modules/core-services/services/project/project.go b/modules/core-services/services/project/project.go index a98690dc1f6..4feb6aee1a7 100644 --- a/modules/core-services/services/project/project.go +++ b/modules/core-services/services/project/project.go @@ -761,7 +761,7 @@ func (p *Project) fetchPodInfo(dto *apistructs.ProjectDTO) { return } var podInfos []apistructs.PodInfo - if err := p.db.Find(&podInfos, map[string]interface{}{"project_id": dto.ID, "phase": "running"}).Error; err != nil { + if err := p.db.Find(&podInfos, RunningPodCond(dto.ID)).Error; err != nil { logrus.WithError(err).WithField("project_id", dto.ID). Warnln("failed to Find the namespaces info in the project") return @@ -1584,3 +1584,10 @@ func (p *Project) ListUnblockAppCountsByProjectIDS(projectIDS []uint64) ([]model } return p.db.ListUnblockAppCountsByProjectIDS(projectIDS) } + +func RunningPodCond(projectID uint64) map[string]interface{} { + return map[string]interface{}{ + "project_id": strconv.FormatUint(projectID, 10), + "phase": "running", + } +} diff --git a/modules/core-services/services/project/project_test.go b/modules/core-services/services/project/project_test.go index 5ecbe69310b..cd7709f8450 100644 --- a/modules/core-services/services/project/project_test.go +++ b/modules/core-services/services/project/project_test.go @@ -398,3 +398,13 @@ func TestGetNotFoundProject(t *testing.T) { _, err := p.Get(context.Background(), 1, true) assert.Equal(t, dao.ErrNotFoundProject, err) } + +func TestRunningPodCond(t *testing.T) { + cond := RunningPodCond(1) + if cond["project_id"] != "1" { + t.Fatal("error") + } + if cond["phase"] != "running" { + t.Fatal("error") + } +}