@@ -2447,49 +2447,7 @@ type DeploymentType struct {
24472447}
24482448
24492449type Deployment struct {
2450- Strategy Strategy `json:"strategy"`
2451- }
2452-
2453- type Strategy struct {
2454- BlueGreen * BlueGreen `json:"blueGreen,omitempty"`
2455- Rolling * Rolling `json:"rolling,omitempty"`
2456- Canary * Canary `json:"canary,omitempty"`
2457- Recreate * Recreate `json:"recreate,omitempty"`
2458- }
2459-
2460- type BlueGreen struct {
2461- AutoPromotionSeconds int `json:"autoPromotionSeconds"`
2462- ScaleDownDelaySeconds int `json:"scaleDownDelaySeconds"`
2463- PreviewReplicaCount int `json:"previewReplicaCount"`
2464- AutoPromotionEnabled bool `json:"autoPromotionEnabled"`
2465- }
2466-
2467- type Canary struct {
2468- MaxSurge string `json:"maxSurge,omitempty"`
2469- MaxUnavailable int `json:"maxUnavailable,omitempty"`
2470- Steps []CanaryStep `json:"steps,omitempty"`
2471- }
2472-
2473- type CanaryStep struct {
2474- // SetWeight sets what percentage of the newRS should receive
2475- SetWeight * int32 `json:"setWeight,omitempty"`
2476- // Pause freezes the rollout by setting spec.Paused to true.
2477- // A Rollout will resume when spec.Paused is reset to false.
2478- // +optional
2479- Pause * RolloutPause `json:"pause,omitempty"`
2480- }
2481-
2482- type RolloutPause struct {
2483- // Duration the amount of time to wait before moving to the next step.
2484- // +optional
2485- Duration * int32 `json:"duration,omitempty"`
2486- }
2487- type Recreate struct {
2488- }
2489-
2490- type Rolling struct {
2491- MaxSurge string `json:"maxSurge"`
2492- MaxUnavailable int `json:"maxUnavailable"`
2450+ Strategy map [string ]interface {} `json:"strategy"`
24932451}
24942452
24952453func (impl PipelineBuilderImpl ) createCdPipeline (ctx context.Context , app * app2.App , pipeline * bean.CDPipelineConfigObject , userId int32 ) (pipelineRes int , err error ) {
@@ -2749,71 +2707,30 @@ func (impl PipelineBuilderImpl) updateCdPipeline(ctx context.Context, pipeline *
27492707 return nil
27502708}
27512709
2752- func (impl PipelineBuilderImpl ) filterDeploymentTemplate (deploymentTemplate chartRepoRepository. DeploymentStrategy , pipelineOverride string ) (string , error ) {
2753- var deploymentType DeploymentType
2754- err := json .Unmarshal ([]byte (pipelineOverride ), & deploymentType )
2710+ func (impl PipelineBuilderImpl ) filterDeploymentTemplate (strategyKey string , pipelineStrategiesJson string ) (string , error ) {
2711+ var pipelineStrategies DeploymentType
2712+ err := json .Unmarshal ([]byte (pipelineStrategiesJson ), & pipelineStrategies )
27552713 if err != nil {
2756- impl .logger .Errorw ("err" , err )
2714+ impl .logger .Errorw ("error while unmarshal strategies" , " err" , err )
27572715 return "" , err
27582716 }
2759- if chartRepoRepository .DEPLOYMENT_STRATEGY_BLUE_GREEN == deploymentTemplate {
2760- newDeploymentType := DeploymentType {
2761- Deployment : Deployment {
2762- Strategy : Strategy {
2763- BlueGreen : deploymentType .Deployment .Strategy .BlueGreen ,
2764- },
2765- },
2766- }
2767- pipelineOverrideBytes , err := json .Marshal (newDeploymentType )
2768- if err != nil {
2769- impl .logger .Errorw ("err" , err )
2770- return "" , err
2771- }
2772- pipelineOverride = string (pipelineOverrideBytes )
2773- } else if chartRepoRepository .DEPLOYMENT_STRATEGY_ROLLING == deploymentTemplate {
2774- newDeploymentType := DeploymentType {
2775- Deployment : Deployment {
2776- Strategy : Strategy {
2777- Rolling : deploymentType .Deployment .Strategy .Rolling ,
2778- },
2779- },
2780- }
2781- pipelineOverrideBytes , err := json .Marshal (newDeploymentType )
2782- if err != nil {
2783- impl .logger .Errorw ("err" , err )
2784- return "" , err
2785- }
2786- pipelineOverride = string (pipelineOverrideBytes )
2787- } else if chartRepoRepository .DEPLOYMENT_STRATEGY_CANARY == deploymentTemplate {
2788- newDeploymentType := DeploymentType {
2789- Deployment : Deployment {
2790- Strategy : Strategy {
2791- Canary : deploymentType .Deployment .Strategy .Canary ,
2792- },
2793- },
2794- }
2795- pipelineOverrideBytes , err := json .Marshal (newDeploymentType )
2796- if err != nil {
2797- impl .logger .Errorw ("err" , err )
2798- return "" , err
2799- }
2800- pipelineOverride = string (pipelineOverrideBytes )
2801- } else if chartRepoRepository .DEPLOYMENT_STRATEGY_RECREATE == deploymentTemplate {
2802- newDeploymentType := DeploymentType {
2803- Deployment : Deployment {
2804- Strategy : Strategy {
2805- Recreate : deploymentType .Deployment .Strategy .Recreate ,
2806- },
2807- },
2808- }
2809- pipelineOverrideBytes , err := json .Marshal (newDeploymentType )
2810- if err != nil {
2811- impl .logger .Errorw ("err" , err )
2812- return "" , err
2813- }
2814- pipelineOverride = string (pipelineOverrideBytes )
2717+ if pipelineStrategies .Deployment .Strategy [strategyKey ] == nil {
2718+ return "" , fmt .Errorf ("no deployment strategy found for %s" , strategyKey )
28152719 }
2816- return pipelineOverride , nil
2720+ strategy := make (map [string ]interface {})
2721+ strategy [strategyKey ] = pipelineStrategies .Deployment .Strategy [strategyKey ].(map [string ]interface {})
2722+ pipelineStrategy := DeploymentType {
2723+ Deployment : Deployment {
2724+ Strategy : strategy ,
2725+ },
2726+ }
2727+ pipelineOverrideBytes , err := json .Marshal (pipelineStrategy )
2728+ if err != nil {
2729+ impl .logger .Errorw ("error while marshal strategies" , "err" , err )
2730+ return "" , err
2731+ }
2732+ pipelineStrategyJson := string (pipelineOverrideBytes )
2733+ return pipelineStrategyJson , nil
28172734}
28182735
28192736func (impl PipelineBuilderImpl ) GetTriggerViewCdPipelinesForApp (appId int ) (cdPipelines * bean.CdPipelines , err error ) {
@@ -3368,7 +3285,7 @@ func (impl PipelineBuilderImpl) FetchCDPipelineStrategy(appId int) (PipelineStra
33683285 }
33693286
33703287 //get global strategy for this chart
3371- globalStrategies , err := impl .globalStrategyMetadataRepository .GetByChartRefId (chart .ChartRefId )
3288+ globalStrategies , err := impl .globalStrategyMetadataChartRefMappingRepository .GetByChartRefId (chart .ChartRefId )
33723289 if err != nil && err != pg .ErrNoRows {
33733290 impl .logger .Errorw ("error in getting global strategies" , "err" , err )
33743291 return pipelineStrategiesResponse , err
@@ -3378,19 +3295,15 @@ func (impl PipelineBuilderImpl) FetchCDPipelineStrategy(appId int) (PipelineStra
33783295 }
33793296 pipelineOverride := chart .PipelineOverride
33803297 for _ , globalStrategy := range globalStrategies {
3381- config , err := impl .filterDeploymentTemplate (globalStrategy .Name , pipelineOverride )
3298+ pipelineStrategyJson , err := impl .filterDeploymentTemplate (globalStrategy .GlobalStrategyMetadata . Key , pipelineOverride )
33823299 if err != nil {
33833300 return pipelineStrategiesResponse , err
33843301 }
33853302 pipelineStrategy := PipelineStrategy {
3386- DeploymentTemplate : globalStrategy .Name ,
3387- Config : []byte (config ),
3388- }
3389- if globalStrategy .Name == chartRepoRepository .DEPLOYMENT_STRATEGY_ROLLING {
3390- pipelineStrategy .Default = true
3391- } else {
3392- pipelineStrategy .Default = false
3303+ DeploymentTemplate : globalStrategy .GlobalStrategyMetadata .Name ,
3304+ Config : []byte (pipelineStrategyJson ),
33933305 }
3306+ pipelineStrategy .Default = globalStrategy .Default
33943307 pipelineStrategiesResponse .PipelineStrategy = append (pipelineStrategiesResponse .PipelineStrategy , pipelineStrategy )
33953308 }
33963309 return pipelineStrategiesResponse , nil
0 commit comments