@@ -23,7 +23,6 @@ import (
2323 "errors"
2424 "fmt"
2525 "github.com/caarlos0/env/v6"
26- pubsub "github.com/devtron-labs/common-lib/pubsub-lib"
2726 client "github.com/devtron-labs/devtron/api/helm-app"
2827 openapi "github.com/devtron-labs/devtron/api/helm-app/openapiClient"
2928 openapi2 "github.com/devtron-labs/devtron/api/openapi/openapiClient"
@@ -74,12 +73,12 @@ type AppStoreDeploymentService interface {
7473 UpdateProjectHelmApp (updateAppRequest * appStoreBean.UpdateProjectHelmAppDTO ) error
7574 UpdateNotesForInstalledApp (installAppId int , notes string ) (bool , error )
7675 UpdatePreviousDeploymentStatusForAppStore (installAppVersionRequest * appStoreBean.InstallAppVersionDTO , triggeredAt time.Time , err error ) error
77- SubscribeHelmInstallStatus () error
7876 UpdateInstallAppVersionHistoryStatus (installedAppVersionHistoryId int , status string ) error
7977}
8078
8179type DeploymentServiceTypeConfig struct {
82- IsInternalUse bool `env:"IS_INTERNAL_USE" envDefault:"false"`
80+ IsInternalUse bool `env:"IS_INTERNAL_USE" envDefault:"false"`
81+ HelmInstallASyncMode bool `env:"RUN_HELM_INSTALL_IN_ASYNC_MODE_HELM_APPS" envDefault:"false"`
8382}
8483
8584func GetDeploymentServiceTypeConfig () (* DeploymentServiceTypeConfig , error ) {
@@ -107,7 +106,6 @@ type AppStoreDeploymentServiceImpl struct {
107106 gitOpsRepository repository2.GitOpsConfigRepository
108107 deploymentTypeConfig * DeploymentServiceTypeConfig
109108 ChartTemplateService util.ChartTemplateService
110- pubSubClient * pubsub.PubSubClientServiceImpl
111109}
112110
113111func NewAppStoreDeploymentServiceImpl (logger * zap.SugaredLogger , installedAppRepository repository.InstalledAppRepository ,
@@ -118,7 +116,7 @@ func NewAppStoreDeploymentServiceImpl(logger *zap.SugaredLogger, installedAppRep
118116 clusterService cluster.ClusterService , helmAppService client.HelmAppService , appStoreDeploymentCommonService appStoreDeploymentCommon.AppStoreDeploymentCommonService ,
119117 globalEnvVariables * util2.GlobalEnvVariables ,
120118 installedAppRepositoryHistory repository.InstalledAppVersionHistoryRepository , gitOpsRepository repository2.GitOpsConfigRepository , attributesService attributes.AttributesService ,
121- deploymentTypeConfig * DeploymentServiceTypeConfig , ChartTemplateService util.ChartTemplateService , pubSubClient * pubsub. PubSubClientServiceImpl ) * AppStoreDeploymentServiceImpl {
119+ deploymentTypeConfig * DeploymentServiceTypeConfig , ChartTemplateService util.ChartTemplateService ) * AppStoreDeploymentServiceImpl {
122120
123121 appStoreDeploymentServiceImpl := & AppStoreDeploymentServiceImpl {
124122 logger : logger ,
@@ -139,11 +137,6 @@ func NewAppStoreDeploymentServiceImpl(logger *zap.SugaredLogger, installedAppRep
139137 gitOpsRepository : gitOpsRepository ,
140138 deploymentTypeConfig : deploymentTypeConfig ,
141139 ChartTemplateService : ChartTemplateService ,
142- pubSubClient : pubSubClient ,
143- }
144- err := appStoreDeploymentServiceImpl .SubscribeHelmInstallStatus ()
145- if err != nil {
146- return nil
147140 }
148141 return appStoreDeploymentServiceImpl
149142}
@@ -1022,7 +1015,6 @@ func (impl AppStoreDeploymentServiceImpl) linkHelmApplicationToChartStore(instal
10221015 if err != nil {
10231016 return nil , err
10241017 }
1025-
10261018 // STEP-3 install app DB post operations
10271019 installAppVersionRequest .DeploymentAppType = util .PIPELINE_DEPLOYMENT_TYPE_HELM
10281020 err = impl .installAppPostDbOperation (installAppVersionRequest )
@@ -1050,9 +1042,52 @@ func (impl AppStoreDeploymentServiceImpl) installAppPostDbOperation(installAppVe
10501042 return err
10511043 }
10521044 }
1045+ if ! impl .deploymentTypeConfig .HelmInstallASyncMode {
1046+ err = impl .updateInstalledAppVersionHistoryWithSync (installAppVersionRequest )
1047+ if err != nil {
1048+ impl .logger .Errorw ("error in updating installedApp History with sync " , "err" , err )
1049+ return err
1050+ }
1051+ }
10531052 return nil
10541053}
10551054
1055+ func (impl AppStoreDeploymentServiceImpl ) updateInstalledAppVersionHistoryWithSync (installAppVersionRequest * appStoreBean.InstallAppVersionDTO ) error {
1056+ if installAppVersionRequest .DeploymentAppType == util .PIPELINE_DEPLOYMENT_TYPE_MANIFEST_DOWNLOAD {
1057+ err := impl .UpdateInstalledAppVersionHistoryStatus (installAppVersionRequest , pipelineConfig .WorkflowSucceeded )
1058+ if err != nil {
1059+ impl .logger .Errorw ("error on creating history for chart deployment" , "error" , err )
1060+ return err
1061+ }
1062+ }
1063+
1064+ if installAppVersionRequest .DeploymentAppType == util .PIPELINE_DEPLOYMENT_TYPE_HELM {
1065+ installedAppVersionHistory , err := impl .installedAppRepositoryHistory .GetInstalledAppVersionHistory (installAppVersionRequest .InstalledAppVersionHistoryId )
1066+ if err != nil {
1067+ impl .logger .Errorw ("error in fetching installed app by installed app id in subscribe helm status callback" , "err" , err )
1068+ return err
1069+ }
1070+ installedAppVersionHistory .Status = pipelineConfig .WorkflowSucceeded
1071+ helmInstallStatus := & appStoreBean.HelmReleaseStatusConfig {
1072+ InstallAppVersionHistoryId : installedAppVersionHistory .Id ,
1073+ Message : "Release Installed" ,
1074+ IsReleaseInstalled : true ,
1075+ ErrorInInstallation : false ,
1076+ }
1077+ data , err := json .Marshal (helmInstallStatus )
1078+ if err != nil {
1079+ impl .logger .Errorw ("error in marshalling helmInstallStatus message" )
1080+ return err
1081+ }
1082+ installedAppVersionHistory .HelmReleaseStatusConfig = string (data )
1083+ _ , err = impl .installedAppRepositoryHistory .UpdateInstalledAppVersionHistory (installedAppVersionHistory , nil )
1084+ if err != nil {
1085+ impl .logger .Errorw ("error in updating helm release status data in installedAppVersionHistoryRepository" , "err" , err )
1086+ return err
1087+ }
1088+ }
1089+ return nil
1090+ }
10561091func (impl AppStoreDeploymentServiceImpl ) GetDeploymentHistory (ctx context.Context , installedApp * appStoreBean.InstallAppVersionDTO ) (* client.DeploymentHistoryAndInstalledAppInfo , error ) {
10571092 result := & client.DeploymentHistoryAndInstalledAppInfo {}
10581093 var err error
@@ -1529,6 +1564,12 @@ func (impl *AppStoreDeploymentServiceImpl) UpdateInstalledApp(ctx context.Contex
15291564 impl .logger .Errorw ("error on creating history for chart deployment" , "error" , err )
15301565 return nil , err
15311566 }
1567+ } else if util .IsHelmApp (installAppVersionRequest .DeploymentAppType ) && ! impl .deploymentTypeConfig .HelmInstallASyncMode {
1568+ err = impl .updateInstalledAppVersionHistoryWithSync (installAppVersionRequest )
1569+ if err != nil {
1570+ impl .logger .Errorw ("error in updating install app version history on sync" , "err" , err )
1571+ return nil , err
1572+ }
15321573 }
15331574
15341575 return installAppVersionRequest , nil
@@ -1577,6 +1618,13 @@ func (impl AppStoreDeploymentServiceImpl) InstallAppByHelm(installAppVersionRequ
15771618 impl .logger .Errorw ("error while installing app via helm" , "error" , err )
15781619 return installAppVersionRequest , err
15791620 }
1621+ if ! impl .deploymentTypeConfig .HelmInstallASyncMode {
1622+ err = impl .updateInstalledAppVersionHistoryWithSync (installAppVersionRequest )
1623+ if err != nil {
1624+ impl .logger .Errorw ("error in updating installed app version history with sync" , "err" , err )
1625+ return installAppVersionRequest , err
1626+ }
1627+ }
15801628 return installAppVersionRequest , nil
15811629}
15821630
@@ -1657,44 +1705,6 @@ func (impl AppStoreDeploymentServiceImpl) UpdatePreviousDeploymentStatusForAppSt
16571705 return nil
16581706}
16591707
1660- func (impl AppStoreDeploymentServiceImpl ) SubscribeHelmInstallStatus () error {
1661-
1662- callback := func (msg * pubsub.PubSubMsg ) {
1663-
1664- impl .logger .Debug ("received helm install status event - HELM_INSTALL_STATUS" , "data" , msg .Data )
1665- helmInstallNatsMessage := & appStoreBean.HelmReleaseStatusConfig {}
1666- err := json .Unmarshal ([]byte (msg .Data ), helmInstallNatsMessage )
1667- if err != nil {
1668- impl .logger .Errorw ("error in unmarshalling helm install status nats message" , "err" , err )
1669- return
1670- }
1671-
1672- installedAppVersionHistory , err := impl .installedAppRepositoryHistory .GetInstalledAppVersionHistory (helmInstallNatsMessage .InstallAppVersionHistoryId )
1673- if err != nil {
1674- impl .logger .Errorw ("error in fetching installed app by installed app id in subscribe helm status callback" , "err" , err )
1675- return
1676- }
1677- if helmInstallNatsMessage .ErrorInInstallation {
1678- installedAppVersionHistory .Status = pipelineConfig .WorkflowFailed
1679- } else {
1680- installedAppVersionHistory .Status = pipelineConfig .WorkflowSucceeded
1681- }
1682- installedAppVersionHistory .HelmReleaseStatusConfig = msg .Data
1683- _ , err = impl .installedAppRepositoryHistory .UpdateInstalledAppVersionHistory (installedAppVersionHistory , nil )
1684- if err != nil {
1685- impl .logger .Errorw ("error in updating helm release status data in installedAppVersionHistoryRepository" , "err" , err )
1686- return
1687- }
1688- }
1689-
1690- err := impl .pubSubClient .Subscribe (pubsub .HELM_CHART_INSTALL_STATUS_TOPIC , callback )
1691- if err != nil {
1692- impl .logger .Error (err )
1693- return err
1694- }
1695- return nil
1696- }
1697-
16981708func (impl AppStoreDeploymentServiceImpl ) UpdateInstallAppVersionHistoryStatus (installedAppVersionHistoryId int , status string ) error {
16991709 dbConnection := impl .installedAppRepository .GetConnection ()
17001710 tx , err := dbConnection .Begin ()
0 commit comments