From 032b524d03f5bb04cbe0c73e290a095621dcd065 Mon Sep 17 00:00:00 2001 From: pashakostohrys Date: Wed, 16 Oct 2024 20:25:34 +0300 Subject: [PATCH] feat: acr controller crashes when here no history --- acr_controller/service/acr_service.go | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/acr_controller/service/acr_service.go b/acr_controller/service/acr_service.go index 211d6492f189f..1bf941b854cd3 100644 --- a/acr_controller/service/acr_service.go +++ b/acr_controller/service/acr_service.go @@ -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 @@ -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 }