Skip to content

Commit 58c3175

Browse files
committed
fix: Missing argocd application update event if there are no histories
1 parent 200fd83 commit 58c3175

1 file changed

Lines changed: 23 additions & 29 deletions

File tree

kubewatch/pkg/resource/application/handler.go

Lines changed: 23 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -53,52 +53,46 @@ func (impl *InformerImpl) GetSharedInformer(clusterLabels *informerBean.ClusterL
5353

5454
_, err := acdInformer.AddEventHandler(cache.ResourceEventHandlerFuncs{
5555
AddFunc: func(obj interface{}) {
56-
impl.logger.Debug("app added")
57-
58-
if app, ok := obj.(*applicationBean.Application); ok {
59-
impl.logger.Debugf("new app detected: %s, status: %s", app.Name, app.Status.Health.Status)
60-
}
56+
impl.logger.Debugw("ARGO_CD_APPLICATION: new application object found")
6157
},
6258
UpdateFunc: func(old interface{}, new interface{}) {
63-
impl.logger.Debug("app update detected")
59+
impl.logger.Debugw("ARGO_CD_APPLICATION: application object update detected")
6460
statusTime := time.Now()
6561
if oldApp, ok := old.(*applicationBean.Application); ok {
6662
if newApp, ok := new.(*applicationBean.Application); ok {
67-
if newApp.Status.History != nil && len(newApp.Status.History) > 0 {
68-
if oldApp.Status.History == nil || len(oldApp.Status.History) == 0 {
69-
impl.logger.Debug("new deployment detected")
63+
if len(oldApp.Status.History) < len(newApp.Status.History) {
64+
impl.logger.Debugw("ARGO_CD_APPLICATION: new deployment detected", "appName", newApp.Name, "status", newApp.Status.Health.Status)
65+
impl.sendAppUpdate(clusterLabels.ClusterId, newApp, statusTime)
66+
} else {
67+
impl.logger.Debugw("ARGO_CD_APPLICATION: old deployment detected for update", "appName", oldApp.Name, "status", oldApp.Status.Health.Status)
68+
oldRevision := oldApp.Status.Sync.Revision
69+
newRevision := newApp.Status.Sync.Revision
70+
oldStatus := string(oldApp.Status.Health.Status)
71+
newStatus := string(newApp.Status.Health.Status)
72+
newSyncStatus := string(newApp.Status.Sync.Status)
73+
oldSyncStatus := string(oldApp.Status.Sync.Status)
74+
if (oldRevision != newRevision) || (oldStatus != newStatus) || (newSyncStatus != oldSyncStatus) {
7075
impl.sendAppUpdate(clusterLabels.ClusterId, newApp, statusTime)
76+
impl.logger.Debugw("ARGO_CD_APPLICATION: send update event for application object", "appName", oldApp.Name, "oldRevision", oldRevision, "newRevision",
77+
newRevision, "oldStatus", oldStatus, "newStatus", newStatus,
78+
"newSyncStatus", newSyncStatus, "oldSyncStatus", oldSyncStatus)
7179
} else {
72-
impl.logger.Debugf("old deployment detected for update: %s, status:%s", oldApp.Name, oldApp.Status.Health.Status)
73-
oldRevision := oldApp.Status.Sync.Revision
74-
newRevision := newApp.Status.Sync.Revision
75-
oldStatus := string(oldApp.Status.Health.Status)
76-
newStatus := string(newApp.Status.Health.Status)
77-
newSyncStatus := string(newApp.Status.Sync.Status)
78-
oldSyncStatus := string(oldApp.Status.Sync.Status)
79-
if (oldRevision != newRevision) || (oldStatus != newStatus) || (newSyncStatus != oldSyncStatus) {
80-
impl.sendAppUpdate(clusterLabels.ClusterId, newApp, statusTime)
81-
impl.logger.Debug("send update app:" + oldApp.Name + ", oldRevision: " + oldRevision + ", newRevision:" +
82-
newRevision + ", oldStatus: " + oldStatus + ", newStatus: " + newStatus +
83-
", newSyncStatus: " + newSyncStatus + ", oldSyncStatus: " + oldSyncStatus)
84-
} else {
85-
impl.logger.Debug("skip updating app:" + oldApp.Name + ", oldRevision: " + oldRevision + ", newRevision:" +
86-
newRevision + ", oldStatus: " + oldStatus + ", newStatus: " + newStatus +
87-
", newSyncStatus: " + newSyncStatus + ", oldSyncStatus: " + oldSyncStatus)
88-
}
80+
impl.logger.Debugw("ARGO_CD_APPLICATION: skip updating event for application object", "appName", oldApp.Name, "oldRevision", oldRevision, "newRevision",
81+
newRevision, "oldStatus", oldStatus, "newStatus", newStatus,
82+
"newSyncStatus", newSyncStatus, "oldSyncStatus", oldSyncStatus)
8983
}
9084
}
9185
} else {
92-
log.Println("app update detected, but skip updating, there is no new app")
86+
impl.logger.Errorw("ARGO_CD_APPLICATION: application object update detected, but could not cast to application object", "oldObj", old, "newObj", new)
9387
}
9488
} else {
95-
log.Println("app update detected, but skip updating, there is no old app")
89+
impl.logger.Errorw("ARGO_CD_APPLICATION: application object update detected, but could not cast to application object", "oldObj", old)
9690
}
9791
},
9892
DeleteFunc: func(obj interface{}) {
9993
if app, ok := obj.(*applicationBean.Application); ok {
10094
statusTime := time.Now()
101-
impl.logger.Debugf("app delete detected: %s, status:%s", app.Name, app.Status.Health.Status)
95+
impl.logger.Debugw("ARGO_CD_APPLICATION: application object delete detected", "appName", app.Name, "status", app.Status.Health.Status)
10296
impl.sendAppDelete(clusterLabels.ClusterId, app, statusTime)
10397
}
10498
},

0 commit comments

Comments
 (0)