Skip to content

Commit 5e69e60

Browse files
fix: nats clients panic in ea-mode (#4162)
* ea-wire-fix * workflow-status-healthy * config-status * helm install status config update * remving on update * update history on update release * install-version-request * group-chart-update * removed response flag and cm * refactoring * config change
1 parent 29a6ce2 commit 5e69e60

File tree

6 files changed

+115
-58
lines changed

6 files changed

+115
-58
lines changed

cmd/external-app/wire.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ package main
55

66
import (
77
"github.com/devtron-labs/authenticator/middleware"
8-
pubsub_lib "github.com/devtron-labs/common-lib/pubsub-lib"
98
util4 "github.com/devtron-labs/common-lib/utils/k8s"
109
"github.com/devtron-labs/devtron/api/apiToken"
1110
chartProvider "github.com/devtron-labs/devtron/api/appStore/chartProvider"
@@ -185,7 +184,7 @@ func InitializeApp() (*App, error) {
185184

186185
security2.NewScanToolMetadataRepositoryImpl,
187186
wire.Bind(new(security2.ScanToolMetadataRepository), new(*security2.ScanToolMetadataRepositoryImpl)),
188-
pubsub_lib.NewPubSubClientServiceImpl,
187+
//pubsub_lib.NewPubSubClientServiceImpl,
189188

190189
// start: docker registry wire set injection
191190
router.NewDockerRegRouterImpl,

cmd/external-app/wire_gen.go

Lines changed: 1 addition & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/appStore/deployment/fullMode/AppStoreDeploymentFullModeService.go

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"context"
2222
"encoding/json"
2323
"fmt"
24+
"github.com/devtron-labs/common-lib/pubsub-lib"
2425
"path"
2526
"regexp"
2627
"time"
@@ -66,6 +67,7 @@ type AppStoreDeploymentFullModeService interface {
6667
UpdateValuesYaml(installAppVersionRequest *appStoreBean.InstallAppVersionDTO, tx *pg.Tx) (*appStoreBean.InstallAppVersionDTO, error)
6768
UpdateRequirementYaml(installAppVersionRequest *appStoreBean.InstallAppVersionDTO, appStoreAppVersion *appStoreDiscoverRepository.AppStoreApplicationVersion) error
6869
GetGitOpsRepoName(appName string, environmentName string) (string, error)
70+
SubscribeHelmInstallStatus() error
6971
}
7072

7173
type AppStoreDeploymentFullModeServiceImpl struct {
@@ -87,6 +89,8 @@ type AppStoreDeploymentFullModeServiceImpl struct {
8789
pipelineStatusTimelineService status.PipelineStatusTimelineService
8890
appStoreDeploymentCommonService appStoreDeploymentCommon.AppStoreDeploymentCommonService
8991
argoClientWrapperService argocdServer.ArgoClientWrapperService
92+
pubSubClient *pubsub_lib.PubSubClientServiceImpl
93+
installedAppRepositoryHistory repository4.InstalledAppVersionHistoryRepository
9094
}
9195

9296
func NewAppStoreDeploymentFullModeServiceImpl(logger *zap.SugaredLogger,
@@ -103,8 +107,10 @@ func NewAppStoreDeploymentFullModeServiceImpl(logger *zap.SugaredLogger,
103107
pipelineStatusTimelineService status.PipelineStatusTimelineService,
104108
appStoreDeploymentCommonService appStoreDeploymentCommon.AppStoreDeploymentCommonService,
105109
argoClientWrapperService argocdServer.ArgoClientWrapperService,
110+
pubSubClient *pubsub_lib.PubSubClientServiceImpl,
111+
installedAppRepositoryHistory repository4.InstalledAppVersionHistoryRepository,
106112
) *AppStoreDeploymentFullModeServiceImpl {
107-
return &AppStoreDeploymentFullModeServiceImpl{
113+
appStoreDeploymentFullModeServiceImpl := &AppStoreDeploymentFullModeServiceImpl{
108114
logger: logger,
109115
chartTemplateService: chartTemplateService,
110116
refChartDir: refChartDir,
@@ -123,7 +129,14 @@ func NewAppStoreDeploymentFullModeServiceImpl(logger *zap.SugaredLogger,
123129
pipelineStatusTimelineService: pipelineStatusTimelineService,
124130
appStoreDeploymentCommonService: appStoreDeploymentCommonService,
125131
argoClientWrapperService: argoClientWrapperService,
132+
pubSubClient: pubSubClient,
133+
installedAppRepositoryHistory: installedAppRepositoryHistory,
126134
}
135+
err := appStoreDeploymentFullModeServiceImpl.SubscribeHelmInstallStatus()
136+
if err != nil {
137+
return nil
138+
}
139+
return appStoreDeploymentFullModeServiceImpl
127140
}
128141

129142
func (impl AppStoreDeploymentFullModeServiceImpl) AppStoreDeployOperationGIT(installAppVersionRequest *appStoreBean.InstallAppVersionDTO, tx *pg.Tx) (*appStoreBean.InstallAppVersionDTO, *util.ChartGitAttribute, error) {
@@ -487,3 +500,41 @@ func (impl AppStoreDeploymentFullModeServiceImpl) UpdateRequirementYaml(installA
487500

488501
return nil
489502
}
503+
504+
func (impl AppStoreDeploymentFullModeServiceImpl) SubscribeHelmInstallStatus() error {
505+
506+
callback := func(msg *pubsub_lib.PubSubMsg) {
507+
508+
impl.logger.Debug("received helm install status event - HELM_INSTALL_STATUS", "data", msg.Data)
509+
helmInstallNatsMessage := &appStoreBean.HelmReleaseStatusConfig{}
510+
err := json.Unmarshal([]byte(msg.Data), helmInstallNatsMessage)
511+
if err != nil {
512+
impl.logger.Errorw("error in unmarshalling helm install status nats message", "err", err)
513+
return
514+
}
515+
516+
installedAppVersionHistory, err := impl.installedAppRepositoryHistory.GetInstalledAppVersionHistory(helmInstallNatsMessage.InstallAppVersionHistoryId)
517+
if err != nil {
518+
impl.logger.Errorw("error in fetching installed app by installed app id in subscribe helm status callback", "err", err)
519+
return
520+
}
521+
if helmInstallNatsMessage.ErrorInInstallation {
522+
installedAppVersionHistory.Status = pipelineConfig.WorkflowFailed
523+
} else {
524+
installedAppVersionHistory.Status = pipelineConfig.WorkflowSucceeded
525+
}
526+
installedAppVersionHistory.HelmReleaseStatusConfig = msg.Data
527+
_, err = impl.installedAppRepositoryHistory.UpdateInstalledAppVersionHistory(installedAppVersionHistory, nil)
528+
if err != nil {
529+
impl.logger.Errorw("error in updating helm release status data in installedAppVersionHistoryRepository", "err", err)
530+
return
531+
}
532+
}
533+
534+
err := impl.pubSubClient.Subscribe(pubsub_lib.HELM_CHART_INSTALL_STATUS_TOPIC, callback)
535+
if err != nil {
536+
impl.logger.Error(err)
537+
return err
538+
}
539+
return nil
540+
}

pkg/appStore/deployment/service/AppStoreDeploymentService.go

Lines changed: 59 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -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

8179
type 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

8584
func 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

113111
func 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+
}
10561091
func (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-
16981708
func (impl AppStoreDeploymentServiceImpl) UpdateInstallAppVersionHistoryStatus(installedAppVersionHistoryId int, status string) error {
16991709
dbConnection := impl.installedAppRepository.GetConnection()
17001710
tx, err := dbConnection.Begin()

pkg/appStore/deployment/tool/AppStoreDeploymentHelmService.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,6 @@ func (impl AppStoreDeploymentHelmServiceImpl) InstallApp(installAppVersionReques
135135
if err != nil {
136136
return installAppVersionRequest, err
137137
}
138-
139138
return installAppVersionRequest, nil
140139
}
141140

0 commit comments

Comments
 (0)