Skip to content

Commit

Permalink
feat: acr controller crashes when here no history
Browse files Browse the repository at this point in the history
  • Loading branch information
pasha-codefresh committed Oct 16, 2024
1 parent cce0e2e commit 032b524
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions acr_controller/service/acr_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,13 +171,17 @@ func (c *acrService) patchOperationSyncResultWithChangeRevision(ctx context.Cont
return err
}

func getCurrentRevisionFromOperation(a *application.Application) string {
if a.Operation != nil && a.Operation.Sync != nil {
return a.Operation.Sync.Revision
}
return ""
}

func (c *acrService) getRevisions(ctx context.Context, a *application.Application) (string, string) {
if a.Status.History == nil || len(a.Status.History) == 0 {
// it is first sync operation, and we have only current revision
if a.Operation != nil && a.Operation.Sync != nil {
return a.Operation.Sync.Revision, ""
}
return "", ""
return getCurrentRevisionFromOperation(a), ""
}

// in case if sync is already done, we need to use revision from sync result and previous revision from history
Expand All @@ -187,7 +191,7 @@ func (c *acrService) getRevisions(ctx context.Context, a *application.Applicatio
}

// in case if sync is in progress, we need to use revision from operation and revision from latest history record
currentRevision := a.Operation.Sync.Revision
currentRevision := getCurrentRevisionFromOperation(a)
previousRevision := a.Status.History[len(a.Status.History)-1].Revision
return currentRevision, previousRevision
}

0 comments on commit 032b524

Please sign in to comment.