@@ -19,6 +19,7 @@ package service
1919import (
2020 "context"
2121 "fmt"
22+ "slices"
2223
2324 "github.com/koderover/zadig/v2/pkg/tool/clientmanager"
2425 "github.com/pkg/errors"
@@ -332,17 +333,47 @@ func PreviewService(args *PreviewServiceArgs, _ *zap.SugaredLogger) (*SvcDiffRes
332333 Latest : TmplYaml {},
333334 }
334335
336+ log .Debugf ("deploy contents: %+v" , args .DeployContents )
337+ log .Debugf ("deploy strategy: %+v" , envInfo .ServiceDeployStrategy [args .ServiceName ])
338+ log .Debugf ("update service revision: %+v" , args .UpdateServiceRevision )
339+ log .Debugf ("variable kvs: %+v" , args .VariableKVs )
340+
335341 curYaml := ""
336342 isImportToDeploy := false
337- if envInfo .ServiceDeployStrategy [args .ServiceName ] == setting .ServiceDeployStrategyImport && (args .UpdateServiceRevision || len (args .VariableKVs ) > 0 ) {
338- isImportToDeploy = true
343+ if envInfo .ServiceDeployStrategy [args .ServiceName ] == setting .ServiceDeployStrategyImport {
344+ // is imported service
345+ if len (args .DeployContents ) > 0 {
346+ // is workflow
347+ if len (args .DeployContents ) == 1 && slices .Contains (args .DeployContents , config .DeployImage ) {
348+ // only update images
349+ envSvc := envInfo .GetServiceMap ()[args .ServiceName ]
350+ if envSvc == nil {
351+ return nil , e .ErrPreviewYaml .AddErr (fmt .Errorf ("service %s not found in environment" , args .ServiceName ))
352+ }
353+ for _ , container := range envSvc .Containers {
354+ ret .Current .Yaml += container .Image + "\n "
355+ }
356+ for _ , container := range args .ServiceModules {
357+ ret .Latest .Yaml += container .Image + "\n "
358+ }
359+ return ret , nil
360+ } else if slices .Contains (args .DeployContents , config .DeployVars ) || slices .Contains (args .DeployContents , config .DeployConfig ) {
361+ // set update variables or configuration
362+ isImportToDeploy = true
363+ }
364+ } else {
365+ // is environment
366+ isImportToDeploy = true
367+ }
339368 }
340369
370+ log .Debugf ("isImportToDeploy: %+v" , isImportToDeploy )
371+
341372 curYaml , _ , err = kube .FetchCurrentAppliedYaml (& kube.GeneSvcYamlOption {
342373 ProductName : args .ProductName ,
343374 EnvName : args .EnvName ,
344375 ServiceName : args .ServiceName ,
345- UpdateServiceRevision : args . UpdateServiceRevision ,
376+ UpdateServiceRevision : false ,
346377 IsImportToDeploy : isImportToDeploy ,
347378 })
348379 if err != nil {
@@ -352,17 +383,6 @@ func PreviewService(args *PreviewServiceArgs, _ *zap.SugaredLogger) (*SvcDiffRes
352383 log .Errorf (ret .Error )
353384 }
354385
355- // for situations only update images, replace images directly
356- if ! args .UpdateServiceRevision && len (args .VariableKVs ) == 0 {
357- latestYaml , _ , err := kube .ReplaceWorkloadImages (curYaml , args .ServiceModules )
358- if err != nil {
359- return nil , e .ErrPreviewYaml .AddErr (err )
360- }
361- ret .Current .Yaml = curYaml
362- ret .Latest .Yaml = latestYaml
363- return ret , nil
364- }
365-
366386 candidateOverrides , err := buildPreviewCandidateOverrides (envInfo , args .ServiceName , args .UpdateServiceRevision , args .VariableKVs )
367387 if err != nil {
368388 return nil , e .ErrPreviewYaml .AddErr (err )
0 commit comments