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

add sae testing env support #3868

Merged
merged 3 commits into from
Dec 3, 2024
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
25 changes: 15 additions & 10 deletions pkg/microservice/aslan/core/common/repository/mongodb/sae_env.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ type SAEEnvFindOptions struct {
type SAEEnvListOptions struct {
EnvName string
ProjectName string
Namespace string
Production *bool
IsSortByUpdateTime bool
IsSortByProductName bool
InEnvs []string
Expand Down Expand Up @@ -79,21 +79,26 @@ func (c *SAEEnvColl) EnsureIndex(ctx context.Context) error {
mod := []mongo.IndexModel{
{
Keys: bson.D{
bson.E{Key: "env_name", Value: 1},
bson.E{Key: "project_name", Value: 1},
bson.E{Key: "production", Value: 1},
bson.E{Key: "update_time", Value: 1},
},
Options: options.Index().SetUnique(true),
Options: options.Index().SetUnique(true).SetName("idx_project_production"),
},
{
Keys: bson.D{
bson.E{Key: "env_name", Value: 1},
bson.E{Key: "project_name", Value: 1},
bson.E{Key: "env_name", Value: 1},
bson.E{Key: "production", Value: 1},
bson.E{Key: "update_time", Value: 1},
},
Options: options.Index().SetUnique(false),
Options: options.Index().SetUnique(false).SetName("idx_project_env_production_time"),
},
}

c.Indexes().DropOne(ctx, "env_name_1_project_name_1")
c.Indexes().DropOne(ctx, "env_name_1_project_name_1_update_time_1")

_, err := c.Indexes().CreateMany(ctx, mod)

return err
Expand Down Expand Up @@ -123,16 +128,16 @@ func (c *SAEEnvColl) List(opt *SAEEnvListOptions) ([]*models.SAEEnv, error) {
if opt == nil {
opt = &SAEEnvListOptions{}
}
if opt.ProjectName != "" {
query["project_name"] = opt.ProjectName
}
if opt.EnvName != "" {
query["env_name"] = opt.EnvName
} else if len(opt.InEnvs) > 0 {
query["env_name"] = bson.M{"$in": opt.InEnvs}
}
if opt.ProjectName != "" {
query["project_name"] = opt.ProjectName
}
if opt.Namespace != "" {
query["namespace"] = opt.Namespace
if opt.Production != nil {
query["production"] = *opt.Production
}
if len(opt.InIDs) > 0 {
var oids []primitive.ObjectID
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ func NewSAEDeployJobCtl(job *commonmodels.JobTask, workflowCtx *commonmodels.Wor
func (c *SAEDeployJobCtl) Clean(ctx context.Context) {}

func (c *SAEDeployJobCtl) Run(ctx context.Context) {
opt := &commonrepo.SAEEnvFindOptions{ProjectName: c.workflowCtx.ProjectName, EnvName: c.jobTaskSpec.Env}
opt := &commonrepo.SAEEnvFindOptions{ProjectName: c.workflowCtx.ProjectName, EnvName: c.jobTaskSpec.Env, Production: &c.jobTaskSpec.Production}
env, err := commonrepo.NewSAEEnvColl().Find(opt)
if err != nil {
err = fmt.Errorf("failed to find SAE env, projectName: %s, envName: %s, error: %s", c.workflowCtx.ProjectName, c.jobTaskSpec.Env, err)
err = fmt.Errorf("failed to find SAE env, projectName: %s, envName: %s, production %v, error: %s", c.workflowCtx.ProjectName, c.jobTaskSpec.Env, c.jobTaskSpec.Production, err)
c.logger.Error(err)
c.job.Status = config.StatusFailed
c.job.Error = err.Error()
Expand Down
Loading
Loading