@@ -18,6 +18,7 @@ package common
18
18
19
19
import (
20
20
"errors"
21
+ "fmt"
21
22
"github.com/devtron-labs/common-lib/utils/k8s/commonBean"
22
23
"github.com/devtron-labs/devtron/client/argocdServer"
23
24
appRepository "github.com/devtron-labs/devtron/internal/sql/repository/app"
@@ -27,16 +28,16 @@ import (
27
28
installedAppReader "github.com/devtron-labs/devtron/pkg/appStore/installedApp/read"
28
29
bean3 "github.com/devtron-labs/devtron/pkg/auth/user/bean"
29
30
chartRepoRepository "github.com/devtron-labs/devtron/pkg/chartRepo/repository"
30
- bean2 "github.com/devtron-labs/devtron/pkg/cluster/bean"
31
+ clusterBean "github.com/devtron-labs/devtron/pkg/cluster/bean"
31
32
bean4 "github.com/devtron-labs/devtron/pkg/cluster/environment/bean"
32
33
"github.com/devtron-labs/devtron/pkg/cluster/environment/repository"
33
34
"github.com/devtron-labs/devtron/pkg/deployment/common/adapter"
34
35
"github.com/devtron-labs/devtron/pkg/deployment/common/bean"
35
36
commonErr "github.com/devtron-labs/devtron/pkg/deployment/common/errors"
36
37
read2 "github.com/devtron-labs/devtron/pkg/deployment/common/read"
37
38
"github.com/devtron-labs/devtron/pkg/deployment/manifest/deploymentTemplate/read"
39
+ util3 "github.com/devtron-labs/devtron/pkg/util"
38
40
"github.com/devtron-labs/devtron/util"
39
- "github.com/devtron-labs/devtron/util/sliceUtil"
40
41
"github.com/go-pg/pg"
41
42
"go.uber.org/zap"
42
43
"path/filepath"
@@ -53,7 +54,7 @@ type DeploymentConfigService interface {
53
54
UpdateRepoUrlForAppAndEnvId (repoURL string , appId , envId int ) error
54
55
GetConfigsByAppIds (appIds []int ) ([]* bean.DeploymentConfig , error )
55
56
UpdateChartLocationInDeploymentConfig (appId , envId , chartRefId int , userId int32 , chartVersion string ) error
56
- GetAllArgoAppNamesByCluster (clusterIds []int ) ([]string , error )
57
+ GetAllArgoAppNamesByCluster (clusterIds []int ) ([]* bean. DevtronArgoCdAppInfo , error )
57
58
GetExternalReleaseType (appId , environmentId int ) (bean.ExternalReleaseType , error )
58
59
CheckIfURLAlreadyPresent (repoURL string ) (bool , error )
59
60
FilterPipelinesByApplicationClusterIdAndNamespace (pipelines []pipelineConfig.Pipeline , applicationObjectClusterId int , applicationObjectNamespace string ) (pipelineConfig.Pipeline , error )
@@ -71,6 +72,7 @@ type DeploymentConfigServiceImpl struct {
71
72
environmentRepository repository.EnvironmentRepository
72
73
chartRefRepository chartRepoRepository.ChartRefRepository
73
74
deploymentConfigReadService read2.DeploymentConfigReadService
75
+ acdAuthConfig * util3.ACDAuthConfig
74
76
}
75
77
76
78
func NewDeploymentConfigServiceImpl (
@@ -85,6 +87,7 @@ func NewDeploymentConfigServiceImpl(
85
87
environmentRepository repository.EnvironmentRepository ,
86
88
chartRefRepository chartRepoRepository.ChartRefRepository ,
87
89
deploymentConfigReadService read2.DeploymentConfigReadService ,
90
+ acdAuthConfig * util3.ACDAuthConfig ,
88
91
) * DeploymentConfigServiceImpl {
89
92
90
93
return & DeploymentConfigServiceImpl {
@@ -99,6 +102,7 @@ func NewDeploymentConfigServiceImpl(
99
102
environmentRepository : environmentRepository ,
100
103
chartRefRepository : chartRefRepository ,
101
104
deploymentConfigReadService : deploymentConfigReadService ,
105
+ acdAuthConfig : acdAuthConfig ,
102
106
}
103
107
}
104
108
@@ -327,21 +331,47 @@ func (impl *DeploymentConfigServiceImpl) UpdateChartLocationInDeploymentConfig(a
327
331
return nil
328
332
}
329
333
330
- func (impl * DeploymentConfigServiceImpl ) GetAllArgoAppNamesByCluster (clusterIds []int ) ([]string , error ) {
331
- allDevtronManagedArgoAppNames := make ([]string , 0 )
332
- devtronArgoAppNames , err := impl .pipelineRepository .GetAllArgoAppNamesByCluster (clusterIds )
334
+ func (impl * DeploymentConfigServiceImpl ) GetAllArgoAppNamesByCluster (clusterIds []int ) ([]* bean.DevtronArgoCdAppInfo , error ) {
335
+ allDevtronManagedArgoAppsInfo := make ([]* bean.DevtronArgoCdAppInfo , 0 )
336
+ linkedReleaseConfig , err := impl .getAllEnvLevelConfigsForLinkedReleases ()
337
+ if err != nil {
338
+ impl .logger .Errorw ("error while fetching linked release configs" , "clusterIds" , clusterIds , "error" , err )
339
+ return allDevtronManagedArgoAppsInfo , err
340
+ }
341
+ linkedReleaseConfigMap := make (map [string ]* bean.DeploymentConfig )
342
+ for _ , config := range linkedReleaseConfig {
343
+ uniqueKey := fmt .Sprintf ("%d-%d" , config .AppId , config .EnvironmentId )
344
+ linkedReleaseConfigMap [uniqueKey ] = config
345
+ }
346
+ devtronArgoAppsInfo , err := impl .pipelineRepository .GetAllArgoAppNamesByCluster (clusterIds )
333
347
if err != nil {
334
348
impl .logger .Errorw ("error while fetching argo app names" , "clusterIds" , clusterIds , "error" , err )
335
- return allDevtronManagedArgoAppNames , err
349
+ return allDevtronManagedArgoAppsInfo , err
350
+ }
351
+ for _ , acdAppInfo := range devtronArgoAppsInfo {
352
+ uniqueKey := fmt .Sprintf ("%d-%d" , acdAppInfo .AppId , acdAppInfo .EnvironmentId )
353
+ var devtronArgoCdAppInfo * bean.DevtronArgoCdAppInfo
354
+ if config , ok := linkedReleaseConfigMap [uniqueKey ]; ok &&
355
+ config .IsAcdRelease () && config .IsLinkedRelease () {
356
+ acdAppClusterId := config .GetApplicationObjectClusterId ()
357
+ acdDefaultNamespace := config .GetApplicationObjectNamespace ()
358
+ devtronArgoCdAppInfo = adapter .GetDevtronArgoCdAppInfo (acdAppInfo .DeploymentAppName , acdAppClusterId , acdDefaultNamespace )
359
+ } else {
360
+ devtronArgoCdAppInfo = adapter .GetDevtronArgoCdAppInfo (acdAppInfo .DeploymentAppName , clusterBean .DefaultClusterId , impl .acdAuthConfig .ACDConfigMapNamespace )
361
+ }
362
+ allDevtronManagedArgoAppsInfo = append (allDevtronManagedArgoAppsInfo , devtronArgoCdAppInfo )
336
363
}
337
- allDevtronManagedArgoAppNames = append (allDevtronManagedArgoAppNames , devtronArgoAppNames ... )
338
364
chartStoreArgoAppNames , err := impl .installedAppReadService .GetAllArgoAppNamesByCluster (clusterIds )
339
365
if err != nil {
340
366
impl .logger .Errorw ("error while fetching argo app names from chart store" , "clusterIds" , clusterIds , "error" , err )
341
- return allDevtronManagedArgoAppNames , err
367
+ return allDevtronManagedArgoAppsInfo , err
342
368
}
343
- allDevtronManagedArgoAppNames = append (allDevtronManagedArgoAppNames , chartStoreArgoAppNames ... )
344
- return sliceUtil .GetUniqueElements (allDevtronManagedArgoAppNames ), nil
369
+ for _ , chartStoreArgoAppName := range chartStoreArgoAppNames {
370
+ // NOTE: Chart Store doesn't support linked releases
371
+ chartStoreArgoCdAppInfo := adapter .GetDevtronArgoCdAppInfo (chartStoreArgoAppName , clusterBean .DefaultClusterId , impl .acdAuthConfig .ACDConfigMapNamespace )
372
+ allDevtronManagedArgoAppsInfo = append (allDevtronManagedArgoAppsInfo , chartStoreArgoCdAppInfo )
373
+ }
374
+ return allDevtronManagedArgoAppsInfo , nil
345
375
}
346
376
347
377
func (impl * DeploymentConfigServiceImpl ) GetExternalReleaseType (appId , environmentId int ) (bean.ExternalReleaseType , error ) {
@@ -358,7 +388,7 @@ func (impl *DeploymentConfigServiceImpl) GetExternalReleaseType(appId, environme
358
388
359
389
func (impl * DeploymentConfigServiceImpl ) CheckIfURLAlreadyPresent (repoURL string ) (bool , error ) {
360
390
//TODO: optimisation
361
- configs , err := impl .getAllConfigsWithCustomGitOpsURL ()
391
+ configs , err := impl .getAllAppLevelConfigsWithCustomGitOpsURL ()
362
392
if err != nil {
363
393
impl .logger .Errorw ("error in getting all configs" , "err" , err )
364
394
return false , err
@@ -486,7 +516,7 @@ func (impl *DeploymentConfigServiceImpl) parseReleaseConfigForHelmApps(appId int
486
516
Version : bean .Version ,
487
517
ArgoCDSpec : bean.ArgoCDSpec {
488
518
Metadata : bean.ApplicationMetadata {
489
- ClusterId : bean2 .DefaultClusterId ,
519
+ ClusterId : clusterBean .DefaultClusterId ,
490
520
Namespace : argocdServer .DevtronInstalationNs ,
491
521
},
492
522
Spec : bean.ApplicationSpec {
@@ -509,8 +539,8 @@ func (impl *DeploymentConfigServiceImpl) parseReleaseConfigForHelmApps(appId int
509
539
return releaseConfig , nil
510
540
}
511
541
512
- func (impl * DeploymentConfigServiceImpl ) getAllConfigsWithCustomGitOpsURL () ([]* bean.DeploymentConfig , error ) {
513
- dbConfigs , err := impl .deploymentConfigRepository .GetAllConfigs ()
542
+ func (impl * DeploymentConfigServiceImpl ) getAllAppLevelConfigsWithCustomGitOpsURL () ([]* bean.DeploymentConfig , error ) {
543
+ dbConfigs , err := impl .deploymentConfigRepository .GetAllAppLevelConfigs ()
514
544
if err != nil {
515
545
impl .logger .Errorw ("error in getting all configs with custom gitops url" , "err" , err )
516
546
return nil , err
@@ -527,6 +557,24 @@ func (impl *DeploymentConfigServiceImpl) getAllConfigsWithCustomGitOpsURL() ([]*
527
557
return configs , nil
528
558
}
529
559
560
+ func (impl * DeploymentConfigServiceImpl ) getAllEnvLevelConfigsForLinkedReleases () ([]* bean.DeploymentConfig , error ) {
561
+ dbConfigs , err := impl .deploymentConfigRepository .GetAllEnvLevelConfigsWithReleaseMode (util2 .PIPELINE_RELEASE_MODE_LINK )
562
+ if err != nil {
563
+ impl .logger .Errorw ("error in getting all env level configs with custom gitops url" , "err" , err )
564
+ return nil , err
565
+ }
566
+ configs := make ([]* bean.DeploymentConfig , 0 )
567
+ for _ , dbConfig := range dbConfigs {
568
+ config , err := adapter .ConvertDeploymentConfigDbObjToDTO (dbConfig )
569
+ if err != nil {
570
+ impl .logger .Error ("error in converting dbObj to dto" , "err" , err )
571
+ return nil , err
572
+ }
573
+ configs = append (configs , config )
574
+ }
575
+ return configs , nil
576
+ }
577
+
530
578
func (impl * DeploymentConfigServiceImpl ) GetConfigDBObj (appId , envId int ) (* deploymentConfig.DeploymentConfig , error ) {
531
579
var configDbObj * deploymentConfig.DeploymentConfig
532
580
var err error
0 commit comments