From 2f7f58fc9a39d4dab304864115e0abc49a11107e Mon Sep 17 00:00:00 2001 From: Ryan Cole Date: Mon, 11 Nov 2024 11:37:39 -0500 Subject: [PATCH] fix: group snapshot error causing panic If a build pipeline in a PR group fails before other PRs in the same group we attempt to notify snapshots that have already been created. This change fixes a bug in which the service would panic and crash if not snapshots had been created for that PR group Signed-off-by: Ryan Cole --- .../buildpipeline/buildpipeline_adapter.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/internal/controller/buildpipeline/buildpipeline_adapter.go b/internal/controller/buildpipeline/buildpipeline_adapter.go index c71e0f769..d304b2806 100644 --- a/internal/controller/buildpipeline/buildpipeline_adapter.go +++ b/internal/controller/buildpipeline/buildpipeline_adapter.go @@ -246,11 +246,14 @@ func (a *Adapter) notifySnapshotsInGroupAboutFailedBuild(pipelineRun *tektonv1.P a.logger.Error(err, "Failed to fetch Snapshots for component", "component.Name", applicationComponent.Name) return err } - latestSnapshot := gitops.SortSnapshots(*allComponentSnapshotsInGroup)[0] - err = gitops.AnnotateSnapshot(a.context, &latestSnapshot, gitops.PRGroupCreationAnnotation, - buildPLRFailureMsg, a.client) - if err != nil { - return err + + if len(*allComponentSnapshotsInGroup) > 0 { + latestSnapshot := gitops.SortSnapshots(*allComponentSnapshotsInGroup)[0] + err = gitops.AnnotateSnapshot(a.context, &latestSnapshot, gitops.PRGroupCreationAnnotation, + buildPLRFailureMsg, a.client) + if err != nil { + return err + } } }