Skip to content

Commit ceb4e2f

Browse files
committed
code review changes:- deploymentConfigService
1 parent 04f0516 commit ceb4e2f

File tree

5 files changed

+46
-9
lines changed

5 files changed

+46
-9
lines changed

internal/sql/repository/deploymentConfig/repository.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package deploymentConfig
1818

1919
import (
20+
"github.com/devtron-labs/devtron/internal/sql/repository/helper"
2021
"github.com/devtron-labs/devtron/pkg/sql"
2122
"github.com/go-pg/pg"
2223
"github.com/go-pg/pg/orm"
@@ -63,6 +64,7 @@ type Repository interface {
6364
GetByAppIdAndEnvIdEvenIfInactive(appId, envId int) (*DeploymentConfig, error)
6465
UpdateRepoUrlByAppIdAndEnvId(repoUrl string, appId, envId int) error
6566
GetConfigByAppIds(appIds []int) ([]*DeploymentConfig, error)
67+
GetDeploymentAppTypeForChartStoreAppByAppId(appId int) (string, error)
6668
}
6769

6870
type RepositoryImpl struct {
@@ -203,3 +205,16 @@ func (impl *RepositoryImpl) GetConfigByAppIds(appIds []int) ([]*DeploymentConfig
203205
Select()
204206
return results, err
205207
}
208+
209+
func (impl *RepositoryImpl) GetDeploymentAppTypeForChartStoreAppByAppId(appId int) (string, error) {
210+
result := &DeploymentConfig{}
211+
err := impl.dbConnection.Model(result).
212+
Join("inner join app a").
213+
JoinOn("deployment_config.app_id = a.id").
214+
Where("deployment_config.app_id = ? ", appId).
215+
Where("deployment_config.active = ?", true).
216+
Where("a.active = ?", true).
217+
Where("a.app_type = ? ", helper.ChartStoreApp).
218+
Select()
219+
return result.DeploymentAppType, err
220+
}

pkg/app/AppCrudOperationService.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ func (impl AppCrudOperationServiceImpl) getAppAndProjectForAppIdentifier(appIden
497497
}
498498
// there can be a case when an app whose installed_app is deployed via argocd and same appName is also deployed externally
499499
// via helm then we need to check if app model found is not deployed by argocd.
500-
isManagedByArgocd, err := impl.installedAppDbService.IsInstalledAppManagedByArgoCd(app.Id)
500+
isManagedByArgocd, err := impl.installedAppDbService.IsChartStoreAppManagedByArgoCd(app.Id)
501501
if err != nil {
502502
impl.logger.Errorw("error in checking if installed app linked to this app is managed via argocd or not ", "appId", app.Id, "err", err)
503503
return app, false, err

pkg/appStore/installedApp/read/InstalledAppReadEAService.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package read
22

33
import (
4+
"github.com/devtron-labs/devtron/internal/util"
45
"github.com/devtron-labs/devtron/pkg/appStore/installedApp/read/adapter"
56
"github.com/devtron-labs/devtron/pkg/appStore/installedApp/read/bean"
67
"github.com/devtron-labs/devtron/pkg/appStore/installedApp/repository"
@@ -32,6 +33,8 @@ type InstalledAppReadServiceEA interface {
3233
// Additional details like app store details are also fetched.
3334
// Refer bean.InstalledAppVersionWithAppStoreDetails for more details.
3435
GetInstalledAppVersionIncludingDeleted(installedAppVersionId int) (*bean.InstalledAppVersionWithAppStoreDetails, error)
36+
// IsChartStoreAppManagedByArgoCd returns if a chart store app is deployed via argo-cd or not
37+
IsChartStoreAppManagedByArgoCd(appId int) (bool, error)
3538
}
3639

3740
type InstalledAppReadServiceEAImpl struct {
@@ -97,3 +100,12 @@ func (impl *InstalledAppReadServiceEAImpl) GetInstalledAppVersionIncludingDelete
97100
}
98101
return adapter.GetInstalledAppVersionWithAppStoreDetails(installedAppVersionModel), nil
99102
}
103+
104+
func (impl *InstalledAppReadServiceEAImpl) IsChartStoreAppManagedByArgoCd(appId int) (bool, error) {
105+
installedAppModel, err := impl.installedAppRepository.GetInstalledAppsMinByAppId(appId)
106+
if err != nil {
107+
impl.logger.Errorw("error while fetching installed apps by app id", "appId", appId, "error", err)
108+
return false, err
109+
}
110+
return util.IsAcdApp(installedAppModel.DeploymentAppType), nil
111+
}

pkg/appStore/installedApp/service/EAMode/InstalledAppDBService.go

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ type InstalledAppDBService interface {
7070
GetInstalledAppVersionHistoryByVersionId(id int) ([]*appStoreRepo.InstalledAppVersionHistory, error)
7171
UpdateDeploymentHistoryMessage(installedAppVersionHistoryId int, message string) error
7272

73-
IsInstalledAppManagedByArgoCd(appId int) (bool, error)
73+
IsChartStoreAppManagedByArgoCd(appId int) (bool, error)
7474
}
7575

7676
type InstalledAppDBServiceImpl struct {
@@ -536,11 +536,6 @@ func (impl *InstalledAppDBServiceImpl) MarkInstalledAppVersionModelInActive(inst
536536
return nil
537537
}
538538

539-
func (impl *InstalledAppDBServiceImpl) IsInstalledAppManagedByArgoCd(appId int) (bool, error) {
540-
installedApp, err := impl.InstalledAppRepository.GetInstalledAppsMinByAppId(appId)
541-
if err != nil {
542-
impl.Logger.Errorw("error while fetching installed_app min data by appId", "appId", appId, "error", err)
543-
return false, err
544-
}
545-
return util.IsAcdApp(installedApp.DeploymentAppType), nil
539+
func (impl *InstalledAppDBServiceImpl) IsChartStoreAppManagedByArgoCd(appId int) (bool, error) {
540+
return impl.deploymentConfigService.IsChartStoreAppManagedByArgoCd(appId)
546541
}

pkg/deployment/common/deploymentConfigService.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ type DeploymentConfigService interface {
3939
GetConfigForDevtronApps(appId, envId int) (*bean.DeploymentConfig, error)
4040
GetAndMigrateConfigIfAbsentForDevtronApps(appId, envId int) (*bean.DeploymentConfig, error)
4141
GetConfigForHelmApps(appId, envId int) (*bean.DeploymentConfig, error)
42+
IsChartStoreAppManagedByArgoCd(appId int) (bool, error)
4243
GetConfigEvenIfInactive(appId, envId int) (*bean.DeploymentConfig, error)
4344
GetAndMigrateConfigIfAbsentForHelmApp(appId, envId int) (*bean.DeploymentConfig, error)
4445
GetAppLevelConfigForDevtronApp(appId int) (*bean.DeploymentConfig, error)
@@ -387,6 +388,20 @@ func (impl *DeploymentConfigServiceImpl) GetConfigForHelmApps(appId, envId int)
387388
return ConvertDeploymentConfigDbObjToDTO(helmDeploymentConfig), nil
388389
}
389390

391+
func (impl *DeploymentConfigServiceImpl) IsChartStoreAppManagedByArgoCd(appId int) (bool, error) {
392+
if impl.deploymentServiceTypeConfig.UseDeploymentConfigData {
393+
return impl.installedAppReadService.IsChartStoreAppManagedByArgoCd(appId)
394+
}
395+
deploymentAppType, err := impl.deploymentConfigRepository.GetDeploymentAppTypeForChartStoreAppByAppId(appId)
396+
if err != nil && !util2.IsErrNoRows(err) {
397+
impl.logger.Errorw("error in GetDeploymentAppTypeForChartStoreAppByAppId", "appId", appId, "err", err)
398+
return false, err
399+
} else if util2.IsErrNoRows(err) {
400+
return impl.installedAppReadService.IsChartStoreAppManagedByArgoCd(appId)
401+
}
402+
return util2.IsAcdApp(deploymentAppType), nil
403+
}
404+
390405
func (impl *DeploymentConfigServiceImpl) GetConfigEvenIfInactive(appId, envId int) (*bean.DeploymentConfig, error) {
391406
config, err := impl.deploymentConfigRepository.GetByAppIdAndEnvIdEvenIfInactive(appId, envId)
392407
if err != nil {

0 commit comments

Comments
 (0)