From 60dc591fdbf492a39e5ba60ebb9836863c63f768 Mon Sep 17 00:00:00 2001 From: Min Min Date: Thu, 29 Aug 2024 15:00:47 +0800 Subject: [PATCH 1/2] remove unused field for db's sake Signed-off-by: Min Min --- .../aslan/core/workflow/service/workflow/job/job.go | 10 ++++++++++ .../core/workflow/service/workflow/job/job_apollo.go | 11 +++++++++++ .../service/workflow/job/job_blue_green_deploy_v2.go | 11 +++++++++++ .../service/workflow/job/job_blue_green_release_v2.go | 4 ++++ .../workflow/service/workflow/job/job_blueking.go | 4 ++++ .../core/workflow/service/workflow/job/job_build.go | 11 +++++++++++ .../service/workflow/job/job_canary_deploy.go | 11 +++++++++++ .../service/workflow/job/job_canary_release.go | 4 ++++ .../service/workflow/job/job_custom_deploy.go | 11 +++++++++++ .../core/workflow/service/workflow/job/job_deploy.go | 11 +++++++++++ .../service/workflow/job/job_distribute_image.go | 11 +++++++++++ .../workflow/service/workflow/job/job_freestyle.go | 4 ++++ .../core/workflow/service/workflow/job/job_grafana.go | 4 ++++ .../workflow/service/workflow/job/job_gray_release.go | 11 +++++++++++ .../service/workflow/job/job_gray_rollback.go | 11 +++++++++++ .../workflow/service/workflow/job/job_guanceyun.go | 4 ++++ .../service/workflow/job/job_helm_chart_deploy.go | 11 +++++++++++ .../service/workflow/job/job_istio_release.go | 11 +++++++++++ .../service/workflow/job/job_istio_rollback.go | 11 +++++++++++ .../core/workflow/service/workflow/job/job_jenkins.go | 4 ++++ .../core/workflow/service/workflow/job/job_jira.go | 4 ++++ .../workflow/service/workflow/job/job_k8s_patch.go | 11 +++++++++++ .../service/workflow/job/job_meego_transition.go | 4 ++++ .../service/workflow/job/job_mse_gray_offline.go | 4 ++++ .../service/workflow/job/job_mse_gray_release.go | 4 ++++ .../core/workflow/service/workflow/job/job_nacos.go | 4 ++++ .../service/workflow/job/job_offline_service.go | 4 ++++ .../core/workflow/service/workflow/job/job_plugin.go | 4 ++++ .../workflow/service/workflow/job/job_scanning.go | 4 ++++ .../core/workflow/service/workflow/job/job_sql.go | 4 ++++ .../core/workflow/service/workflow/job/job_testing.go | 4 ++++ .../workflow/job/job_update_env_istio_config.go | 4 ++++ .../workflow/service/workflow/job/job_vm_deploy.go | 11 +++++++++++ .../service/workflow/job/job_workflow_trigger.go | 4 ++++ .../workflow/service/workflow/workflow_task_v4.go | 10 ++++++++++ 35 files changed, 250 insertions(+) diff --git a/pkg/microservice/aslan/core/workflow/service/workflow/job/job.go b/pkg/microservice/aslan/core/workflow/service/workflow/job/job.go index 59601af7b5..7d0ae9c654 100644 --- a/pkg/microservice/aslan/core/workflow/service/workflow/job/job.go +++ b/pkg/microservice/aslan/core/workflow/service/workflow/job/job.go @@ -53,6 +53,8 @@ type JobCtl interface { SetPreset() error // SetOptions sets all the possible options for the workflow SetOptions() error + // ClearOptions clears the option field to save space for db and memory + ClearOptions() error ClearSelectionField() error ToJobs(taskID int64) ([]*commonmodels.JobTask, error) // MergeArgs merge the current workflow with the user input: args @@ -182,6 +184,14 @@ func SetOptions(job *commonmodels.Job, workflow *commonmodels.WorkflowV4) error return jobCtl.SetOptions() } +func ClearOptions(job *commonmodels.Job, workflow *commonmodels.WorkflowV4) error { + jobCtl, err := InitJobCtl(job, workflow) + if err != nil { + return warpJobError(job.Name, err) + } + return jobCtl.ClearOptions() +} + func UpdateWithLatestSetting(job *commonmodels.Job, workflow *commonmodels.WorkflowV4) error { jobCtl, err := InitJobCtl(job, workflow) if err != nil { diff --git a/pkg/microservice/aslan/core/workflow/service/workflow/job/job_apollo.go b/pkg/microservice/aslan/core/workflow/service/workflow/job/job_apollo.go index e512b88e9e..8a4ffc65cb 100644 --- a/pkg/microservice/aslan/core/workflow/service/workflow/job/job_apollo.go +++ b/pkg/microservice/aslan/core/workflow/service/workflow/job/job_apollo.go @@ -125,6 +125,17 @@ func (j *ApolloJob) SetOptions() error { return nil } +func (j *ApolloJob) ClearOptions() error { + j.spec = &commonmodels.ApolloJobSpec{} + if err := commonmodels.IToi(j.job.Spec, j.spec); err != nil { + return err + } + + j.spec.NamespaceListOption = nil + j.job.Spec = j.spec + return nil +} + func (j *ApolloJob) ClearSelectionField() error { j.spec = &commonmodels.ApolloJobSpec{} if err := commonmodels.IToi(j.job.Spec, j.spec); err != nil { diff --git a/pkg/microservice/aslan/core/workflow/service/workflow/job/job_blue_green_deploy_v2.go b/pkg/microservice/aslan/core/workflow/service/workflow/job/job_blue_green_deploy_v2.go index 508d095c01..4259c7ddae 100644 --- a/pkg/microservice/aslan/core/workflow/service/workflow/job/job_blue_green_deploy_v2.go +++ b/pkg/microservice/aslan/core/workflow/service/workflow/job/job_blue_green_deploy_v2.go @@ -168,6 +168,17 @@ func (j *BlueGreenDeployV2Job) SetOptions() error { return nil } +func (j *BlueGreenDeployV2Job) ClearOptions() error { + j.spec = &commonmodels.BlueGreenDeployV2JobSpec{} + if err := commonmodels.IToi(j.job.Spec, j.spec); err != nil { + return err + } + + j.spec.EnvOptions = nil + j.job.Spec = j.spec + return nil +} + func (j *BlueGreenDeployV2Job) ClearSelectionField() error { j.spec = &commonmodels.BlueGreenDeployV2JobSpec{} if err := commonmodels.IToi(j.job.Spec, j.spec); err != nil { diff --git a/pkg/microservice/aslan/core/workflow/service/workflow/job/job_blue_green_release_v2.go b/pkg/microservice/aslan/core/workflow/service/workflow/job/job_blue_green_release_v2.go index 3bd2c1102d..d2396c9115 100644 --- a/pkg/microservice/aslan/core/workflow/service/workflow/job/job_blue_green_release_v2.go +++ b/pkg/microservice/aslan/core/workflow/service/workflow/job/job_blue_green_release_v2.go @@ -55,6 +55,10 @@ func (j *BlueGreenReleaseV2Job) SetOptions() error { return nil } +func (j *BlueGreenReleaseV2Job) ClearOptions() error { + return nil +} + func (j *BlueGreenReleaseV2Job) ClearSelectionField() error { return nil } diff --git a/pkg/microservice/aslan/core/workflow/service/workflow/job/job_blueking.go b/pkg/microservice/aslan/core/workflow/service/workflow/job/job_blueking.go index 247ccb673d..a5c0c5e29e 100644 --- a/pkg/microservice/aslan/core/workflow/service/workflow/job/job_blueking.go +++ b/pkg/microservice/aslan/core/workflow/service/workflow/job/job_blueking.go @@ -54,6 +54,10 @@ func (j *BlueKingJob) SetOptions() error { return nil } +func (j *BlueKingJob) ClearOptions() error { + return nil +} + func (j *BlueKingJob) ClearSelectionField() error { j.spec = &commonmodels.BlueKingJobSpec{} if err := commonmodels.IToi(j.job.Spec, j.spec); err != nil { diff --git a/pkg/microservice/aslan/core/workflow/service/workflow/job/job_build.go b/pkg/microservice/aslan/core/workflow/service/workflow/job/job_build.go index b9b1a96998..53832c1a9a 100644 --- a/pkg/microservice/aslan/core/workflow/service/workflow/job/job_build.go +++ b/pkg/microservice/aslan/core/workflow/service/workflow/job/job_build.go @@ -237,6 +237,17 @@ func (j *BuildJob) SetOptions() error { return nil } +func (j *BuildJob) ClearOptions() error { + j.spec = &commonmodels.ZadigBuildJobSpec{} + if err := commonmodels.IToi(j.job.Spec, j.spec); err != nil { + return err + } + + j.spec.ServiceAndBuildsOptions = nil + j.job.Spec = j.spec + return nil +} + func (j *BuildJob) GetRepos() ([]*types.Repository, error) { resp := []*types.Repository{} j.spec = &commonmodels.ZadigBuildJobSpec{} diff --git a/pkg/microservice/aslan/core/workflow/service/workflow/job/job_canary_deploy.go b/pkg/microservice/aslan/core/workflow/service/workflow/job/job_canary_deploy.go index bc230f8968..82c64bae13 100644 --- a/pkg/microservice/aslan/core/workflow/service/workflow/job/job_canary_deploy.go +++ b/pkg/microservice/aslan/core/workflow/service/workflow/job/job_canary_deploy.go @@ -98,6 +98,17 @@ func (j *CanaryDeployJob) SetOptions() error { return nil } +func (j *CanaryDeployJob) ClearOptions() error { + j.spec = &commonmodels.CanaryDeployJobSpec{} + if err := commonmodels.IToi(j.job.Spec, j.spec); err != nil { + return err + } + + j.spec.TargetOptions = nil + j.job.Spec = j.spec + return nil +} + func (j *CanaryDeployJob) ClearSelectionField() error { j.spec = &commonmodels.CanaryDeployJobSpec{} if err := commonmodels.IToi(j.job.Spec, j.spec); err != nil { diff --git a/pkg/microservice/aslan/core/workflow/service/workflow/job/job_canary_release.go b/pkg/microservice/aslan/core/workflow/service/workflow/job/job_canary_release.go index e90c2ac746..e812eafaa6 100644 --- a/pkg/microservice/aslan/core/workflow/service/workflow/job/job_canary_release.go +++ b/pkg/microservice/aslan/core/workflow/service/workflow/job/job_canary_release.go @@ -54,6 +54,10 @@ func (j *CanaryReleaseJob) SetOptions() error { return nil } +func (j *CanaryReleaseJob) ClearOptions() error { + return nil +} + func (j *CanaryReleaseJob) ClearSelectionField() error { return nil } diff --git a/pkg/microservice/aslan/core/workflow/service/workflow/job/job_custom_deploy.go b/pkg/microservice/aslan/core/workflow/service/workflow/job/job_custom_deploy.go index 33fe096fe9..b18436ea1a 100644 --- a/pkg/microservice/aslan/core/workflow/service/workflow/job/job_custom_deploy.go +++ b/pkg/microservice/aslan/core/workflow/service/workflow/job/job_custom_deploy.go @@ -89,6 +89,17 @@ func (j *CustomDeployJob) SetOptions() error { return nil } +func (j *CustomDeployJob) ClearOptions() error { + j.spec = &commonmodels.CustomDeployJobSpec{} + if err := commonmodels.IToi(j.job.Spec, j.spec); err != nil { + return err + } + + j.spec.TargetOptions = nil + j.job.Spec = j.spec + return nil +} + func (j *CustomDeployJob) ClearSelectionField() error { j.spec = &commonmodels.CustomDeployJobSpec{} if err := commonmodels.IToi(j.job.Spec, j.spec); err != nil { diff --git a/pkg/microservice/aslan/core/workflow/service/workflow/job/job_deploy.go b/pkg/microservice/aslan/core/workflow/service/workflow/job/job_deploy.go index 5fbb300515..688aa67fc3 100644 --- a/pkg/microservice/aslan/core/workflow/service/workflow/job/job_deploy.go +++ b/pkg/microservice/aslan/core/workflow/service/workflow/job/job_deploy.go @@ -379,6 +379,17 @@ func (j *DeployJob) SetOptions() error { return nil } +func (j *DeployJob) ClearOptions() error { + j.spec = &commonmodels.ZadigDeployJobSpec{} + if err := commonmodels.IToi(j.job.Spec, j.spec); err != nil { + return err + } + + j.spec.EnvOptions = nil + j.job.Spec = j.spec + return nil +} + func (j *DeployJob) ClearSelectionField() error { j.spec = &commonmodels.ZadigDeployJobSpec{} if err := commonmodels.IToi(j.job.Spec, j.spec); err != nil { diff --git a/pkg/microservice/aslan/core/workflow/service/workflow/job/job_distribute_image.go b/pkg/microservice/aslan/core/workflow/service/workflow/job/job_distribute_image.go index f005d51b4a..09cb0a7b82 100644 --- a/pkg/microservice/aslan/core/workflow/service/workflow/job/job_distribute_image.go +++ b/pkg/microservice/aslan/core/workflow/service/workflow/job/job_distribute_image.go @@ -133,6 +133,17 @@ func (j *ImageDistributeJob) SetOptions() error { return nil } +func (j *ImageDistributeJob) ClearOptions() error { + j.spec = &commonmodels.ZadigDistributeImageJobSpec{} + if err := commonmodels.IToi(j.job.Spec, j.spec); err != nil { + return err + } + + j.spec.TargetOptions = nil + j.job.Spec = j.spec + return nil +} + func (j *ImageDistributeJob) ClearSelectionField() error { j.spec = &commonmodels.ZadigDistributeImageJobSpec{} if err := commonmodels.IToi(j.job.Spec, j.spec); err != nil { diff --git a/pkg/microservice/aslan/core/workflow/service/workflow/job/job_freestyle.go b/pkg/microservice/aslan/core/workflow/service/workflow/job/job_freestyle.go index 70b55aaae2..ecb8355f21 100644 --- a/pkg/microservice/aslan/core/workflow/service/workflow/job/job_freestyle.go +++ b/pkg/microservice/aslan/core/workflow/service/workflow/job/job_freestyle.go @@ -110,6 +110,10 @@ func (j *FreeStyleJob) SetOptions() error { return nil } +func (j *FreeStyleJob) ClearOptions() error { + return nil +} + func (j *FreeStyleJob) ClearSelectionField() error { j.spec = &commonmodels.FreestyleJobSpec{} if err := commonmodels.IToi(j.job.Spec, j.spec); err != nil { diff --git a/pkg/microservice/aslan/core/workflow/service/workflow/job/job_grafana.go b/pkg/microservice/aslan/core/workflow/service/workflow/job/job_grafana.go index 5a0f3b9510..fa596454b0 100644 --- a/pkg/microservice/aslan/core/workflow/service/workflow/job/job_grafana.go +++ b/pkg/microservice/aslan/core/workflow/service/workflow/job/job_grafana.go @@ -57,6 +57,10 @@ func (j *GrafanaJob) SetOptions() error { return nil } +func (j *GrafanaJob) ClearOptions() error { + return nil +} + func (j *GrafanaJob) ClearSelectionField() error { return nil } diff --git a/pkg/microservice/aslan/core/workflow/service/workflow/job/job_gray_release.go b/pkg/microservice/aslan/core/workflow/service/workflow/job/job_gray_release.go index 53dca8a2c4..5cd6576f3a 100644 --- a/pkg/microservice/aslan/core/workflow/service/workflow/job/job_gray_release.go +++ b/pkg/microservice/aslan/core/workflow/service/workflow/job/job_gray_release.go @@ -90,6 +90,17 @@ func (j *GrayReleaseJob) SetOptions() error { return nil } +func (j *GrayReleaseJob) ClearOptions() error { + j.spec = &commonmodels.GrayReleaseJobSpec{} + if err := commonmodels.IToi(j.job.Spec, j.spec); err != nil { + return err + } + + j.spec.TargetOptions = nil + j.job.Spec = j.spec + return nil +} + func (j *GrayReleaseJob) ClearSelectionField() error { j.spec = &commonmodels.GrayReleaseJobSpec{} if err := commonmodels.IToiYaml(j.job.Spec, j.spec); err != nil { diff --git a/pkg/microservice/aslan/core/workflow/service/workflow/job/job_gray_rollback.go b/pkg/microservice/aslan/core/workflow/service/workflow/job/job_gray_rollback.go index 847b26f937..e5055b915b 100644 --- a/pkg/microservice/aslan/core/workflow/service/workflow/job/job_gray_rollback.go +++ b/pkg/microservice/aslan/core/workflow/service/workflow/job/job_gray_rollback.go @@ -132,6 +132,17 @@ func (j *GrayRollbackJob) SetOptions() error { return nil } +func (j *GrayRollbackJob) ClearOptions() error { + j.spec = &commonmodels.GrayRollbackJobSpec{} + if err := commonmodels.IToi(j.job.Spec, j.spec); err != nil { + return err + } + + j.spec.Targets = make([]*commonmodels.GrayRollbackTarget, 0) + j.job.Spec = j.spec + return nil +} + func (j *GrayRollbackJob) ClearSelectionField() error { j.spec = &commonmodels.GrayRollbackJobSpec{} if err := commonmodels.IToi(j.job.Spec, j.spec); err != nil { diff --git a/pkg/microservice/aslan/core/workflow/service/workflow/job/job_guanceyun.go b/pkg/microservice/aslan/core/workflow/service/workflow/job/job_guanceyun.go index 176c4d3275..e57923dabe 100644 --- a/pkg/microservice/aslan/core/workflow/service/workflow/job/job_guanceyun.go +++ b/pkg/microservice/aslan/core/workflow/service/workflow/job/job_guanceyun.go @@ -54,6 +54,10 @@ func (j *GuanceyunCheckJob) SetOptions() error { return nil } +func (j *GuanceyunCheckJob) ClearOptions() error { + return nil +} + func (j *GuanceyunCheckJob) ClearSelectionField() error { return nil } diff --git a/pkg/microservice/aslan/core/workflow/service/workflow/job/job_helm_chart_deploy.go b/pkg/microservice/aslan/core/workflow/service/workflow/job/job_helm_chart_deploy.go index f5abe7a1df..a5ba52a65e 100644 --- a/pkg/microservice/aslan/core/workflow/service/workflow/job/job_helm_chart_deploy.go +++ b/pkg/microservice/aslan/core/workflow/service/workflow/job/job_helm_chart_deploy.go @@ -149,6 +149,17 @@ func (j *HelmChartDeployJob) SetOptions() error { return nil } +func (j *HelmChartDeployJob) ClearOptions() error { + j.spec = &commonmodels.ZadigHelmChartDeployJobSpec{} + if err := commonmodels.IToi(j.job.Spec, j.spec); err != nil { + return err + } + + j.spec.EnvOptions = nil + j.job.Spec = j.spec + return nil +} + func (j *HelmChartDeployJob) ClearSelectionField() error { j.spec = &commonmodels.ZadigHelmChartDeployJobSpec{} if err := commonmodels.IToi(j.job.Spec, j.spec); err != nil { diff --git a/pkg/microservice/aslan/core/workflow/service/workflow/job/job_istio_release.go b/pkg/microservice/aslan/core/workflow/service/workflow/job/job_istio_release.go index 276d964ad9..a53f2fc5c9 100644 --- a/pkg/microservice/aslan/core/workflow/service/workflow/job/job_istio_release.go +++ b/pkg/microservice/aslan/core/workflow/service/workflow/job/job_istio_release.go @@ -90,6 +90,17 @@ func (j *IstioReleaseJob) SetOptions() error { return nil } +func (j *IstioReleaseJob) ClearOptions() error { + j.spec = &commonmodels.IstioJobSpec{} + if err := commonmodels.IToi(j.job.Spec, j.spec); err != nil { + return err + } + + j.spec.TargetOptions = nil + j.job.Spec = j.spec + return nil +} + func (j *IstioReleaseJob) ClearSelectionField() error { j.spec = &commonmodels.IstioJobSpec{} if err := commonmodels.IToi(j.job.Spec, j.spec); err != nil { diff --git a/pkg/microservice/aslan/core/workflow/service/workflow/job/job_istio_rollback.go b/pkg/microservice/aslan/core/workflow/service/workflow/job/job_istio_rollback.go index 18f18800a9..f2e0428633 100644 --- a/pkg/microservice/aslan/core/workflow/service/workflow/job/job_istio_rollback.go +++ b/pkg/microservice/aslan/core/workflow/service/workflow/job/job_istio_rollback.go @@ -135,6 +135,17 @@ func (j *IstioRollBackJob) SetOptions() error { return nil } +func (j *IstioRollBackJob) ClearOptions() error { + j.spec = &commonmodels.IstioRollBackJobSpec{} + if err := commonmodels.IToi(j.job.Spec, j.spec); err != nil { + return err + } + + j.spec.TargetOptions = nil + j.job.Spec = j.spec + return nil +} + func (j *IstioRollBackJob) ClearSelectionField() error { j.spec = &commonmodels.IstioRollBackJobSpec{} if err := commonmodels.IToi(j.job.Spec, j.spec); err != nil { diff --git a/pkg/microservice/aslan/core/workflow/service/workflow/job/job_jenkins.go b/pkg/microservice/aslan/core/workflow/service/workflow/job/job_jenkins.go index 2b90d89a7f..d42b977f99 100644 --- a/pkg/microservice/aslan/core/workflow/service/workflow/job/job_jenkins.go +++ b/pkg/microservice/aslan/core/workflow/service/workflow/job/job_jenkins.go @@ -103,6 +103,10 @@ func (j *JenkinsJob) SetOptions() error { return nil } +func (j *JenkinsJob) ClearOptions() error { + return nil +} + func (j *JenkinsJob) ClearSelectionField() error { return nil } diff --git a/pkg/microservice/aslan/core/workflow/service/workflow/job/job_jira.go b/pkg/microservice/aslan/core/workflow/service/workflow/job/job_jira.go index bdd0f1a15b..23e726bf5d 100644 --- a/pkg/microservice/aslan/core/workflow/service/workflow/job/job_jira.go +++ b/pkg/microservice/aslan/core/workflow/service/workflow/job/job_jira.go @@ -57,6 +57,10 @@ func (j *JiraJob) SetOptions() error { return nil } +func (j *JiraJob) ClearOptions() error { + return nil +} + func (j *JiraJob) ClearSelectionField() error { return nil } diff --git a/pkg/microservice/aslan/core/workflow/service/workflow/job/job_k8s_patch.go b/pkg/microservice/aslan/core/workflow/service/workflow/job/job_k8s_patch.go index 43dcbc3af3..ca06f8bb41 100644 --- a/pkg/microservice/aslan/core/workflow/service/workflow/job/job_k8s_patch.go +++ b/pkg/microservice/aslan/core/workflow/service/workflow/job/job_k8s_patch.go @@ -90,6 +90,17 @@ func (j *K8sPacthJob) SetOptions() error { return nil } +func (j *K8sPacthJob) ClearOptions() error { + j.spec = &commonmodels.K8sPatchJobSpec{} + if err := commonmodels.IToi(j.job.Spec, j.spec); err != nil { + return err + } + + j.spec.PatchItemOptions = nil + j.job.Spec = j.spec + return nil +} + func (j *K8sPacthJob) ClearSelectionField() error { j.spec = &commonmodels.K8sPatchJobSpec{} if err := commonmodels.IToi(j.job.Spec, j.spec); err != nil { diff --git a/pkg/microservice/aslan/core/workflow/service/workflow/job/job_meego_transition.go b/pkg/microservice/aslan/core/workflow/service/workflow/job/job_meego_transition.go index 14df28370f..c41abff3d5 100644 --- a/pkg/microservice/aslan/core/workflow/service/workflow/job/job_meego_transition.go +++ b/pkg/microservice/aslan/core/workflow/service/workflow/job/job_meego_transition.go @@ -55,6 +55,10 @@ func (j *MeegoTransitionJob) SetOptions() error { return nil } +func (j *MeegoTransitionJob) ClearOptions() error { + return nil +} + func (j *MeegoTransitionJob) ClearSelectionField() error { return nil } diff --git a/pkg/microservice/aslan/core/workflow/service/workflow/job/job_mse_gray_offline.go b/pkg/microservice/aslan/core/workflow/service/workflow/job/job_mse_gray_offline.go index 54322a5517..6bf5e7b0fa 100644 --- a/pkg/microservice/aslan/core/workflow/service/workflow/job/job_mse_gray_offline.go +++ b/pkg/microservice/aslan/core/workflow/service/workflow/job/job_mse_gray_offline.go @@ -55,6 +55,10 @@ func (j *MseGrayOfflineJob) SetOptions() error { return nil } +func (j *MseGrayOfflineJob) ClearOptions() error { + return nil +} + func (j *MseGrayOfflineJob) ClearSelectionField() error { return nil } diff --git a/pkg/microservice/aslan/core/workflow/service/workflow/job/job_mse_gray_release.go b/pkg/microservice/aslan/core/workflow/service/workflow/job/job_mse_gray_release.go index 6dd6c244b8..17ac1bf1af 100644 --- a/pkg/microservice/aslan/core/workflow/service/workflow/job/job_mse_gray_release.go +++ b/pkg/microservice/aslan/core/workflow/service/workflow/job/job_mse_gray_release.go @@ -66,6 +66,10 @@ func (j *MseGrayReleaseJob) SetOptions() error { return nil } +func (j *MseGrayReleaseJob) ClearOptions() error { + return nil +} + func (j *MseGrayReleaseJob) ClearSelectionField() error { return nil } diff --git a/pkg/microservice/aslan/core/workflow/service/workflow/job/job_nacos.go b/pkg/microservice/aslan/core/workflow/service/workflow/job/job_nacos.go index c113496daf..37dfc647ea 100644 --- a/pkg/microservice/aslan/core/workflow/service/workflow/job/job_nacos.go +++ b/pkg/microservice/aslan/core/workflow/service/workflow/job/job_nacos.go @@ -123,6 +123,10 @@ func (j *NacosJob) SetOptions() error { return nil } +func (j *NacosJob) ClearOptions() error { + return nil +} + func (j *NacosJob) ClearSelectionField() error { return nil } diff --git a/pkg/microservice/aslan/core/workflow/service/workflow/job/job_offline_service.go b/pkg/microservice/aslan/core/workflow/service/workflow/job/job_offline_service.go index 0db2d9181c..2b361f6767 100644 --- a/pkg/microservice/aslan/core/workflow/service/workflow/job/job_offline_service.go +++ b/pkg/microservice/aslan/core/workflow/service/workflow/job/job_offline_service.go @@ -56,6 +56,10 @@ func (j *OfflineServiceJob) SetOptions() error { return nil } +func (j *OfflineServiceJob) ClearOptions() error { + return nil +} + func (j *OfflineServiceJob) ClearSelectionField() error { return nil } diff --git a/pkg/microservice/aslan/core/workflow/service/workflow/job/job_plugin.go b/pkg/microservice/aslan/core/workflow/service/workflow/job/job_plugin.go index 6b225a47c9..b94a5a37e6 100644 --- a/pkg/microservice/aslan/core/workflow/service/workflow/job/job_plugin.go +++ b/pkg/microservice/aslan/core/workflow/service/workflow/job/job_plugin.go @@ -56,6 +56,10 @@ func (j *PluginJob) SetOptions() error { return nil } +func (j *PluginJob) ClearOptions() error { + return nil +} + func (j *PluginJob) ClearSelectionField() error { return nil } diff --git a/pkg/microservice/aslan/core/workflow/service/workflow/job/job_scanning.go b/pkg/microservice/aslan/core/workflow/service/workflow/job/job_scanning.go index dc3eca7fc7..2c2c7b445e 100644 --- a/pkg/microservice/aslan/core/workflow/service/workflow/job/job_scanning.go +++ b/pkg/microservice/aslan/core/workflow/service/workflow/job/job_scanning.go @@ -77,6 +77,10 @@ func (j *ScanningJob) SetOptions() error { return nil } +func (j *ScanningJob) ClearOptions() error { + return nil +} + func (j *ScanningJob) ClearSelectionField() error { return nil } diff --git a/pkg/microservice/aslan/core/workflow/service/workflow/job/job_sql.go b/pkg/microservice/aslan/core/workflow/service/workflow/job/job_sql.go index d81dde8e03..b32c96d99a 100644 --- a/pkg/microservice/aslan/core/workflow/service/workflow/job/job_sql.go +++ b/pkg/microservice/aslan/core/workflow/service/workflow/job/job_sql.go @@ -55,6 +55,10 @@ func (j *SQLJob) SetOptions() error { return nil } +func (j *SQLJob) ClearOptions() error { + return nil +} + func (j *SQLJob) ClearSelectionField() error { return nil } diff --git a/pkg/microservice/aslan/core/workflow/service/workflow/job/job_testing.go b/pkg/microservice/aslan/core/workflow/service/workflow/job/job_testing.go index 51db02a1d6..29fe36a5a3 100644 --- a/pkg/microservice/aslan/core/workflow/service/workflow/job/job_testing.go +++ b/pkg/microservice/aslan/core/workflow/service/workflow/job/job_testing.go @@ -104,6 +104,10 @@ func (j *TestingJob) SetOptions() error { return nil } +func (j *TestingJob) ClearOptions() error { + return nil +} + func (j *TestingJob) ClearSelectionField() error { j.spec = &commonmodels.ZadigTestingJobSpec{} if err := commonmodels.IToiYaml(j.job.Spec, j.spec); err != nil { diff --git a/pkg/microservice/aslan/core/workflow/service/workflow/job/job_update_env_istio_config.go b/pkg/microservice/aslan/core/workflow/service/workflow/job/job_update_env_istio_config.go index e585a0db0d..f55ec25d31 100644 --- a/pkg/microservice/aslan/core/workflow/service/workflow/job/job_update_env_istio_config.go +++ b/pkg/microservice/aslan/core/workflow/service/workflow/job/job_update_env_istio_config.go @@ -49,6 +49,10 @@ func (j *UpdateEnvIstioConfigJob) SetOptions() error { return nil } +func (j *UpdateEnvIstioConfigJob) ClearOptions() error { + return nil +} + func (j *UpdateEnvIstioConfigJob) ClearSelectionField() error { return nil } diff --git a/pkg/microservice/aslan/core/workflow/service/workflow/job/job_vm_deploy.go b/pkg/microservice/aslan/core/workflow/service/workflow/job/job_vm_deploy.go index ac1f26e4f3..b2e172a342 100644 --- a/pkg/microservice/aslan/core/workflow/service/workflow/job/job_vm_deploy.go +++ b/pkg/microservice/aslan/core/workflow/service/workflow/job/job_vm_deploy.go @@ -145,6 +145,17 @@ func (j *VMDeployJob) SetOptions() error { return nil } +func (j *VMDeployJob) ClearOptions() error { + j.spec = &commonmodels.ZadigVMDeployJobSpec{} + if err := commonmodels.IToi(j.job.Spec, j.spec); err != nil { + return err + } + + j.spec.EnvOptions = nil + j.job.Spec = j.spec + return nil +} + func (j *VMDeployJob) ClearSelectionField() error { j.spec = &commonmodels.ZadigVMDeployJobSpec{} if err := commonmodels.IToi(j.job.Spec, j.spec); err != nil { diff --git a/pkg/microservice/aslan/core/workflow/service/workflow/job/job_workflow_trigger.go b/pkg/microservice/aslan/core/workflow/service/workflow/job/job_workflow_trigger.go index 0d5b3f48bd..35f3ad576a 100644 --- a/pkg/microservice/aslan/core/workflow/service/workflow/job/job_workflow_trigger.go +++ b/pkg/microservice/aslan/core/workflow/service/workflow/job/job_workflow_trigger.go @@ -95,6 +95,10 @@ func (j *WorkflowTriggerJob) SetOptions() error { return nil } +func (j *WorkflowTriggerJob) ClearOptions() error { + return nil +} + func (j *WorkflowTriggerJob) ClearSelectionField() error { j.spec = &commonmodels.WorkflowTriggerJobSpec{} if err := commonmodels.IToi(j.job.Spec, j.spec); err != nil { diff --git a/pkg/microservice/aslan/core/workflow/service/workflow/workflow_task_v4.go b/pkg/microservice/aslan/core/workflow/service/workflow/workflow_task_v4.go index 3193061863..91bb802b27 100644 --- a/pkg/microservice/aslan/core/workflow/service/workflow/workflow_task_v4.go +++ b/pkg/microservice/aslan/core/workflow/service/workflow/workflow_task_v4.go @@ -399,6 +399,16 @@ func CreateWorkflowTaskV4(args *CreateWorkflowTaskV4Args, workflow *commonmodels workflowTask.TaskCreatorPhone = userInfo.Phone } + for _, stage := range workflow.Stages { + for _, job := range stage.Jobs { + err := jobctl.ClearOptions(job, workflow) + if err != nil { + log.Errorf("failed to remove the job options in the workflow parameters for job %s, stage: %s, error: %s", job.Name, stage.Name, err) + return resp, fmt.Errorf("failed to remove the job options in the workflow parameters for job %s, stage: %s, error: %s", job.Name, stage.Name, err) + } + } + } + // save workflow original workflow task args. originTaskArgs := &commonmodels.WorkflowV4{} if err := commonmodels.IToi(workflow, originTaskArgs); err != nil { From 1470f124216e181596629d92bc2a5b0dedd05307 Mon Sep 17 00:00:00 2001 From: Min Min Date: Thu, 29 Aug 2024 18:14:10 +0800 Subject: [PATCH 2/2] add ua for zeekr Signed-off-by: Min Min --- pkg/cli/upgradeassistant/cmd/migrate/300.go | 120 ++++++++++++++++++++ 1 file changed, 120 insertions(+) create mode 100644 pkg/cli/upgradeassistant/cmd/migrate/300.go diff --git a/pkg/cli/upgradeassistant/cmd/migrate/300.go b/pkg/cli/upgradeassistant/cmd/migrate/300.go new file mode 100644 index 0000000000..222bc29432 --- /dev/null +++ b/pkg/cli/upgradeassistant/cmd/migrate/300.go @@ -0,0 +1,120 @@ +/* +Copyright 2023 The KodeRover Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package migrate + +import ( + "fmt" + "runtime" + + "github.com/koderover/zadig/v2/pkg/cli/upgradeassistant/internal/upgradepath" + commonmodels "github.com/koderover/zadig/v2/pkg/microservice/aslan/core/common/repository/models" + "github.com/koderover/zadig/v2/pkg/microservice/aslan/core/common/repository/mongodb" + templaterepo "github.com/koderover/zadig/v2/pkg/microservice/aslan/core/common/repository/mongodb/template" + jobctl "github.com/koderover/zadig/v2/pkg/microservice/aslan/core/workflow/service/workflow/job" + "github.com/koderover/zadig/v2/pkg/tool/log" + "go.mongodb.org/mongo-driver/mongo" +) + +func init() { + upgradepath.RegisterHandler("2.3.0", "3.0.0", V230ToV300) + upgradepath.RegisterHandler("3.0.0", "2.3.0", V230ToV220) +} + +func V230ToV300() error { + log.Infof("-------- start migrate workflow task data --------") + err := removeWorkflowTaskExtraData() + if err != nil { + log.Errorf("migrate workflow task data error: %s", err) + return err + } + + return nil +} + +func V300ToV230() error { + return nil +} + +// remove 100 of the workflow task's extra option field to make data clean +func removeWorkflowTaskExtraData() error { + // find all projects to do the migration + projects, err := templaterepo.NewProductColl().List() + if err != nil { + log.Errorf("failed to list project list to do workflow migrations, error: %s", err) + return fmt.Errorf("failed to list project list to do workflow migrations") + } + + for _, project := range projects { + // list all workflows + workflows, _, err := mongodb.NewWorkflowV4Coll().List(&mongodb.ListWorkflowV4Option{ + ProjectName: project.ProductName, + }, 0, 0) + + if err != nil { + log.Errorf("failed to list workflow for project: %s, error: %s", project.ProductName, err) + return fmt.Errorf("failed to list workflow for project: %s, error: %s", project.ProductName, err) + } + + for _, workflow := range workflows { + // list first 100 task to remove all unnecessary fields + tasks, _, err := mongodb.NewworkflowTaskv4Coll().List(&mongodb.ListWorkflowTaskV4Option{ + WorkflowName: "", + ProjectName: "", + Limit: 100, + Skip: 0, + }) + + if err != nil && (err != mongo.ErrNilDocument && err != mongo.ErrNoDocuments) { + log.Errorf("failed to list workflow task for project: %s, workflowName: %s, error: %s", project.ProductName, workflow.Name, err) + return fmt.Errorf("failed to list workflow task for project: %s, workflowName: %s, error: %s", project.ProductName, workflow.Name, err) + } + + if tasks != nil && len(tasks) != 0 { + for _, task := range tasks { + err := cleanTask(task, workflow) + if err != nil { + log.Errorf("failed to clean the task's data, taskID: %d, workflowName: %s, project: %s, error: %s", task.TaskID, workflow.Name, project.ProductName, err) + return fmt.Errorf("failed to clean the task's data, taskID: %d, workflowName: %s, project: %s, error: %s", task.TaskID, workflow.Name, project.ProductName, err) + } + + err = mongodb.NewworkflowTaskv4Coll().Update(task.ID.Hex(), task) + if err != nil { + log.Errorf("failed to update the task's data, taskID: %d, workflowName: %s, project: %s, error: %s", task.TaskID, workflow.Name, project.ProductName, err) + return fmt.Errorf("failed to update the task's data, taskID: %d, workflowName: %s, project: %s, error: %s", task.TaskID, workflow.Name, project.ProductName, err) + } + } + } + } + + // after a project is done, trigger a manual gc to save memory + runtime.GC() + } + + return nil +} + +func cleanTask(task *commonmodels.WorkflowTask, workflow *commonmodels.WorkflowV4) error { + for _, stage := range task.OriginWorkflowArgs.Stages { + for _, job := range stage.Jobs { + err := jobctl.ClearOptions(job, workflow) + if err != nil { + return err + } + } + } + return nil +}