Skip to content

Commit 3127716

Browse files
committed
fix: isNewDeploymentFound logic for application update event
1 parent b688faf commit 3127716

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

kubewatch/pkg/resource/application/bean.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,17 @@ type applicationDetail struct {
2727
ClusterId int `json:"clusterId"`
2828
}
2929

30+
// isNewDeploymentFound checks if a new deployment is found by comparing the history of old and new application objects.
31+
func isNewDeploymentFound(oldAppObj, newAppObj *v1alpha1.Application) bool {
32+
if len(oldAppObj.Status.History) < len(newAppObj.Status.History) {
33+
return true
34+
} else if len(oldAppObj.Status.History) != 0 && len(oldAppObj.Status.History) == len(newAppObj.Status.History) {
35+
return oldAppObj.Status.History.LastRevisionHistory().ID < newAppObj.Status.History.LastRevisionHistory().ID
36+
}
37+
return false
38+
}
39+
40+
// getApplicationLastSyncedResourcesCount returns the count of resources that were last synced in the application.
3041
func getApplicationLastSyncedResourcesCount(appObj *v1alpha1.Application) int {
3142
if appObj.Status.OperationState == nil || appObj.Status.OperationState.SyncResult == nil {
3243
return 0

kubewatch/pkg/resource/application/handler.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ func (impl *InformerImpl) GetSharedInformer(clusterLabels *informerBean.ClusterL
6060
statusTime := time.Now()
6161
if oldApp, ok := old.(*applicationBean.Application); ok {
6262
if newApp, ok := new.(*applicationBean.Application); ok {
63-
if len(oldApp.Status.History) < len(newApp.Status.History) {
63+
if isNewDeploymentFound(oldApp, newApp) {
6464
impl.logger.Debugw("ARGO_CD_APPLICATION: new deployment detected", "appName", newApp.Name, "status", newApp.Status.Health.Status)
6565
impl.sendAppUpdate(clusterLabels.ClusterId, newApp, statusTime)
6666
} else {

0 commit comments

Comments
 (0)