Skip to content

Commit cd64c5c

Browse files
authored
fix release plan status and workflow spec (#4358)
Signed-off-by: Patrick Zhao <[email protected]>
1 parent 3bd4a61 commit cd64c5c

File tree

3 files changed

+31
-9
lines changed

3 files changed

+31
-9
lines changed

pkg/microservice/aslan/core/common/repository/models/workflow_v4.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,7 @@ type DeployHelmChart struct {
526526
type DeployBasicInfo struct {
527527
ServiceName string `bson:"service_name" yaml:"service_name" json:"service_name"`
528528
Modules []*DeployModuleInfo `bson:"modules" yaml:"modules" json:"modules"`
529-
Deployed bool `bson:"-" yaml:"deployed" json:"deployed"`
529+
Deployed bool `bson:"deployed" yaml:"deployed" json:"deployed"`
530530
AutoSync bool `bson:"-" yaml:"auto_sync" json:"auto_sync"`
531531
UpdateConfig bool `bson:"update_config" yaml:"update_config" json:"update_config"`
532532
Updatable bool `bson:"-" yaml:"updatable" json:"updatable"`

pkg/microservice/aslan/core/release_plan/service/execute.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@ package service
1818

1919
import (
2020
"fmt"
21-
"github.com/koderover/zadig/v2/pkg/microservice/aslan/core/workflow/service/workflow/controller"
2221
"time"
2322

2423
"github.com/pkg/errors"
2524

2625
"github.com/koderover/zadig/v2/pkg/microservice/aslan/config"
2726
"github.com/koderover/zadig/v2/pkg/microservice/aslan/core/common/repository/models"
2827
"github.com/koderover/zadig/v2/pkg/microservice/aslan/core/workflow/service/workflow"
28+
"github.com/koderover/zadig/v2/pkg/microservice/aslan/core/workflow/service/workflow/controller"
2929
"github.com/koderover/zadig/v2/pkg/shared/client/user"
3030
"github.com/koderover/zadig/v2/pkg/tool/log"
3131
)

pkg/microservice/aslan/core/release_plan/service/release_plan.go

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -803,7 +803,7 @@ func SkipReleaseJob(c *handler.Context, planID string, args *SkipReleaseJobArgs,
803803
return nil
804804
}
805805

806-
func UpdateReleasePlanStatus(c *handler.Context, planID, status string, isSystemAdmin bool) error {
806+
func UpdateReleasePlanStatus(c *handler.Context, planID, targetStatus string, isSystemAdmin bool) error {
807807
approveLock := getLock(planID)
808808
approveLock.Lock()
809809
defer approveLock.Unlock()
@@ -815,12 +815,16 @@ func UpdateReleasePlanStatus(c *handler.Context, planID, status string, isSystem
815815
return errors.Wrap(err, "get plan")
816816
}
817817

818+
if plan.Status == config.ReleasePlanStatus(targetStatus) {
819+
return fmt.Errorf("current status can not equal to target status %s", targetStatus)
820+
}
821+
818822
if c.UserID != plan.ManagerID && !isSystemAdmin {
819823
return errors.Errorf("only manager can update plan status")
820824
}
821825

822-
if !lo.Contains(config.ReleasePlanStatusMap[plan.Status], config.ReleasePlanStatus(status)) {
823-
return errors.Errorf("can't convert plan status %s to %s", plan.Status, status)
826+
if !lo.Contains(config.ReleasePlanStatusMap[plan.Status], config.ReleasePlanStatus(targetStatus)) {
827+
return errors.Errorf("can't convert plan status %s to %s", plan.Status, targetStatus)
824828
}
825829

826830
userInfo, err := user.New().GetUserByID(c.UserID)
@@ -846,11 +850,20 @@ func UpdateReleasePlanStatus(c *handler.Context, planID, status string, isSystem
846850
return errors.Errorf("plan must not have no jobs")
847851
}
848852
plan.PlanningTime = time.Now().Unix()
853+
case config.ReleasePlanStatusWaitForApproveExternalCheck,
854+
config.ReleasePlanStatusWaitForApproveExternalCheckFailed,
855+
config.ReleasePlanStatusWaitForExecuteExternalCheck,
856+
config.ReleasePlanStatusWaitForExecuteExternalCheckFailed,
857+
config.ReleasePlanStatusWaitForAllDoneExternalCheck,
858+
config.ReleasePlanStatusWaitForAllDoneExternalCheckFailed:
859+
if config.ReleasePlanStatus(targetStatus) != config.ReleasePlanStatusPlanning && config.ReleasePlanStatus(targetStatus) != config.ReleasePlanStatusCancel {
860+
return fmt.Errorf("can't update status, current status: %s", plan.Status)
861+
}
849862
}
850-
plan.Status = config.ReleasePlanStatus(status)
863+
plan.Status = config.ReleasePlanStatus(targetStatus)
851864

852865
// target status check and update
853-
switch config.ReleasePlanStatus(status) {
866+
switch config.ReleasePlanStatus(targetStatus) {
854867
case config.ReleasePlanStatusPlanning:
855868
for _, job := range plan.Jobs {
856869
job.LastStatus = job.Status
@@ -861,6 +874,9 @@ func UpdateReleasePlanStatus(c *handler.Context, planID, status string, isSystem
861874
plan.HookSettings = hookSetting.ToHookSettings()
862875

863876
plan.PlanningTime = time.Now().Unix()
877+
plan.ApprovalTime = 0
878+
plan.ExecutingTime = 0
879+
plan.SuccessTime = 0
864880
plan.WaitForApproveExternalCheckTime = 0
865881
plan.WaitForExecuteExternalCheckTime = 0
866882
plan.WaitForAllDoneExternalCheckTime = 0
@@ -924,7 +940,7 @@ func UpdateReleasePlanStatus(c *handler.Context, planID, status string, isSystem
924940
TargetType: TargetTypeReleasePlanStatus,
925941
Detail: detail,
926942
Before: plan.Status,
927-
After: status,
943+
After: targetStatus,
928944
CreatedAt: time.Now().Unix(),
929945
}); err != nil {
930946
log.Errorf("create release plan log error: %v", err)
@@ -1599,6 +1615,10 @@ func convertWorkflowV4ToOpenAPIWorkflowV4(workflow *commonmodels.WorkflowV4) (*w
15991615

16001616
hookSpec := interface{}(nil)
16011617
for _, job := range stage.Jobs {
1618+
if job.Skipped {
1619+
continue
1620+
}
1621+
16021622
switch job.JobType {
16031623
case config.JobZadigBuild:
16041624
spec := new(commonmodels.ZadigBuildJobSpec)
@@ -1934,7 +1954,9 @@ func convertWorkflowV4ToOpenAPIWorkflowV4(workflow *commonmodels.WorkflowV4) (*w
19341954
})
19351955
}
19361956

1937-
hookStages = append(hookStages, hookStage)
1957+
if len(hookStage.Jobs) != 0 {
1958+
hookStages = append(hookStages, hookStage)
1959+
}
19381960
}
19391961

19401962
return &webhooknotify.OpenAPIWorkflowV4{

0 commit comments

Comments
 (0)