@@ -24,6 +24,7 @@ import (
24
24
"fmt"
25
25
"github.com/devtron-labs/common-lib/pubsub-lib/model"
26
26
"github.com/devtron-labs/devtron/pkg/app"
27
+ "k8s.io/utils/pointer"
27
28
"time"
28
29
29
30
"github.com/devtron-labs/devtron/internal/sql/repository/pipelineConfig"
@@ -74,7 +75,7 @@ func NewApplicationStatusHandlerImpl(logger *zap.SugaredLogger, pubsubClient *pu
74
75
}
75
76
err := appStatusUpdateHandlerImpl .Subscribe ()
76
77
if err != nil {
77
- //logger.Error("err", err)
78
+ // logger.Error("err", err)
78
79
return nil
79
80
}
80
81
err = appStatusUpdateHandlerImpl .SubscribeDeleteStatus ()
@@ -91,7 +92,6 @@ type ApplicationDetail struct {
91
92
92
93
func (impl * ApplicationStatusHandlerImpl ) Subscribe () error {
93
94
callback := func (msg * model.PubSubMsg ) {
94
- impl .logger .Debugw ("APP_STATUS_UPDATE_REQ" , "stage" , "raw" , "data" , msg .Data )
95
95
applicationDetail := ApplicationDetail {}
96
96
err := json .Unmarshal ([]byte (msg .Data ), & applicationDetail )
97
97
if err != nil {
@@ -109,10 +109,10 @@ func (impl *ApplicationStatusHandlerImpl) Subscribe() error {
109
109
_ , err = impl .pipelineRepository .GetArgoPipelineByArgoAppName (app .ObjectMeta .Name )
110
110
if err != nil && err == pg .ErrNoRows {
111
111
impl .logger .Infow ("this app not found in pipeline table looking in installed_apps table" , "appName" , app .ObjectMeta .Name )
112
- //if not found in pipeline table then search in installed_apps table
112
+ // if not found in pipeline table then search in installed_apps table
113
113
gitOpsDeployedAppNames , err := impl .installedAppRepository .GetAllGitOpsDeploymentAppName ()
114
114
if err != nil && err == pg .ErrNoRows {
115
- //no installed_apps found
115
+ // no installed_apps found
116
116
impl .logger .Errorw ("no installed apps found" , "err" , err )
117
117
return
118
118
} else if err != nil {
@@ -127,17 +127,17 @@ func (impl *ApplicationStatusHandlerImpl) Subscribe() error {
127
127
devtronGitOpsAppName = app .ObjectMeta .Name
128
128
}
129
129
if slices .Contains (gitOpsDeployedAppNames , devtronGitOpsAppName ) {
130
- //app found in installed_apps table hence setting flag to true
130
+ // app found in installed_apps table hence setting flag to true
131
131
isAppStoreApplication = true
132
132
} else {
133
- //app neither found in installed_apps nor in pipeline table hence returning
133
+ // app neither found in installed_apps nor in pipeline table hence returning
134
134
return
135
135
}
136
136
}
137
137
isSucceeded , pipelineOverride , err := impl .appService .UpdateDeploymentStatusAndCheckIsSucceeded (app , applicationDetail .StatusTime , isAppStoreApplication )
138
138
if err != nil {
139
139
impl .logger .Errorw ("error on application status update" , "err" , err , "msg" , string (msg .Data ))
140
- //TODO - check update for charts - fix this call
140
+ // TODO - check update for charts - fix this call
141
141
if err == pg .ErrNoRows {
142
142
// if not found in charts (which is for devtron apps) try to find in installed app (which is for devtron charts)
143
143
_ , err := impl .installedAppService .UpdateInstalledAppVersionStatus (app )
@@ -153,7 +153,10 @@ func (impl *ApplicationStatusHandlerImpl) Subscribe() error {
153
153
// invoke DagExecutor, for cd success which will trigger post stage if exist.
154
154
if isSucceeded {
155
155
impl .logger .Debugw ("git hash history" , "list" , app .Status .History )
156
- err = impl .workflowDagExecutor .HandleDeploymentSuccessEvent (pipelineOverride )
156
+ triggerContext := pipeline.TriggerContext {
157
+ ReferenceId : pointer .String (msg .MsgId ),
158
+ }
159
+ err = impl .workflowDagExecutor .HandleDeploymentSuccessEvent (triggerContext , pipelineOverride )
157
160
if err != nil {
158
161
impl .logger .Errorw ("deployment success event error" , "pipelineOverride" , pipelineOverride , "err" , err )
159
162
return
@@ -162,7 +165,13 @@ func (impl *ApplicationStatusHandlerImpl) Subscribe() error {
162
165
impl .logger .Debugw ("application status update completed" , "app" , app .Name )
163
166
}
164
167
165
- err := impl .pubsubClient .Subscribe (pubsub .APPLICATION_STATUS_UPDATE_TOPIC , callback )
168
+ // add required logging here
169
+ var loggerFunc pubsub.LoggerFunc = func (msg model.PubSubMsg ) (string , []interface {}) {
170
+ return "" , nil
171
+ }
172
+
173
+ validations := impl .workflowDagExecutor .GetTriggerValidateFuncs ()
174
+ err := impl .pubsubClient .Subscribe (pubsub .APPLICATION_STATUS_UPDATE_TOPIC , callback , loggerFunc , validations ... )
166
175
if err != nil {
167
176
impl .logger .Error (err )
168
177
return err
@@ -173,7 +182,6 @@ func (impl *ApplicationStatusHandlerImpl) Subscribe() error {
173
182
func (impl * ApplicationStatusHandlerImpl ) SubscribeDeleteStatus () error {
174
183
callback := func (msg * model.PubSubMsg ) {
175
184
176
- impl .logger .Debugw ("APP_STATUS_DELETE_REQ" , "stage" , "raw" , "data" , msg .Data )
177
185
applicationDetail := ApplicationDetail {}
178
186
err := json .Unmarshal ([]byte (msg .Data ), & applicationDetail )
179
187
if err != nil {
@@ -191,7 +199,18 @@ func (impl *ApplicationStatusHandlerImpl) SubscribeDeleteStatus() error {
191
199
impl .logger .Errorw ("error in updating pipeline delete status" , "err" , err , "appName" , app .Name )
192
200
}
193
201
}
194
- err := impl .pubsubClient .Subscribe (pubsub .APPLICATION_STATUS_DELETE_TOPIC , callback )
202
+
203
+ // add required logging here
204
+ var loggerFunc pubsub.LoggerFunc = func (msg model.PubSubMsg ) (string , []interface {}) {
205
+ applicationDetail := ApplicationDetail {}
206
+ err := json .Unmarshal ([]byte (msg .Data ), & applicationDetail )
207
+ if err != nil {
208
+ return "unmarshal error on app delete status" , []interface {}{"err" , err }
209
+ }
210
+ return "got message for application status delete" , []interface {}{"appName" , applicationDetail .Application .Name , "namespace" , applicationDetail .Application .Namespace , "deleteTimestamp" , applicationDetail .Application .DeletionTimestamp }
211
+ }
212
+
213
+ err := impl .pubsubClient .Subscribe (pubsub .APPLICATION_STATUS_DELETE_TOPIC , callback , loggerFunc )
195
214
if err != nil {
196
215
impl .logger .Errorw ("error in subscribing to argo application status delete topic" , "err" , err )
197
216
return err
@@ -210,7 +229,7 @@ func (impl *ApplicationStatusHandlerImpl) updateArgoAppDeleteStatus(app *v1alpha
210
229
return errors .New ("invalid nats message, pipeline already deleted" )
211
230
}
212
231
if err == pg .ErrNoRows {
213
- //Helm app deployed using argocd
232
+ // Helm app deployed using argocd
214
233
var gitHash string
215
234
if app .Operation != nil && app .Operation .Sync != nil {
216
235
gitHash = app .Operation .Sync .Revision
@@ -229,7 +248,7 @@ func (impl *ApplicationStatusHandlerImpl) updateArgoAppDeleteStatus(app *v1alpha
229
248
impl .logger .Errorw ("App not found in database" , "installedAppId" , model .InstalledAppId , "err" , err )
230
249
return fmt .Errorf ("app not found in database %s" , err )
231
250
} else if installedApp .DeploymentAppDeleteRequest == false {
232
- //TODO 4465 remove app from log after final RCA
251
+ // TODO 4465 remove app from log after final RCA
233
252
impl .logger .Infow ("Deployment delete not requested for app, not deleting app from DB" , "appName" , app .Name , "app" , app )
234
253
return nil
235
254
}
0 commit comments