MCPcopy Index your code
hub / github.com/devtron-labs/devtron / Create

Method Create

pkg/chart/ChartService.go:142–331  ·  view source on GitHub ↗
(templateRequest bean3.TemplateRequest, ctx context.Context)

Source from the content-addressed store, hash-verified

140}
141
142func (impl *ChartServiceImpl) Create(templateRequest bean3.TemplateRequest, ctx context.Context) (*bean3.TemplateRequest, error) {
143 newCtx, span := otel.Tracer("orchestrator").Start(ctx, "ChartServiceImpl.Create")
144 defer span.End()
145 err := impl.chartRefService.CheckChartExists(templateRequest.ChartRefId)
146 if err != nil {
147 impl.logger.Errorw("error in getting missing chart for chartRefId", "err", err, "chartRefId")
148 return nil, err
149 }
150 chartMeta, err := impl.getChartMetaData(templateRequest)
151 if err != nil {
152 return nil, err
153 }
154
155 existingChart, _ := impl.chartRepository.FindChartByAppIdAndRefId(templateRequest.AppId, templateRequest.ChartRefId)
156 if existingChart != nil && existingChart.Id > 0 {
157 return nil, fmt.Errorf("this reference chart already has added to appId %d refId %d", templateRequest.AppId, templateRequest.Id)
158 }
159
160 //save chart
161 // 1. create chart, 2. push in repo, 3. add value of chart variable 4. save chart
162 charRepository, err := impl.getChartRepo(templateRequest)
163 if err != nil {
164 impl.logger.Errorw("error in fetching chart repo detail", "req", templateRequest)
165 return nil, err
166 }
167
168 refChart, templateName, _, pipelineStrategyPath, err := impl.chartRefService.GetRefChart(templateRequest.ChartRefId)
169 if err != nil {
170 return nil, err
171 }
172
173 if err != nil {
174 impl.logger.Errorw("chart version parsing", "err", err)
175 return nil, err
176 }
177
178 tx, err := impl.chartRepository.StartTx()
179 if err != nil {
180 impl.logger.Errorw("error in starting transaction to update charts", "error", err)
181 return nil, err
182 }
183 defer impl.chartRepository.RollbackTx(tx)
184 // STARTS
185
186 currentLatestChart, err := impl.chartRepository.FindLatestChartForAppByAppId(tx, templateRequest.AppId)
187 if err != nil && pg.ErrNoRows != err {
188 return nil, err
189 }
190 gitRepoUrl := apiGitOpsBean.GIT_REPO_NOT_CONFIGURED
191 if currentLatestChart.GitRepoUrl != "" {
192 gitRepoUrl = currentLatestChart.GitRepoUrl
193 }
194
195 impl.logger.Debugw("current latest chart in db", "chartId", currentLatestChart.Id)
196 if currentLatestChart.Id > 0 {
197 err = impl.UpdateExistingChartsToLatestFalse(tx, &templateRequest, currentLatestChart)
198 if err != nil {
199 impl.logger.Errorw("error in updating charts", "chartId", currentLatestChart.Id, "error", err)

Callers 1

UpgradeForAppMethod · 0.95

Calls 15

getChartMetaDataMethod · 0.95
getChartRepoMethod · 0.95
getNewVersionMethod · 0.95
ChartAdaptorFunction · 0.92
JsonPatchMethod · 0.80
CheckChartExistsMethod · 0.65
GetRefChartMethod · 0.65
StartTxMethod · 0.65
RollbackTxMethod · 0.65

Tested by

no test coverage detected