Skip to content

chore: chart service crud and configProperties #6642

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

Open
wants to merge 14 commits into
base: develop
Choose a base branch
from
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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should create add a new method GetConfigForDevtronAppsWiithTx to the interface and internally handle nil param.

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
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 @@ -486,7 +486,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 @@ -785,7 +785,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 @@ -949,7 +949,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 @@ -225,7 +225,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