@@ -70,7 +70,6 @@ type ChartRepositoryService interface {
70
70
GetChartRepoByName (name string ) (* ChartRepoDto , error )
71
71
GetChartRepoList () ([]* ChartRepoWithIsEditableDto , error )
72
72
GetChartRepoListMin () ([]* ChartRepoDto , error )
73
- ValidateDeploymentCount (request * ChartRepoDto ) error
74
73
ValidateChartRepo (request * ChartRepoDto ) * DetailedErrorHelmRepoValidation
75
74
ValidateAndCreateChartRepo (request * ChartRepoDto ) (* chartRepoRepository.ChartRepo , error , * DetailedErrorHelmRepoValidation )
76
75
ValidateAndUpdateChartRepo (request * ChartRepoDto ) (* chartRepoRepository.ChartRepo , error , * DetailedErrorHelmRepoValidation )
@@ -225,17 +224,13 @@ func (impl *ChartRepositoryServiceImpl) CreateChartRepo(request *ChartRepoDto) (
225
224
return chartRepo , nil
226
225
}
227
226
228
- func (impl * ChartRepositoryServiceImpl ) ValidateDeploymentCount ( request * ChartRepoDto ) error {
229
- activeDeploymentCount , err := impl .repoRepository .FindDeploymentCountByChartRepoId (request . Id )
227
+ func (impl * ChartRepositoryServiceImpl ) getCountOfDeployedCharts ( chartRepoId int ) ( int , error ) {
228
+ activeDeploymentCount , err := impl .repoRepository .FindDeploymentCountByChartRepoId (chartRepoId )
230
229
if err != nil {
231
- impl .logger .Errorw ("error in getting deployment count, CheckDeploymentCount" , "err" , err , "payload" , request )
232
- return err
233
- }
234
- if activeDeploymentCount > 0 {
235
- err = & util.ApiError {Code : "400" , HttpStatusCode : 400 , UserMessage : "cannot update, found charts deployed using this repo" }
236
- return err
230
+ impl .logger .Errorw ("error in getting deployment count, CheckDeploymentCount" , "chartRepoId" , chartRepoId , "err" , err )
231
+ return 0 , err
237
232
}
238
- return err
233
+ return activeDeploymentCount , nil
239
234
}
240
235
241
236
func (impl * ChartRepositoryServiceImpl ) UpdateData (request * ChartRepoDto ) (* chartRepoRepository.ChartRepo , error ) {
@@ -256,6 +251,18 @@ func (impl *ChartRepositoryServiceImpl) UpdateData(request *ChartRepoDto) (*char
256
251
if request .Name != previousName && strings .ToLower (request .Name ) != request .Name {
257
252
return nil , errors .New ("invalid repo name: please use lowercase" )
258
253
}
254
+
255
+ deployedChartCount , err := impl .getCountOfDeployedCharts (request .Id )
256
+ if err != nil {
257
+ impl .logger .Errorw ("error in getting charts deployed via chart repo" , "chartRepoId" , request .Id , "err" , err )
258
+ return nil , err
259
+ }
260
+
261
+ if deployedChartCount > 0 && (request .Name != previousName || request .Url != previousUrl ) {
262
+ err = & util.ApiError {Code : "400" , HttpStatusCode : 400 , UserMessage : "cannot update, found charts deployed using this repo" }
263
+ return nil , err
264
+ }
265
+
259
266
chartRepo .Url = request .Url
260
267
chartRepo .Name = request .Name
261
268
chartRepo .AuthMode = request .AuthMode
0 commit comments