Skip to content
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
3041db5
tx in chart service crud and configProperties
iamayushm Jun 3, 2025
c740276
Merge branch 'develop' into chart-service-refactoring
iamayushm Jun 3, 2025
7e7638c
wip
iamayushm Jun 3, 2025
31622a4
refactoring
iamayushm Jun 4, 2025
f4835b2
fix
iamayushm Jun 4, 2025
6258e6d
pointer handling
iamayushm Jun 4, 2025
f53cb41
latest flag update
iamayushm Jun 4, 2025
7f16d00
tx fix
iamayushm Jun 4, 2025
ab42685
fix chart location
iamayushm Jun 4, 2025
b76b90d
update fix
iamayushm Jun 5, 2025
3f2e3d8
update audit log
iamayushm Jun 11, 2025
98e62ee
review changes
iamayushm Jun 19, 2025
3c0f6c8
Merge remote-tracking branch 'origin/develop' into chart-service-refa…
iamayushm Jun 19, 2025
cd3973f
tx commit
iamayushm Jun 19, 2025
69084a0
Merge remote-tracking branch 'origin/develop' into chart-service-refa…
iamayushm Jul 4, 2025
a1034e4
build fix
iamayushm Jul 4, 2025
de25e0d
fix: Notifier v1 removed (#6705)
prkhrkat Jul 4, 2025
808607d
Merge remote-tracking branch 'origin/main' into chart-service-refacto…
iamayushm Jul 10, 2025
35ce7c6
Merge remote-tracking branch 'origin/develop' into chart-service-refa…
iamayushm Jul 10, 2025
c86b395
updating tx
iamayushm Jul 11, 2025
e6ede29
override method update
iamayushm Jul 14, 2025
7cc5e2e
fix overriden
iamayushm Jul 14, 2025
992823e
updating condition
iamayushm Jul 14, 2025
9a0d46d
develop merge
iamayushm Jul 16, 2025
40b7a83
review comments
iamayushm Jul 16, 2025
fbb4af5
Merge remote-tracking branch 'origin/develop' into chart-service-refa…
iamayushm Jul 17, 2025
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
4 changes: 2 additions & 2 deletions api/restHandler/app/appList/AppListingRestHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,7 @@ func (handler AppListingRestHandlerImpl) FetchResourceTree(w http.ResponseWriter
common.WriteJsonResp(w, fmt.Errorf("unauthorized user"), nil, http.StatusForbidden)
return
}
envDeploymentConfig, err := handler.deploymentConfigService.GetConfigForDevtronApps(appId, envId)
envDeploymentConfig, err := handler.deploymentConfigService.GetConfigForDevtronApps(nil, appId, envId)
if err != nil {
handler.logger.Errorw("error in fetching deployment config", "appId", appId, "envId", envId, "err", err)
common.WriteJsonResp(w, fmt.Errorf("error in getting deployment config for env"), nil, http.StatusInternalServerError)
Expand Down Expand Up @@ -887,7 +887,7 @@ func (handler AppListingRestHandlerImpl) GetHostUrlsByBatch(w http.ResponseWrite
}

cdPipeline := pipelines[0]
envDeploymentConfig, err := handler.deploymentConfigService.GetConfigForDevtronApps(appId, envId)
envDeploymentConfig, err := handler.deploymentConfigService.GetConfigForDevtronApps(nil, appId, envId)
if err != nil {
handler.logger.Errorw("error in fetching deployment config", "appId", appId, "envId", envId, "err", err)
common.WriteJsonResp(w, fmt.Errorf("error in getting deployment config for env"), nil, http.StatusInternalServerError)
Expand Down
2 changes: 1 addition & 1 deletion cmd/external-app/wire_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"github.com/devtron-labs/devtron/pkg/cluster/environment/repository"
"github.com/devtron-labs/devtron/pkg/sql"
"github.com/go-pg/pg"
"github.com/go-pg/pg/orm"
"github.com/juju/errors"
)

Expand Down Expand Up @@ -58,16 +59,16 @@ type EnvConfigOverrideRepository interface {
ActiveEnvConfigOverride(appId, environmentId int) (*EnvConfigOverride, error) //successful env config
GetByIdIncludingInactive(id int) (*EnvConfigOverride, error)
//this api updates only EnvOverrideValues, EnvMergedValues, Status, ManualReviewed, active based on id
UpdateProperties(config *EnvConfigOverride) error
UpdateProperties(tx *pg.Tx, config *EnvConfigOverride) error
GetByEnvironment(targetEnvironmentId int) ([]EnvConfigOverride, error)

GetEnvConfigByChartId(chartId int) ([]EnvConfigOverride, error)
UpdateEnvConfigStatus(config *EnvConfigOverride) error
Delete(envConfigOverride *EnvConfigOverride) error
FindLatestChartForAppByAppIdAndEnvId(appId, targetEnvironmentId int) (*EnvConfigOverride, error)
FindLatestChartForAppByAppIdAndEnvId(tx *pg.Tx, appId, targetEnvironmentId int) (*EnvConfigOverride, error)
FindChartRefIdsForLatestChartForAppByAppIdAndEnvIds(appId int, targetEnvironmentIds []int) (map[int]int, error)
FindChartByAppIdAndEnvIdAndChartRefId(appId, targetEnvironmentId int, chartRefId int) (*EnvConfigOverride, error)
Update(envConfigOverride *EnvConfigOverride) (*EnvConfigOverride, error)
Update(tx *pg.Tx, envConfigOverride *EnvConfigOverride) (*EnvConfigOverride, error)
FindChartForAppByAppIdAndEnvId(appId, targetEnvironmentId int) (*EnvConfigOverride, error)
SaveWithTxn(model *EnvConfigOverride, tx *pg.Tx) error
UpdateWithTxn(envConfigOverride *EnvConfigOverride, tx *pg.Tx) (*EnvConfigOverride, error)
Expand All @@ -78,6 +79,7 @@ type EnvConfigOverrideRepository interface {
// EnvConfigOverride.Chart is not populated,
// as the chartRepoRepository.Chart contains the reference chart(in bytes).
GetAllOverridesForApp(appId int) ([]*EnvConfigOverride, error)
GetDbConnection() *pg.DB
}

type EnvConfigOverrideRepositoryImpl struct {
Expand Down Expand Up @@ -205,8 +207,13 @@ func (r EnvConfigOverrideRepositoryImpl) GetByIdIncludingInactive(id int) (*EnvC

// this api updates only EnvOverrideValues, EnvMergedValues, Status, ManualReviewed, active
// based on id
func (r EnvConfigOverrideRepositoryImpl) UpdateProperties(config *EnvConfigOverride) error {
_, err := r.dbConnection.Model(config).
func (r EnvConfigOverrideRepositoryImpl) UpdateProperties(tx *pg.Tx, config *EnvConfigOverride) error {
var connection orm.DB
connection = tx
if tx == nil {
connection = r.dbConnection
}
_, err := connection.Model(config).
Set("env_override_yaml = ?", config.EnvOverrideValues).
Set("status =?", config.Status).
Set("reviewed =?", config.ManualReviewed).
Expand Down Expand Up @@ -272,9 +279,14 @@ func (r EnvConfigOverrideRepositoryImpl) Delete(envConfigOverride *EnvConfigOver
return err
}

func (r EnvConfigOverrideRepositoryImpl) FindLatestChartForAppByAppIdAndEnvId(appId, targetEnvironmentId int) (*EnvConfigOverride, error) {
func (r EnvConfigOverrideRepositoryImpl) FindLatestChartForAppByAppIdAndEnvId(tx *pg.Tx, appId, targetEnvironmentId int) (*EnvConfigOverride, error) {
eco := &EnvConfigOverride{}
err := r.dbConnection.
var connection orm.DB
connection = tx
if tx == nil {
connection = r.dbConnection
}
err := connection.
Model(eco).
Where("env_config_override.target_environment = ?", targetEnvironmentId).
Where("env_config_override.latest = ?", true).
Expand Down Expand Up @@ -321,8 +333,13 @@ func (r EnvConfigOverrideRepositoryImpl) FindChartByAppIdAndEnvIdAndChartRefId(a
return eco, err
}

func (r EnvConfigOverrideRepositoryImpl) Update(envConfigOverride *EnvConfigOverride) (*EnvConfigOverride, error) {
err := r.dbConnection.Update(envConfigOverride)
func (r EnvConfigOverrideRepositoryImpl) Update(tx *pg.Tx, envConfigOverride *EnvConfigOverride) (*EnvConfigOverride, error) {
var connection orm.DB
connection = tx
if tx == nil {
connection = r.dbConnection
}
err := connection.Update(envConfigOverride)
return envConfigOverride, err
}

Expand Down Expand Up @@ -380,3 +397,7 @@ func (r EnvConfigOverrideRepositoryImpl) GetAllOverridesForApp(appId int) ([]*En
Select()
return eco, err
}

func (r EnvConfigOverrideRepositoryImpl) GetDbConnection() *pg.DB {
return r.dbConnection
}
22 changes: 10 additions & 12 deletions internal/sql/repository/deploymentConfig/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,12 @@ func (impl *RepositoryImpl) UpdateAll(tx *pg.Tx, configs []*DeploymentConfig) ([

func (impl *RepositoryImpl) GetByAppIdAndEnvId(tx *pg.Tx, appId, envId int) (*DeploymentConfig, error) {
result := &DeploymentConfig{}
var query *orm.Query
if tx != nil {
query = tx.Model(result)
} else {
query = impl.dbConnection.Model(result)
var connection orm.DB
connection = tx
if tx == nil {
connection = impl.dbConnection
}
err := query.
err := connection.Model(result).
Join("INNER JOIN app a").
JoinOn("deployment_config.app_id = a.id").
Join("INNER JOIN environment e").
Expand All @@ -146,13 +145,12 @@ func (impl *RepositoryImpl) GetByAppIdAndEnvId(tx *pg.Tx, appId, envId int) (*De

func (impl *RepositoryImpl) GetAppLevelConfigForDevtronApps(tx *pg.Tx, appId int) (*DeploymentConfig, error) {
result := &DeploymentConfig{}
var query *orm.Query
if tx != nil {
query = tx.Model(result)
} else {
query = impl.dbConnection.Model(result)
var connection orm.DB
connection = tx
if tx == nil {
connection = impl.dbConnection
}
err := query.
err := connection.Model(result).
Join("INNER JOIN app a").
JoinOn("deployment_config.app_id = a.id").
Where("a.active = ?", true).
Expand Down
4 changes: 2 additions & 2 deletions pkg/app/AppListingService.go
Original file line number Diff line number Diff line change
Expand Up @@ -760,7 +760,7 @@ func (impl AppListingServiceImpl) FetchOtherEnvironment(ctx context.Context, app
return envs, err
}
newCtx, span = otel.Tracer("chartRepository").Start(newCtx, "FindLatestChartForAppByAppId")
chart, err := impl.chartRepository.FindLatestChartForAppByAppId(appId)
chart, err := impl.chartRepository.FindLatestChartForAppByAppId(nil, appId)
span.End()
if err != nil && err != pg.ErrNoRows {
impl.Logger.Errorw("error in fetching latest chart", "err", err)
Expand All @@ -781,7 +781,7 @@ func (impl AppListingServiceImpl) FetchOtherEnvironment(ctx context.Context, app
}
for _, env := range envs {
newCtx, span = otel.Tracer("envOverrideRepository").Start(newCtx, "FindLatestChartForAppByAppIdAndEnvId")
envOverride, err := impl.envConfigOverrideReadService.FindLatestChartForAppByAppIdAndEnvId(appId, env.EnvironmentId)
envOverride, err := impl.envConfigOverrideReadService.FindLatestChartForAppByAppIdAndEnvId(nil, appId, env.EnvironmentId)
span.End()
if err != nil && !errors2.IsNotFound(err) {
impl.Logger.Errorw("error in fetching latest chart by appId and envId", "err", err, "appId", appId, "envId", env.EnvironmentId)
Expand Down
6 changes: 3 additions & 3 deletions pkg/app/AppService.go
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ func (impl *AppServiceImpl) CheckIfPipelineUpdateEventIsValid(app *v1alpha1.Appl
// drop event
return isValid, pipeline, cdWfr, pipelineOverride, nil
}
deploymentConfig, err := impl.deploymentConfigService.GetConfigForDevtronApps(pipeline.AppId, pipeline.EnvironmentId)
deploymentConfig, err := impl.deploymentConfigService.GetConfigForDevtronApps(nil, pipeline.AppId, pipeline.EnvironmentId)
if err != nil {
impl.logger.Errorw("error in getting deployment config by appId and environmentId", "appId", pipeline.AppId, "environmentId", pipeline.EnvironmentId, "err", err)
return isValid, pipeline, cdWfr, pipelineOverride, err
Expand Down Expand Up @@ -787,7 +787,7 @@ type ValuesOverrideResponse struct {

func (impl *AppServiceImpl) CreateGitOpsRepo(app *app.App, targetRevision string, userId int32) (gitOpsRepoName string, chartGitAttr *commonBean.ChartGitAttribute, err error) {

deploymentConfig, err := impl.deploymentConfigService.GetConfigForDevtronApps(app.Id, 0)
deploymentConfig, err := impl.deploymentConfigService.GetConfigForDevtronApps(nil, app.Id, 0)
if err != nil {
impl.logger.Errorw("error in getting deployment config for devtron apps", "appId", app.Id, "err", err)
return "", nil, err
Expand Down Expand Up @@ -951,7 +951,7 @@ func (impl *AppServiceImpl) UpdateCdWorkflowRunnerByACDObject(app *v1alpha1.Appl
}
appId := wfr.CdWorkflow.Pipeline.AppId
envId := wfr.CdWorkflow.Pipeline.EnvironmentId
envDeploymentConfig, err := impl.deploymentConfigService.GetConfigForDevtronApps(appId, envId)
envDeploymentConfig, err := impl.deploymentConfigService.GetConfigForDevtronApps(nil, appId, envId)
if err != nil {
impl.logger.Errorw("error in fetching environment deployment config by appId and envId", "appId", appId, "envId", envId, "err", err)
return err
Expand Down
2 changes: 1 addition & 1 deletion pkg/app/status/PipelineStatusTimelineService.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ func (impl *PipelineStatusTimelineServiceImpl) FetchTimelines(appId, envId, wfrI
triggeredBy = wfr.TriggeredBy
wfrStatus = wfr.Status

envDeploymentConfig, err := impl.deploymentConfigService.GetConfigForDevtronApps(appId, envId)
envDeploymentConfig, err := impl.deploymentConfigService.GetConfigForDevtronApps(nil, appId, envId)
if err != nil {
impl.logger.Errorw("error in fetching environment deployment config by appId and envId", "appId", appId, "envId", envId, "err", err)
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion pkg/appWorkflow/AppWorkflowService.go
Original file line number Diff line number Diff line change
Expand Up @@ -820,7 +820,7 @@ func (impl AppWorkflowServiceImpl) FindCdPipelinesByAppId(appId int) (*bean.CdPi
}

for _, pipeline := range dbPipelines {
envDeploymentConfig, err := impl.deploymentConfigService.GetConfigForDevtronApps(appId, pipeline.EnvironmentId)
envDeploymentConfig, err := impl.deploymentConfigService.GetConfigForDevtronApps(nil, appId, pipeline.EnvironmentId)
if err != nil {
impl.Logger.Errorw("error in fetching environment deployment config by appId and envId", "appId", appId, "envId", pipeline.EnvironmentId, "err", err)
return nil, err
Expand Down
Loading