Skip to content

fix: quota audit #3349

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

Merged
merged 3 commits into from
Dec 14, 2021
Merged
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
16 changes: 11 additions & 5 deletions modules/core-services/services/project/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,16 @@ func New(opts ...Option) *Project {
}

// WithDBClient 配置 db client
func WithDBClient(dbClient *dao.DBClient) Option {
func WithDBClient(db *dao.DBClient) Option {
return func(project *Project) {
project.db = dbClient
project.db = db
}
}

// WithUCClient 配置 uc client
func WithUCClient(ucClient *ucauth.UCClient) Option {
func WithUCClient(uc *ucauth.UCClient) Option {
return func(project *Project) {
project.uc = ucClient
project.uc = uc
}
}

Expand Down Expand Up @@ -345,6 +345,8 @@ func (p *Project) Update(ctx context.Context, orgID, projectID int64, userID str
if err != nil {
return nil, errors.Wrap(err, "failed to GetProjectByID")
}
var oldClusterConfig = make(map[string]string)
_ = json.Unmarshal([]byte(project.ClusterConfig), &oldClusterConfig)
oldQuota, err := p.db.GetQuotaByProjectID(projectID)
if err != nil {
return nil, errors.Wrap(err, "failed to GetQuotaByProjectID")
Expand Down Expand Up @@ -372,14 +374,18 @@ func (p *Project) Update(ctx context.Context, orgID, projectID int64, userID str
return &project, nil
}

// check new quota is less than reqeust
// check new quota is less than request
var dto = new(apistructs.ProjectDTO)
dto.ID = uint64(project.ID)
setProjectDtoQuotaFromModel(dto, project.Quota)
p.fetchPodInfo(dto)
changedRecord := make(map[string]bool)
if oldQuota == nil {
oldQuota = new(apistructs.ProjectQuota)
oldQuota.ProdClusterName = oldClusterConfig["PROD"]
oldQuota.StagingClusterName = oldClusterConfig["STAGING"]
oldQuota.TestClusterName = oldClusterConfig["TEST"]
oldQuota.DevClusterName = oldClusterConfig["DEV"]
}
isQuotaChangedOnTheWorkspace(changedRecord, *oldQuota, *project.Quota)
if msg, ok := p.checkNewQuotaIsLessThanRequest(ctx, dto, changedRecord); !ok {
Expand Down