Skip to content

Commit 80e63ed

Browse files
authored
support restart job (#4479)
Signed-off-by: Patrick Zhao <zhaoyu@koderover.com>
1 parent 2380f2e commit 80e63ed

File tree

9 files changed

+945
-3
lines changed

9 files changed

+945
-3
lines changed

pkg/microservice/aslan/config/consts.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ const (
228228
JobZadigVMDeploy JobType = "zadig-vm-deploy"
229229
JobZadigHelmDeploy JobType = "zadig-helm-deploy"
230230
JobZadigHelmChartDeploy JobType = "zadig-helm-chart-deploy"
231+
JobZadigRestart JobType = "zadig-restart"
231232
JobFreestyle JobType = "freestyle"
232233
JobPlugin JobType = "plugin"
233234
JobK8sBlueGreenDeploy JobType = "k8s-blue-green-deploy"

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,18 @@ type JobTaskDeploySpec struct {
240240
OriginRevision int64 `bson:"origin_revision" json:"origin_revision" yaml:"origin_revision"`
241241
}
242242

243+
type JobTaskRestartSpec struct {
244+
Env string `bson:"env" json:"env" yaml:"env"`
245+
ServiceName string `bson:"service_name" json:"service_name" yaml:"service_name"`
246+
Production bool `bson:"production" json:"production" yaml:"production"`
247+
DeployType string `bson:"deploy_type" json:"deploy_type" yaml:"deploy_type"`
248+
SkipCheckRunStatus bool `bson:"skip_check_run_status" json:"skip_check_run_status" yaml:"skip_check_run_status"`
249+
ClusterID string `bson:"cluster_id" json:"cluster_id" yaml:"cluster_id"`
250+
Timeout int `bson:"timeout" json:"timeout" yaml:"timeout"`
251+
ReplaceResources []Resource `bson:"replace_resources" json:"replace_resources" yaml:"replace_resources"`
252+
RelatedPodLabels []map[string]string `bson:"-" json:"-" yaml:"-"`
253+
}
254+
243255
type JobTaskDeployRevertSpec struct {
244256
JobTaskCommonRevertSpec `bson:",inline" json:",inline" yaml:",inline"`
245257
Env string `bson:"env" json:"env" yaml:"env"`

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -613,6 +613,25 @@ type ServiceWithModuleAndImage struct {
613613
ServiceModules []*DeployModuleInfo `bson:"service_modules" yaml:"service_modules" json:"service_modules"`
614614
}
615615

616+
type ZadigRestartJobSpec struct {
617+
Env string `bson:"env" yaml:"env" json:"env"`
618+
// fromjob/runtime/fixed, runtime 表示运行时输入,fromjob 表示从上游构建任务中获取
619+
EnvSource config.DeploySourceType `bson:"env_source" yaml:"env_source" json:"env_source"`
620+
// 当 source 为 fromjob 时需要,指定部署镜像来源是上游哪一个构建任务
621+
EnvJobName string `bson:"env_job_name" yaml:"env_job_name" json:"env_job_name"`
622+
EnvOptions []*ZadigRestartEnvInformation `bson:"-" yaml:"env_options" json:"env_options"`
623+
Production bool `bson:"production" yaml:"production" json:"production"`
624+
DeployType string `bson:"deploy_type" yaml:"deploy_type,omitempty" json:"deploy_type"`
625+
SkipCheckRunStatus bool `bson:"skip_check_run_status" yaml:"skip_check_run_status" json:"skip_check_run_status"`
626+
// fromjob/runtime, runtime 表示运行时输入,fromjob 表示从上游构建任务中获取
627+
Source config.DeploySourceType `bson:"source" yaml:"source" json:"source"`
628+
// 当 source 为 fromjob 时需要,指定部署镜像来源是上游哪一个构建任务
629+
JobName string `bson:"job_name" yaml:"job_name" json:"job_name"`
630+
// save the origin quoted job name
631+
OriginJobName string `bson:"origin_job_name" yaml:"origin_job_name" json:"origin_job_name"`
632+
Services []string `bson:"services" yaml:"services" json:"services"`
633+
}
634+
616635
type ZadigDistributeImageJobSpec struct {
617636
// fromjob/runtime, `runtime` means runtime input, `fromjob` means that it is obtained from the upstream build job
618637
Source config.DeploySourceType `bson:"source" yaml:"source" json:"source"`
@@ -859,6 +878,13 @@ type ZadigDeployEnvInformation struct {
859878
Services []*DeployOptionInfo `json:"services" yaml:"services"`
860879
}
861880

881+
type ZadigRestartEnvInformation struct {
882+
Env string `json:"env" yaml:"env"`
883+
EnvAlias string `json:"env_alias" yaml:"env_alias"`
884+
Production bool `json:"production" yaml:"production"`
885+
Services []string `json:"services" yaml:"services"`
886+
}
887+
862888
type ZadigHelmDeployEnvInformation struct {
863889
Env string `json:"env" yaml:"env"`
864890
Services []*DeployHelmChart `json:"services" yaml:"services"`

pkg/microservice/aslan/core/common/service/kube/render.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ func FetchCurrentAppliedYaml(option *GeneSvcYamlOption) (string, int, error) {
403403
return fullRenderedYaml, 0, nil
404404
}
405405

406-
func fetchImportedManifests(option *GeneSvcYamlOption, productInfo *models.Product, serviceTmp *models.Service, svcRender *template.ServiceRender) (string, []*WorkloadResource, error) {
406+
func FetchImportedManifests(option *GeneSvcYamlOption, productInfo *models.Product, serviceTmp *models.Service, svcRender *template.ServiceRender) (string, []*WorkloadResource, error) {
407407
fullRenderedYaml, err := RenderServiceYaml(serviceTmp.Yaml, option.ProductName, option.ServiceName, svcRender)
408408
if err != nil {
409409
return "", nil, err
@@ -543,7 +543,7 @@ func GenerateRenderedYaml(option *GeneSvcYamlOption) (string, int, []*WorkloadRe
543543

544544
// service not deployed by zadig, should only be updated with images
545545
if !option.UnInstall && !option.UpdateServiceRevision && variableYamlNil(option.VariableYaml) && curProductSvc != nil && !commonutil.ServiceDeployed(option.ServiceName, productInfo.ServiceDeployStrategy) {
546-
manifest, workloads, err := fetchImportedManifests(option, productInfo, prodSvcTemplate, serviceRender)
546+
manifest, workloads, err := FetchImportedManifests(option, productInfo, prodSvcTemplate, serviceRender)
547547
return manifest, int(curProductSvc.Revision), workloads, err
548548
}
549549

pkg/microservice/aslan/core/common/service/workflowcontroller/jobcontroller/job.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ func initJobCtl(job *commonmodels.JobTask, workflowCtx *commonmodels.WorkflowTas
5555
jobCtl = NewHelmDeployJobCtl(job, workflowCtx, ack, logger)
5656
case string(config.JobZadigHelmChartDeploy):
5757
jobCtl = NewHelmChartDeployJobCtl(job, workflowCtx, ack, logger)
58+
case string(config.JobZadigRestart):
59+
jobCtl = NewRestartJobCtl(job, workflowCtx, ack, logger)
5860
case string(config.JobCustomDeploy):
5961
jobCtl = NewCustomDeployJobCtl(job, workflowCtx, ack, logger)
6062
case string(config.JobPlugin):

0 commit comments

Comments
 (0)