Skip to content

fix: Validate config cm cs #5750

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions pkg/pipeline/ConfigMapService.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,17 @@ func NewConfigMapServiceImpl(chartRepository chartRepoRepository.ChartRepository
}
}

func (impl ConfigMapServiceImpl) checkIfConfigDataAlreadyExist(appId int) (int, error) {
config, err := impl.configMapRepository.GetByAppIdAppLevel(appId)
if err != nil && err != pg.ErrNoRows {
impl.logger.Errorw("error while checking if config data exist from db by appId", "appId", appId, "error", err)
return 0, err
} else if util.IsErrNoRows(err) {
return 0, nil
}
return config.Id, nil
}

func (impl ConfigMapServiceImpl) CMGlobalAddUpdate(configMapRequest *bean.ConfigDataRequest) (*bean.ConfigDataRequest, error) {
if len(configMapRequest.ConfigData) != 1 {
return nil, fmt.Errorf("invalid request multiple config found for add or update")
Expand All @@ -140,6 +151,14 @@ func (impl ConfigMapServiceImpl) CMGlobalAddUpdate(configMapRequest *bean.Config
return configMapRequest, err
}
var model *chartConfig.ConfigMapAppModel
requestId, err := impl.checkIfConfigDataAlreadyExist(configMapRequest.AppId)
if err != nil {
impl.logger.Errorw("error in checking if config map data already exists or not for appId", "appId", configMapRequest.AppId, "error", err)
return configMapRequest, err
}
if requestId > 0 {
configMapRequest.Id = requestId
}
if configMapRequest.Id > 0 {
model, err = impl.configMapRepository.GetByIdAppLevel(configMapRequest.Id)
if err != nil {
Expand Down Expand Up @@ -525,6 +544,14 @@ func (impl ConfigMapServiceImpl) CSGlobalAddUpdate(configMapRequest *bean.Config
impl.logger.Errorw("error in validating", "error", err)
return configMapRequest, err
}
requestId, err := impl.checkIfConfigDataAlreadyExist(configMapRequest.AppId)
if err != nil {
impl.logger.Errorw("error in checking if config secret data already exists or not for appId", "appId", configMapRequest.AppId, "error", err)
return configMapRequest, err
}
if requestId > 0 {
configMapRequest.Id = requestId
}
var model *chartConfig.ConfigMapAppModel
if configMapRequest.Id > 0 {
model, err = impl.configMapRepository.GetByIdAppLevel(configMapRequest.Id)
Expand Down
Loading