@@ -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"
@@ -334,15 +335,38 @@ func PreviewService(args *PreviewServiceArgs, _ *zap.SugaredLogger) (*SvcDiffRes
334335
335336 curYaml := ""
336337 isImportToDeploy := false
337- if envInfo .ServiceDeployStrategy [args .ServiceName ] == setting .ServiceDeployStrategyImport && (args .UpdateServiceRevision || len (args .VariableKVs ) > 0 ) {
338- isImportToDeploy = true
338+ if envInfo .ServiceDeployStrategy [args .ServiceName ] == setting .ServiceDeployStrategyImport {
339+ // is imported service
340+ if len (args .DeployContents ) > 0 {
341+ // is workflow
342+ if len (args .DeployContents ) == 1 && slices .Contains (args .DeployContents , config .DeployImage ) {
343+ // only update images
344+ envSvc := envInfo .GetServiceMap ()[args .ServiceName ]
345+ if envSvc == nil {
346+ return nil , e .ErrPreviewYaml .AddErr (fmt .Errorf ("service %s not found in environment" , args .ServiceName ))
347+ }
348+ for _ , container := range envSvc .Containers {
349+ ret .Current .Yaml += container .Image + "\n "
350+ }
351+ for _ , container := range args .ServiceModules {
352+ ret .Latest .Yaml += container .Image + "\n "
353+ }
354+ return ret , nil
355+ } else if slices .Contains (args .DeployContents , config .DeployVars ) || slices .Contains (args .DeployContents , config .DeployConfig ) {
356+ // set update variables or configuration
357+ isImportToDeploy = true
358+ }
359+ } else {
360+ // is environment
361+ isImportToDeploy = true
362+ }
339363 }
340364
341365 curYaml , _ , err = kube .FetchCurrentAppliedYaml (& kube.GeneSvcYamlOption {
342366 ProductName : args .ProductName ,
343367 EnvName : args .EnvName ,
344368 ServiceName : args .ServiceName ,
345- UpdateServiceRevision : args . UpdateServiceRevision ,
369+ UpdateServiceRevision : false ,
346370 IsImportToDeploy : isImportToDeploy ,
347371 })
348372 if err != nil {
@@ -352,17 +376,6 @@ func PreviewService(args *PreviewServiceArgs, _ *zap.SugaredLogger) (*SvcDiffRes
352376 log .Errorf (ret .Error )
353377 }
354378
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-
366379 candidateOverrides , err := buildPreviewCandidateOverrides (envInfo , args .ServiceName , args .UpdateServiceRevision , args .VariableKVs )
367380 if err != nil {
368381 return nil , e .ErrPreviewYaml .AddErr (err )
0 commit comments