@@ -129,6 +129,17 @@ func NewConfigMapServiceImpl(chartRepository chartRepoRepository.ChartRepository
129
129
}
130
130
}
131
131
132
+ func (impl ConfigMapServiceImpl ) checkIfConfigDataAlreadyExist (appId int ) (int , error ) {
133
+ config , err := impl .configMapRepository .GetByAppIdAppLevel (appId )
134
+ if err != nil && err != pg .ErrNoRows {
135
+ impl .logger .Errorw ("error while checking if config data exist from db by appId" , "appId" , appId , "error" , err )
136
+ return 0 , err
137
+ } else if util .IsErrNoRows (err ) {
138
+ return 0 , nil
139
+ }
140
+ return config .Id , nil
141
+ }
142
+
132
143
func (impl ConfigMapServiceImpl ) CMGlobalAddUpdate (configMapRequest * bean.ConfigDataRequest ) (* bean.ConfigDataRequest , error ) {
133
144
if len (configMapRequest .ConfigData ) != 1 {
134
145
return nil , fmt .Errorf ("invalid request multiple config found for add or update" )
@@ -140,6 +151,14 @@ func (impl ConfigMapServiceImpl) CMGlobalAddUpdate(configMapRequest *bean.Config
140
151
return configMapRequest , err
141
152
}
142
153
var model * chartConfig.ConfigMapAppModel
154
+ requestId , err := impl .checkIfConfigDataAlreadyExist (configMapRequest .AppId )
155
+ if err != nil {
156
+ impl .logger .Errorw ("error in checking if config map data already exists or not for appId" , "appId" , configMapRequest .AppId , "error" , err )
157
+ return configMapRequest , err
158
+ }
159
+ if requestId > 0 {
160
+ configMapRequest .Id = requestId
161
+ }
143
162
if configMapRequest .Id > 0 {
144
163
model , err = impl .configMapRepository .GetByIdAppLevel (configMapRequest .Id )
145
164
if err != nil {
@@ -525,6 +544,14 @@ func (impl ConfigMapServiceImpl) CSGlobalAddUpdate(configMapRequest *bean.Config
525
544
impl .logger .Errorw ("error in validating" , "error" , err )
526
545
return configMapRequest , err
527
546
}
547
+ requestId , err := impl .checkIfConfigDataAlreadyExist (configMapRequest .AppId )
548
+ if err != nil {
549
+ impl .logger .Errorw ("error in checking if config secret data already exists or not for appId" , "appId" , configMapRequest .AppId , "error" , err )
550
+ return configMapRequest , err
551
+ }
552
+ if requestId > 0 {
553
+ configMapRequest .Id = requestId
554
+ }
528
555
var model * chartConfig.ConfigMapAppModel
529
556
if configMapRequest .Id > 0 {
530
557
model , err = impl .configMapRepository .GetByIdAppLevel (configMapRequest .Id )
0 commit comments