From 804420454945519fd97163706d3d1f219331092f Mon Sep 17 00:00:00 2001 From: andrii-codefresh Date: Wed, 9 Oct 2024 21:52:49 +0300 Subject: [PATCH] use proper revision source --- event_reporter/reporter/application_event_reporter.go | 10 +++++----- event_reporter/utils/app_revision.go | 8 ++++++++ 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/event_reporter/reporter/application_event_reporter.go b/event_reporter/reporter/application_event_reporter.go index 0260ae15657bd..2dd8aac7b7b22 100644 --- a/event_reporter/reporter/application_event_reporter.go +++ b/event_reporter/reporter/application_event_reporter.go @@ -87,7 +87,7 @@ func (s *applicationEventReporter) shouldSendResourceEvent(a *appv1.Application, return true } -func (r *applicationEventReporter) getApplicationManifests(ctx context.Context, a *appv1.Application, revision *string, logCtx *log.Entry) (*apiclient.ManifestResponse, bool) { +func (r *applicationEventReporter) getDesiredManifests(ctx context.Context, a *appv1.Application, revision *string, logCtx *log.Entry) (*apiclient.ManifestResponse, bool) { // get the desired state manifests of the application project := a.Spec.GetProject() desiredManifests, err := r.applicationServiceClient.GetManifests(ctx, &application.ApplicationManifestQuery{ @@ -138,10 +138,10 @@ func (s *applicationEventReporter) StreamApplicationEvents( logCtx.Info("getting desired manifests") - desiredManifests, manifestGenErr := s.getApplicationManifests(ctx, a, nil, logCtx) + desiredManifests, manifestGenErr := s.getDesiredManifests(ctx, a, nil, logCtx) - liveManifests, _ := s.getApplicationManifests(ctx, a, &a.Status.Sync.Revision, logCtx) - applicationVersions := liveManifests.GetApplicationVersions() + syncManifests, _ := s.getDesiredManifests(ctx, a, utils.GetOperationStateRevision(a), logCtx) + applicationVersions := syncManifests.GetApplicationVersions() logCtx.Info("getting parent application name") @@ -159,7 +159,7 @@ func (s *applicationEventReporter) StreamApplicationEvents( rs := utils.GetAppAsResource(a) - parentDesiredManifests, manifestGenErr := s.getApplicationManifests(ctx, parentApplicationEntity, nil, logCtx) + parentDesiredManifests, manifestGenErr := s.getDesiredManifests(ctx, parentApplicationEntity, nil, logCtx) // helm app hasnt revision // TODO: add check if it helm application diff --git a/event_reporter/utils/app_revision.go b/event_reporter/utils/app_revision.go index 161f37f20d5a2..f4bb1bcb232ae 100644 --- a/event_reporter/utils/app_revision.go +++ b/event_reporter/utils/app_revision.go @@ -65,6 +65,14 @@ func GetOperationRevision(a *appv1.Application) string { return revision } +func GetOperationStateRevision(a *appv1.Application) *string { + if a == nil || a.Status.OperationState == nil || a.Status.OperationState.SyncResult == nil { + return nil + } + + return &a.Status.OperationState.SyncResult.Revision +} + func GetOperationSyncRevisions(a *appv1.Application) []string { if a == nil { return []string{}