Skip to content

Commit e524505

Browse files
fix: duplication of tags on giving same key-value pair (#4139)
* fix-duplicate * unique-key * duplicate-fix * create app fix
1 parent 8460c9d commit e524505

File tree

2 files changed

+22
-14
lines changed

2 files changed

+22
-14
lines changed

pkg/app/AppCrudOperationService.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ func (impl AppCrudOperationServiceImpl) UpdateLabelsInApp(request *bean.CreateAp
206206
appLabelMap[uniqueLabelExists] = appLabel
207207
}
208208
}
209-
209+
appLabelDeleteMap := make(map[string]bool, 0)
210210
for _, label := range request.AppLabels {
211211
uniqueLabelRequest := fmt.Sprintf("%s:%s:%t", label.Key, label.Value, label.Propagate)
212212
if _, ok := appLabelMap[uniqueLabelRequest]; !ok {
@@ -227,10 +227,13 @@ func (impl AppCrudOperationServiceImpl) UpdateLabelsInApp(request *bean.CreateAp
227227
return nil, err
228228
}
229229
} else {
230-
// delete from map so that item remain live, all other item will be delete from this app
231-
delete(appLabelMap, uniqueLabelRequest)
230+
// storing this unique so that item remain live, all other item will be delete from this app
231+
appLabelDeleteMap[uniqueLabelRequest] = true
232232
}
233233
}
234+
for labelReq, _ := range appLabelDeleteMap {
235+
delete(appLabelMap, labelReq)
236+
}
234237
for _, appLabel := range appLabelMap {
235238
err = impl.appLabelRepository.Delete(appLabel, tx)
236239
if err != nil {

pkg/pipeline/CiCdPipelineOrchestrator.go

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1021,18 +1021,23 @@ func (impl CiCdPipelineOrchestratorImpl) CreateApp(createRequest *bean.CreateApp
10211021
}
10221022
// create labels and tags with app
10231023
if app.Active && len(createRequest.AppLabels) > 0 {
1024+
appLabelMap := make(map[string]bool)
10241025
for _, label := range createRequest.AppLabels {
1025-
request := &bean.AppLabelDto{
1026-
AppId: app.Id,
1027-
Key: label.Key,
1028-
Value: label.Value,
1029-
Propagate: label.Propagate,
1030-
UserId: createRequest.UserId,
1031-
}
1032-
_, err := impl.appLabelsService.Create(request, tx)
1033-
if err != nil {
1034-
impl.logger.Errorw("error on creating labels for app id ", "err", err, "appId", app.Id)
1035-
return nil, err
1026+
uniqueLabelExists := fmt.Sprintf("%s:%s:%t", label.Key, label.Value, label.Propagate)
1027+
if _, ok := appLabelMap[uniqueLabelExists]; !ok {
1028+
appLabelMap[uniqueLabelExists] = true
1029+
request := &bean.AppLabelDto{
1030+
AppId: app.Id,
1031+
Key: label.Key,
1032+
Value: label.Value,
1033+
Propagate: label.Propagate,
1034+
UserId: createRequest.UserId,
1035+
}
1036+
_, err := impl.appLabelsService.Create(request, tx)
1037+
if err != nil {
1038+
impl.logger.Errorw("error on creating labels for app id ", "err", err, "appId", app.Id)
1039+
return nil, err
1040+
}
10361041
}
10371042
}
10381043
}

0 commit comments

Comments
 (0)