Skip to content

Commit

Permalink
fixing argo-cd resource cache (#86)
Browse files Browse the repository at this point in the history
  • Loading branch information
roi-codefresh authored May 9, 2022
1 parent 27db5ae commit 2167dba
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.1.14-cap-CR-fix-rename-file
2.1.14-cap-CR-11584-fix-resource-cache
22 changes: 14 additions & 8 deletions server/application/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -1265,6 +1265,7 @@ func (s *Server) getApplicationEventPayload(ctx context.Context, a *appv1.Applic
var (
syncStarted = metav1.Now()
syncFinished *metav1.Time
logCtx = log.WithField("application", a.Name)
)

obj := appv1.Application{}
Expand All @@ -1287,16 +1288,20 @@ func (s *Server) getApplicationEventPayload(ctx context.Context, a *appv1.Applic
Revision: &a.Status.Sync.Revision,
})
if err != nil {
return nil, fmt.Errorf("failed to get revision metadata: %w", err)
}
if !strings.Contains(err.Error(), "not found") {
return nil, fmt.Errorf("failed to get revision metadata: %w", err)
}

if obj.ObjectMeta.Labels == nil {
obj.ObjectMeta.Labels = map[string]string{}
}
logCtx.Warnf("failed to get revision metadata: %s, reporting application deletion event", err.Error())
} else {
if obj.ObjectMeta.Labels == nil {
obj.ObjectMeta.Labels = map[string]string{}
}

obj.ObjectMeta.Labels["app.meta.commit-date"] = revisionMetadata.Date.Format("2006-01-02T15:04:05.000Z")
obj.ObjectMeta.Labels["app.meta.commit-author"] = revisionMetadata.Author
obj.ObjectMeta.Labels["app.meta.commit-message"] = revisionMetadata.Message
obj.ObjectMeta.Labels["app.meta.commit-date"] = revisionMetadata.Date.Format("2006-01-02T15:04:05.000Z")
obj.ObjectMeta.Labels["app.meta.commit-author"] = revisionMetadata.Author
obj.ObjectMeta.Labels["app.meta.commit-message"] = revisionMetadata.Message
}
}

object, err := json.Marshal(&obj)
Expand All @@ -1307,6 +1312,7 @@ func (s *Server) getApplicationEventPayload(ctx context.Context, a *appv1.Applic
actualManifest := string(object)
if a.DeletionTimestamp != nil {
actualManifest = "" // mark as deleted
logCtx.Info("reporting application deletion event")
}

hs := string(a.Status.Health.Status)
Expand Down
4 changes: 2 additions & 2 deletions server/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ func lastApplicationEventKey(a *appv1.Application) string {
}

func lastResourceEventKey(a *appv1.Application, rs appv1.ResourceStatus) string {
return fmt.Sprintf("app|%s/%s|res|%s/%s/%s/%s/%s|last-sent-event",
a.Namespace, a.Name, rs.Group, rs.Version, rs.Kind, rs.Name, rs.Namespace)
return fmt.Sprintf("app|%s/%s|%s|res|%s/%s/%s/%s/%s|last-sent-event",
a.Namespace, a.Name, a.Status.Sync.Revision, rs.Group, rs.Version, rs.Kind, rs.Name, rs.Namespace)
}

func repoConnectionStateKey(repo string) string {
Expand Down

0 comments on commit 2167dba

Please sign in to comment.