MCPcopy
hub / github.com/devtron-labs/devtron / executeDeploymentCreate

Function executeDeploymentCreate

pkg/appClone/batch/Deployment.go:87–171  ·  view source on GitHub ↗
(impl DeploymentActionImpl, deployment *v1.Deployment, ctx context.Context)

Source from the content-addressed store, hash-verified

85}
86
87func executeDeploymentCreate(impl DeploymentActionImpl, deployment *v1.Deployment, ctx context.Context) error {
88 if deployment.Operation != v1.Create {
89 return nil
90 }
91 if deployment.Destination.App == nil || len(*deployment.Destination.App) == 0 {
92 return fmt.Errorf("app name cannot be empty in deployment pipeline creation")
93 }
94 if deployment.Destination.Environment == nil || len(*deployment.Destination.Environment) == 0 {
95 return fmt.Errorf("environment cannot be empty in deployment pipeline creation")
96 }
97 if deployment.Destination.Workflow == nil || len(*deployment.Destination.Workflow) == 0 {
98 return fmt.Errorf("workflow cannot be empty in deployment pipeline creation")
99 }
100 if deployment.Strategy.BlueGreen == nil && deployment.Strategy.Recreate == nil && deployment.Strategy.Rolling == nil && deployment.Strategy.Canary == nil {
101 return fmt.Errorf("atleast one deployment strategy should be defined in deployment pipeline creation")
102 }
103 if len(deployment.Strategy.Default) == 0 {
104 return fmt.Errorf("default cannot be empty it should have one of BLUE_GREEN, CANARY, ROLLING, RECREATE")
105 }
106
107 app, err := impl.appRepo.FindActiveByName(*deployment.Destination.App)
108 if err != nil {
109 return fmt.Errorf("error `%s` with appname %s while creating pipeline", err.Error(), *deployment.Destination.App)
110 }
111 env, err := impl.envService.FindOne(*deployment.Destination.Environment)
112 if err != nil {
113 return fmt.Errorf("error `%s` with environment %s while creating pipeline", err.Error(), *deployment.Destination.Environment)
114 }
115
116 workflow, err := impl.appWorkflowRepo.FindByAppId(app.Id)
117 if err != nil {
118 return fmt.Errorf("error `%s` finding workflow for application %s while creating deployment pipeline", err.Error(), *deployment.Destination.App)
119 }
120
121 var ciPipeline *pc.CiPipeline
122 if deployment.PreviousPipeline == nil || deployment.PreviousPipeline.Build == nil || deployment.PreviousPipeline.Build.Destination == nil || deployment.PreviousPipeline.Build.Destination.Pipeline == nil {
123 return fmt.Errorf("previous pipeline cannot be empty for deployment")
124 }
125 if deployment.PreviousPipeline != nil {
126 if deployment.PreviousPipeline.Build != nil && deployment.PreviousPipeline.Build.Destination != nil && deployment.PreviousPipeline.Build.Destination.Pipeline != nil {
127 previousPipeName := *deployment.PreviousPipeline.Build.Destination.Pipeline
128 if !strings.HasPrefix(previousPipeName, *deployment.Destination.App+"-") {
129 //change pipeline name to appName-pipelineName
130 previousPipeName = fmt.Sprintf("%s-ci-%s", *deployment.Destination.App, previousPipeName)
131 }
132 ciPipeline, err = impl.ciPipelineRepository.FindByName(previousPipeName)
133 if err != nil {
134 return fmt.Errorf("error `%s` while finding previous pipeline %s in deployment pipeline creation", err.Error(), *deployment.PreviousPipeline.Build.Destination.Pipeline)
135 }
136 if ciPipeline.AppId != app.Id {
137 return fmt.Errorf("previous pipeline `%s` should belong to same application in deployment pipeline creation", *deployment.PreviousPipeline.Build.Destination.Pipeline)
138 }
139 }
140 }
141
142 pipelineConfig, err := transformToDeploymentConfig(deployment, env, workflow, ciPipeline)
143 if err != nil {
144 return err

Callers

nothing calls this directly

Calls 11

AppendErrorStringFunction · 0.92
GetErrorOrNilFunction · 0.92
FindActiveByNameMethod · 0.65
FindOneMethod · 0.65
FindByAppIdMethod · 0.65
FindByNameMethod · 0.65
ExecuteMethod · 0.65
GetPropsMethod · 0.65
CreateCdPipelinesMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…