From 10515e7342884b4d3ab144a6282e4c1bff38f31c Mon Sep 17 00:00:00 2001 From: Cynthia Date: Thu, 2 Jul 2026 11:00:27 +0800 Subject: [PATCH 1/5] fix(workflow): avoid helm auto sync panic for undeployed services Signed-off-by: Cynthia --- .../jobcontroller/job_helm_deploy.go | 21 ++++++++++++++++ .../workflow/controller/job/job_deploy.go | 25 +++++++++++-------- 2 files changed, 36 insertions(+), 10 deletions(-) diff --git a/pkg/microservice/aslan/core/common/service/workflowcontroller/jobcontroller/job_helm_deploy.go b/pkg/microservice/aslan/core/common/service/workflowcontroller/jobcontroller/job_helm_deploy.go index 0e595974e8..519df159f4 100644 --- a/pkg/microservice/aslan/core/common/service/workflowcontroller/jobcontroller/job_helm_deploy.go +++ b/pkg/microservice/aslan/core/common/service/workflowcontroller/jobcontroller/job_helm_deploy.go @@ -150,6 +150,9 @@ func (c *HelmDeployJobCtl) Run(ctx context.Context) { } newEnvService.DeployStrategy = setting.ServiceDeployStrategyDeploy productInfo.ServiceDeployStrategy[c.jobTaskSpec.ServiceName] = setting.ServiceDeployStrategyDeploy + if currentEnvSvc == nil { + fillHelmValuesSource(newEnvService, latestTmplSvc) + } // calc final values yaml finalValuesYaml := "" @@ -346,6 +349,24 @@ func (c *HelmDeployJobCtl) Run(ctx context.Context) { c.job.Status = config.StatusPassed } +func fillHelmValuesSource(envSvc *commonmodels.ProductService, tmplSvc *commonmodels.Service) { + if envSvc == nil || tmplSvc == nil { + return + } + + createFrom, err := tmplSvc.GetHelmCreateFrom() + if err != nil || createFrom.YamlData == nil { + return + } + + serviceRender := envSvc.GetServiceRender() + serviceRender.OverrideYaml.Source = createFrom.YamlData.Source + serviceRender.OverrideYaml.SourceDetail = createFrom.YamlData.SourceDetail + serviceRender.OverrideYaml.SourceID = createFrom.YamlData.SourceID + serviceRender.OverrideYaml.AutoSync = createFrom.YamlData.AutoSync + serviceRender.OverrideYaml.AutoSyncYaml = createFrom.YamlData.AutoSyncYaml +} + type ManifestStruct struct { Manifest string Unstructured *unstructured.Unstructured diff --git a/pkg/microservice/aslan/core/workflow/service/workflow/controller/job/job_deploy.go b/pkg/microservice/aslan/core/workflow/service/workflow/controller/job/job_deploy.go index b9b0634272..ec0269eb74 100644 --- a/pkg/microservice/aslan/core/workflow/service/workflow/controller/job/job_deploy.go +++ b/pkg/microservice/aslan/core/workflow/service/workflow/controller/job/job_deploy.go @@ -24,6 +24,7 @@ import ( "github.com/koderover/zadig/v2/pkg/microservice/aslan/config" commonmodels "github.com/koderover/zadig/v2/pkg/microservice/aslan/core/common/repository/models" + templatemodels "github.com/koderover/zadig/v2/pkg/microservice/aslan/core/common/repository/models/template" commonrepo "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" commonservice "github.com/koderover/zadig/v2/pkg/microservice/aslan/core/common/service" @@ -639,17 +640,19 @@ func (j DeployJobController) ToTask(taskID int64) ([]*commonmodels.JobTask, erro for jobSubTaskID, svc := range j.jobSpec.Services { var serviceRevision int64 var autoSyncFlag bool + var serviceRender *templatemodels.ServiceRender pSvc, ok := productServiceMap[svc.ServiceName] if ok { serviceRevision = pSvc.Revision + serviceRender = pSvc.GetServiceRender() // if the service is deployed in the env, and the variable is set to auto sync, ignore user input. // sync the values from codehost and set the value merge strategy to override - if pSvc.GetServiceRender().OverrideYaml.AutoSync { + if serviceRender.OverrideYaml.AutoSync { autoSyncFlag = true } if len(j.jobSpec.DeployContents) == 1 && slices.Contains(j.jobSpec.DeployContents, config.DeployImage) && - commonutil.GetChartDeployed(pSvc.GetServiceRender(), product.ServiceDeployStrategy) == setting.ServiceDeployStrategyDraft { + commonutil.GetChartDeployed(serviceRender, product.ServiceDeployStrategy) == setting.ServiceDeployStrategyDraft { return nil, fmt.Errorf("service %s is in draft, cannot deploy image only", svc.ServiceName) } } @@ -698,15 +701,17 @@ func (j DeployJobController) ToTask(taskID int64) ([]*commonmodels.JobTask, erro } if autoSyncFlag || j.jobSpec.ValueSyncStrategy == config.ValueSyncStrategyAuto { - pSvc.GetServiceRender().SetAutoSync(true) - _, values, err := commonservice.SyncYamlFromSource(pSvc.GetServiceRender().OverrideYaml, pSvc.GetServiceRender().OverrideYaml.YamlContent, pSvc.GetServiceRender().OverrideYaml.AutoSyncYaml) - if err != nil { - return nil, fmt.Errorf("failed to sync values for service: %s, error: %s", svc.ServiceName, err) + if serviceRender != nil { + serviceRender.SetAutoSync(true) + _, values, err := commonservice.SyncYamlFromSource(serviceRender.OverrideYaml, serviceRender.OverrideYaml.YamlContent, serviceRender.OverrideYaml.AutoSyncYaml) + if err != nil { + return nil, fmt.Errorf("failed to sync values for service: %s, error: %s", svc.ServiceName, err) + } + serviceRender.SetAutoSync(autoSyncFlag) + jobTaskSpec.UpdateConfig = svc.UpdateConfig + jobTaskSpec.VariableYaml = values + jobTaskSpec.UserSuppliedValue = values } - pSvc.GetServiceRender().SetAutoSync(autoSyncFlag) - jobTaskSpec.UpdateConfig = svc.UpdateConfig - jobTaskSpec.VariableYaml = values - jobTaskSpec.UserSuppliedValue = values } jobTask := &commonmodels.JobTask{ From 76ffcffee1e3d377efba41384194dd0a685da50d Mon Sep 17 00:00:00 2001 From: Cynthia Date: Thu, 2 Jul 2026 11:52:14 +0800 Subject: [PATCH 2/5] fix(workflow): sync values from source for undeployed helm service in auto mode Signed-off-by: Cynthia --- .../repository/models/wokflow_task_v4.go | 1 + .../jobcontroller/job_helm_deploy.go | 5 +++ .../workflow/controller/job/job_deploy.go | 41 +++++++++++++++++++ 3 files changed, 47 insertions(+) diff --git a/pkg/microservice/aslan/core/common/repository/models/wokflow_task_v4.go b/pkg/microservice/aslan/core/common/repository/models/wokflow_task_v4.go index f68200a438..6282f1f75b 100644 --- a/pkg/microservice/aslan/core/common/repository/models/wokflow_task_v4.go +++ b/pkg/microservice/aslan/core/common/repository/models/wokflow_task_v4.go @@ -307,6 +307,7 @@ type JobTaskHelmDeploySpec struct { YamlContent string `bson:"yaml_content" json:"yaml_content" yaml:"yaml_content"` // UserSuppliedValue added since 1.18, the values that users gives. UserSuppliedValue string `bson:"user_supplied_value" json:"user_supplied_value" yaml:"user_supplied_value"` + ValuesSyncedFromSource bool `bson:"values_synced_from_source" json:"values_synced_from_source" yaml:"values_synced_from_source"` UpdateConfig bool `bson:"update_config" json:"update_config" yaml:"update_config"` SkipCheckRunStatus bool `bson:"skip_check_run_status" json:"skip_check_run_status" yaml:"skip_check_run_status"` SkipCheckHelmWorkfloadStatus bool `bson:"skip_check_helm_workload_status" json:"skip_check_helm_workload_status" yaml:"skip_check_helm_workload_status"` diff --git a/pkg/microservice/aslan/core/common/service/workflowcontroller/jobcontroller/job_helm_deploy.go b/pkg/microservice/aslan/core/common/service/workflowcontroller/jobcontroller/job_helm_deploy.go index 519df159f4..b3d734587a 100644 --- a/pkg/microservice/aslan/core/common/service/workflowcontroller/jobcontroller/job_helm_deploy.go +++ b/pkg/microservice/aslan/core/common/service/workflowcontroller/jobcontroller/job_helm_deploy.go @@ -215,6 +215,11 @@ func (c *HelmDeployJobCtl) Run(ctx context.Context) { logError(c.job, msg, c.logger) return } + if currentEnvSvc == nil && c.jobTaskSpec.ValuesSyncedFromSource { + // use the pure source values (before image injection in GenMergedValues) as the + // auto-sync baseline, so that future syncs compare against the unmodified source yaml. + newEnvService.GetServiceRender().SetAutoSyncYaml(c.jobTaskSpec.UserSuppliedValue) + } } newResourceMap, err := genHelmResourceMap(helmDeploySvc, productInfo, newEnvService, latestTmplSvc, helmClient) diff --git a/pkg/microservice/aslan/core/workflow/service/workflow/controller/job/job_deploy.go b/pkg/microservice/aslan/core/workflow/service/workflow/controller/job/job_deploy.go index ec0269eb74..34150dbedf 100644 --- a/pkg/microservice/aslan/core/workflow/service/workflow/controller/job/job_deploy.go +++ b/pkg/microservice/aslan/core/workflow/service/workflow/controller/job/job_deploy.go @@ -711,6 +711,18 @@ func (j DeployJobController) ToTask(taskID int64) ([]*commonmodels.JobTask, erro jobTaskSpec.UpdateConfig = svc.UpdateConfig jobTaskSpec.VariableYaml = values jobTaskSpec.UserSuppliedValue = values + jobTaskSpec.ValuesSyncedFromSource = true + } else { + values, synced, err := syncValuesFromTemplateService(revisionSvc, svc.VariableYaml) + if err != nil { + return nil, fmt.Errorf("failed to sync values for service: %s, error: %s", svc.ServiceName, err) + } + if synced { + jobTaskSpec.UpdateConfig = svc.UpdateConfig + jobTaskSpec.VariableYaml = values + jobTaskSpec.UserSuppliedValue = values + jobTaskSpec.ValuesSyncedFromSource = true + } } } @@ -743,6 +755,35 @@ func (j DeployJobController) SetRepoCommitInfo() error { return nil } +func syncValuesFromTemplateService(service *commonmodels.Service, currentValues string) (string, bool, error) { + if service == nil { + return "", false, nil + } + + createFrom, err := service.GetHelmCreateFrom() + if err != nil || createFrom.YamlData == nil { + return "", false, nil + } + + yamlData := &templatemodels.CustomYaml{ + YamlContent: createFrom.YamlData.YamlContent, + RenderVariableKVs: createFrom.YamlData.RenderVariableKVs, + Source: createFrom.YamlData.Source, + AutoSync: true, + AutoSyncYaml: createFrom.YamlData.AutoSyncYaml, + SourceDetail: createFrom.YamlData.SourceDetail, + SourceID: createFrom.YamlData.SourceID, + } + _, values, err := commonservice.SyncYamlFromSource(yamlData, currentValues, yamlData.AutoSyncYaml) + if err != nil { + return "", false, err + } + if values == "" { + return "", false, nil + } + return values, true, nil +} + func (j DeployJobController) GetVariableList(jobName string, getAggregatedVariables, getRuntimeVariables, getPlaceHolderVariables, getServiceSpecificVariables, useUserInputValue bool) ([]*commonmodels.KeyVal, error) { resp := make([]*commonmodels.KeyVal, 0) From 96a01a273c89cf60ea2f6cca0f8dcff6ceb24b27 Mon Sep 17 00:00:00 2001 From: Cynthia Date: Thu, 2 Jul 2026 17:00:59 +0800 Subject: [PATCH 3/5] fix: sync helm values from git chart source on first deploy Signed-off-by: Cynthia --- .../jobcontroller/job_helm_deploy.go | 36 +++++++++++- .../workflow/controller/job/job_deploy.go | 56 ++++++++++++++----- 2 files changed, 78 insertions(+), 14 deletions(-) diff --git a/pkg/microservice/aslan/core/common/service/workflowcontroller/jobcontroller/job_helm_deploy.go b/pkg/microservice/aslan/core/common/service/workflowcontroller/jobcontroller/job_helm_deploy.go index b3d734587a..cba1273368 100644 --- a/pkg/microservice/aslan/core/common/service/workflowcontroller/jobcontroller/job_helm_deploy.go +++ b/pkg/microservice/aslan/core/common/service/workflowcontroller/jobcontroller/job_helm_deploy.go @@ -35,6 +35,7 @@ import ( "github.com/koderover/zadig/v2/pkg/microservice/aslan/config" commonmodels "github.com/koderover/zadig/v2/pkg/microservice/aslan/core/common/repository/models" + templatemodels "github.com/koderover/zadig/v2/pkg/microservice/aslan/core/common/repository/models/template" commonrepo "github.com/koderover/zadig/v2/pkg/microservice/aslan/core/common/repository/mongodb" helmservice "github.com/koderover/zadig/v2/pkg/microservice/aslan/core/common/service/helm" "github.com/koderover/zadig/v2/pkg/microservice/aslan/core/common/service/joblog" @@ -216,9 +217,16 @@ func (c *HelmDeployJobCtl) Run(ctx context.Context) { return } if currentEnvSvc == nil && c.jobTaskSpec.ValuesSyncedFromSource { + svcRender := newEnvService.GetServiceRender() + // For a git-loaded helm service (no YamlData on the template), fillHelmValuesSource + // left the source empty. Seed it from the chart git repo so future auto-sync runs + // can re-fetch the latest values.yaml from the same source. + if svcRender.OverrideYaml.Source == "" { + seedChartRepoSource(svcRender, latestTmplSvc) + } // use the pure source values (before image injection in GenMergedValues) as the // auto-sync baseline, so that future syncs compare against the unmodified source yaml. - newEnvService.GetServiceRender().SetAutoSyncYaml(c.jobTaskSpec.UserSuppliedValue) + svcRender.SetAutoSyncYaml(c.jobTaskSpec.UserSuppliedValue) } } @@ -372,6 +380,32 @@ func fillHelmValuesSource(envSvc *commonmodels.ProductService, tmplSvc *commonmo serviceRender.OverrideYaml.AutoSyncYaml = createFrom.YamlData.AutoSyncYaml } +// seedChartRepoSource records the chart git repo as the values source on the render, for +// git-loaded helm services whose values were synced from the chart's values.yaml. Unlike +// fillHelmValuesSource (which only handles templates carrying YamlData), this serves services +// loaded directly from a git repo where the chart's values.yaml is the source of truth. +// AutoSync is intentionally left untouched: the workflow's auto sync strategy drives sync at +// deploy time via a temporary flip in ToTask, so we only persist the source location here. +func seedChartRepoSource(svcRender *templatemodels.ServiceRender, tmplSvc *commonmodels.Service) { + if svcRender == nil || svcRender.OverrideYaml == nil || tmplSvc == nil { + return + } + if tmplSvc.CodehostID == 0 || tmplSvc.RepoName == "" || tmplSvc.LoadPath == "" { + return + } + svcRender.OverrideYaml.Source = setting.SourceFromGitRepo + svcRender.OverrideYaml.SourceDetail = &commonmodels.CreateFromRepo{ + GitRepoConfig: &templatemodels.GitRepoConfig{ + CodehostID: tmplSvc.CodehostID, + Owner: tmplSvc.RepoOwner, + Repo: tmplSvc.RepoName, + Branch: tmplSvc.BranchName, + Namespace: tmplSvc.RepoNamespace, + }, + LoadPath: fmt.Sprintf("%s/%s", tmplSvc.LoadPath, setting.ValuesYaml), + } +} + type ManifestStruct struct { Manifest string Unstructured *unstructured.Unstructured diff --git a/pkg/microservice/aslan/core/workflow/service/workflow/controller/job/job_deploy.go b/pkg/microservice/aslan/core/workflow/service/workflow/controller/job/job_deploy.go index 34150dbedf..473af67a6d 100644 --- a/pkg/microservice/aslan/core/workflow/service/workflow/controller/job/job_deploy.go +++ b/pkg/microservice/aslan/core/workflow/service/workflow/controller/job/job_deploy.go @@ -28,6 +28,7 @@ import ( commonrepo "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" commonservice "github.com/koderover/zadig/v2/pkg/microservice/aslan/core/common/service" + "github.com/koderover/zadig/v2/pkg/microservice/aslan/core/common/service/fs" "github.com/koderover/zadig/v2/pkg/microservice/aslan/core/common/service/kube" "github.com/koderover/zadig/v2/pkg/microservice/aslan/core/common/service/repository" commontypes "github.com/koderover/zadig/v2/pkg/microservice/aslan/core/common/types" @@ -760,28 +761,57 @@ func syncValuesFromTemplateService(service *commonmodels.Service, currentValues return "", false, nil } + // chart-template service with a values source: sync from the configured source. createFrom, err := service.GetHelmCreateFrom() - if err != nil || createFrom.YamlData == nil { - return "", false, nil + if err == nil && createFrom.YamlData != nil { + yamlData := &templatemodels.CustomYaml{ + YamlContent: createFrom.YamlData.YamlContent, + RenderVariableKVs: createFrom.YamlData.RenderVariableKVs, + Source: createFrom.YamlData.Source, + AutoSync: true, + AutoSyncYaml: createFrom.YamlData.AutoSyncYaml, + SourceDetail: createFrom.YamlData.SourceDetail, + SourceID: createFrom.YamlData.SourceID, + } + _, values, err := commonservice.SyncYamlFromSource(yamlData, currentValues, yamlData.AutoSyncYaml) + if err != nil { + return "", false, err + } + if values == "" { + return "", false, nil + } + return values, true, nil } - yamlData := &templatemodels.CustomYaml{ - YamlContent: createFrom.YamlData.YamlContent, - RenderVariableKVs: createFrom.YamlData.RenderVariableKVs, - Source: createFrom.YamlData.Source, - AutoSync: true, - AutoSyncYaml: createFrom.YamlData.AutoSyncYaml, - SourceDetail: createFrom.YamlData.SourceDetail, - SourceID: createFrom.YamlData.SourceID, + // git-loaded helm service (chart loaded from a git repo): the chart's values.yaml in + // the repo is the source of truth. Fetch the latest values.yaml so the first deployment + // is driven by the up-to-date chart values instead of a possibly stale snapshot. + return syncValuesFromChartRepo(service) +} + +// syncValuesFromChartRepo downloads the chart's values.yaml from the service's git repo. +// It is the fallback for undeployed helm services loaded from a git repo, whose template +// has no YamlData (no separate values auto-sync source) but whose chart values live in git. +func syncValuesFromChartRepo(service *commonmodels.Service) (string, bool, error) { + if service == nil || service.CodehostID == 0 || service.RepoName == "" || service.LoadPath == "" { + return "", false, nil } - _, values, err := commonservice.SyncYamlFromSource(yamlData, currentValues, yamlData.AutoSyncYaml) + valuesPath := fmt.Sprintf("%s/%s", service.LoadPath, setting.ValuesYaml) + valuesYAML, err := fs.DownloadFileFromSource(&fs.DownloadFromSourceArgs{ + CodehostID: service.CodehostID, + Owner: service.RepoOwner, + Namespace: service.RepoNamespace, + Repo: service.RepoName, + Path: valuesPath, + Branch: service.BranchName, + }) if err != nil { return "", false, err } - if values == "" { + if len(valuesYAML) == 0 { return "", false, nil } - return values, true, nil + return string(valuesYAML), true, nil } func (j DeployJobController) GetVariableList(jobName string, getAggregatedVariables, getRuntimeVariables, getPlaceHolderVariables, getServiceSpecificVariables, useUserInputValue bool) ([]*commonmodels.KeyVal, error) { From 7f01d37e02033c3d4cd7b97412cdca6e924e46f1 Mon Sep 17 00:00:00 2001 From: Cynthia Date: Fri, 3 Jul 2026 09:53:12 +0800 Subject: [PATCH 4/5] fix(workflow): sync helm values from source on first deploy Signed-off-by: Cynthia --- .../jobcontroller/job_helm_deploy.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/pkg/microservice/aslan/core/common/service/workflowcontroller/jobcontroller/job_helm_deploy.go b/pkg/microservice/aslan/core/common/service/workflowcontroller/jobcontroller/job_helm_deploy.go index cba1273368..b0e9d2d5b4 100644 --- a/pkg/microservice/aslan/core/common/service/workflowcontroller/jobcontroller/job_helm_deploy.go +++ b/pkg/microservice/aslan/core/common/service/workflowcontroller/jobcontroller/job_helm_deploy.go @@ -153,6 +153,8 @@ func (c *HelmDeployJobCtl) Run(ctx context.Context) { productInfo.ServiceDeployStrategy[c.jobTaskSpec.ServiceName] = setting.ServiceDeployStrategyDeploy if currentEnvSvc == nil { fillHelmValuesSource(newEnvService, latestTmplSvc) + seedChartRepoSource(newEnvService.GetServiceRender(), latestTmplSvc) + applySyncedValuesToNewEnvService(newEnvService, c.jobTaskSpec) } // calc final values yaml @@ -380,6 +382,16 @@ func fillHelmValuesSource(envSvc *commonmodels.ProductService, tmplSvc *commonmo serviceRender.OverrideYaml.AutoSyncYaml = createFrom.YamlData.AutoSyncYaml } +func applySyncedValuesToNewEnvService(envSvc *commonmodels.ProductService, jobSpec *commonmodels.JobTaskHelmDeploySpec) { + if envSvc == nil || jobSpec == nil || !jobSpec.ValuesSyncedFromSource || jobSpec.VariableYaml == "" { + return + } + + serviceRender := envSvc.GetServiceRender() + serviceRender.SetOverrideYaml(jobSpec.VariableYaml) + serviceRender.SetAutoSyncYaml(jobSpec.UserSuppliedValue) +} + // seedChartRepoSource records the chart git repo as the values source on the render, for // git-loaded helm services whose values were synced from the chart's values.yaml. Unlike // fillHelmValuesSource (which only handles templates carrying YamlData), this serves services @@ -390,6 +402,9 @@ func seedChartRepoSource(svcRender *templatemodels.ServiceRender, tmplSvc *commo if svcRender == nil || svcRender.OverrideYaml == nil || tmplSvc == nil { return } + if svcRender.OverrideYaml.SourceDetail != nil { + return + } if tmplSvc.CodehostID == 0 || tmplSvc.RepoName == "" || tmplSvc.LoadPath == "" { return } From fef6b46b29c68a6777866278b4cff260e2cfad24 Mon Sep 17 00:00:00 2001 From: Cynthia Date: Fri, 3 Jul 2026 11:21:08 +0800 Subject: [PATCH 5/5] refactor(workflow): simplify helm values sync setup Signed-off-by: Cynthia --- .../jobcontroller/job_helm_deploy.go | 26 +++++-------------- .../workflow/controller/job/job_deploy.go | 13 ++-------- 2 files changed, 9 insertions(+), 30 deletions(-) diff --git a/pkg/microservice/aslan/core/common/service/workflowcontroller/jobcontroller/job_helm_deploy.go b/pkg/microservice/aslan/core/common/service/workflowcontroller/jobcontroller/job_helm_deploy.go index b0e9d2d5b4..3fb1ab52ad 100644 --- a/pkg/microservice/aslan/core/common/service/workflowcontroller/jobcontroller/job_helm_deploy.go +++ b/pkg/microservice/aslan/core/common/service/workflowcontroller/jobcontroller/job_helm_deploy.go @@ -153,8 +153,11 @@ func (c *HelmDeployJobCtl) Run(ctx context.Context) { productInfo.ServiceDeployStrategy[c.jobTaskSpec.ServiceName] = setting.ServiceDeployStrategyDeploy if currentEnvSvc == nil { fillHelmValuesSource(newEnvService, latestTmplSvc) - seedChartRepoSource(newEnvService.GetServiceRender(), latestTmplSvc) - applySyncedValuesToNewEnvService(newEnvService, c.jobTaskSpec) + if c.jobTaskSpec.ValuesSyncedFromSource && c.jobTaskSpec.VariableYaml != "" { + serviceRender := newEnvService.GetServiceRender() + serviceRender.SetOverrideYaml(c.jobTaskSpec.VariableYaml) + serviceRender.SetAutoSyncYaml(c.jobTaskSpec.UserSuppliedValue) + } } // calc final values yaml @@ -382,27 +385,12 @@ func fillHelmValuesSource(envSvc *commonmodels.ProductService, tmplSvc *commonmo serviceRender.OverrideYaml.AutoSyncYaml = createFrom.YamlData.AutoSyncYaml } -func applySyncedValuesToNewEnvService(envSvc *commonmodels.ProductService, jobSpec *commonmodels.JobTaskHelmDeploySpec) { - if envSvc == nil || jobSpec == nil || !jobSpec.ValuesSyncedFromSource || jobSpec.VariableYaml == "" { - return - } - - serviceRender := envSvc.GetServiceRender() - serviceRender.SetOverrideYaml(jobSpec.VariableYaml) - serviceRender.SetAutoSyncYaml(jobSpec.UserSuppliedValue) -} - -// seedChartRepoSource records the chart git repo as the values source on the render, for -// git-loaded helm services whose values were synced from the chart's values.yaml. Unlike -// fillHelmValuesSource (which only handles templates carrying YamlData), this serves services -// loaded directly from a git repo where the chart's values.yaml is the source of truth. -// AutoSync is intentionally left untouched: the workflow's auto sync strategy drives sync at -// deploy time via a temporary flip in ToTask, so we only persist the source location here. +// seedChartRepoSource records the chart git repo as the values source for git-loaded helm services. func seedChartRepoSource(svcRender *templatemodels.ServiceRender, tmplSvc *commonmodels.Service) { if svcRender == nil || svcRender.OverrideYaml == nil || tmplSvc == nil { return } - if svcRender.OverrideYaml.SourceDetail != nil { + if svcRender.OverrideYaml.Source != "" || svcRender.OverrideYaml.SourceDetail != nil { return } if tmplSvc.CodehostID == 0 || tmplSvc.RepoName == "" || tmplSvc.LoadPath == "" { diff --git a/pkg/microservice/aslan/core/workflow/service/workflow/controller/job/job_deploy.go b/pkg/microservice/aslan/core/workflow/service/workflow/controller/job/job_deploy.go index 473af67a6d..fac43dd36f 100644 --- a/pkg/microservice/aslan/core/workflow/service/workflow/controller/job/job_deploy.go +++ b/pkg/microservice/aslan/core/workflow/service/workflow/controller/job/job_deploy.go @@ -783,19 +783,10 @@ func syncValuesFromTemplateService(service *commonmodels.Service, currentValues return values, true, nil } - // git-loaded helm service (chart loaded from a git repo): the chart's values.yaml in - // the repo is the source of truth. Fetch the latest values.yaml so the first deployment - // is driven by the up-to-date chart values instead of a possibly stale snapshot. - return syncValuesFromChartRepo(service) -} - -// syncValuesFromChartRepo downloads the chart's values.yaml from the service's git repo. -// It is the fallback for undeployed helm services loaded from a git repo, whose template -// has no YamlData (no separate values auto-sync source) but whose chart values live in git. -func syncValuesFromChartRepo(service *commonmodels.Service) (string, bool, error) { - if service == nil || service.CodehostID == 0 || service.RepoName == "" || service.LoadPath == "" { + if service.CodehostID == 0 || service.RepoName == "" || service.LoadPath == "" { return "", false, nil } + valuesPath := fmt.Sprintf("%s/%s", service.LoadPath, setting.ValuesYaml) valuesYAML, err := fs.DownloadFileFromSource(&fs.DownloadFromSourceArgs{ CodehostID: service.CodehostID,