From d508ad2a733b5a3a5696eab37e8d7910f00e259c Mon Sep 17 00:00:00 2001 From: Ryan Cole Date: Mon, 25 Nov 2024 14:06:14 -0500 Subject: [PATCH] feat: begin referencing status.lastPromotedImage Attempt to use status.lastPrommotedImage as the source of truth for the gcl. Fall back on the spec.containerImage field, despite the fact that it may have been changed by imageRepository Signed-off-by: Ryan Cole --- gitops/snapshot.go | 5 ++++- internal/controller/component/component_adapter.go | 5 ++++- internal/controller/snapshot/snapshot_adapter.go | 5 ++++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/gitops/snapshot.go b/gitops/snapshot.go index fcde83314..85aa73817 100644 --- a/gitops/snapshot.go +++ b/gitops/snapshot.go @@ -755,7 +755,10 @@ func PrepareSnapshot(ctx context.Context, adapterClient client.Client, applicati var snapshotComponents []applicationapiv1alpha1.SnapshotComponent for _, applicationComponent := range *applicationComponents { applicationComponent := applicationComponent // G601 - containerImage := applicationComponent.Spec.ContainerImage + containerImage := applicationComponent.Status.LastPromotedImage + if containerImage == "" { + containerImage = applicationComponent.Spec.ContainerImage + } var componentSource *applicationapiv1alpha1.ComponentSource if applicationComponent.Name == component.Name { diff --git a/internal/controller/component/component_adapter.go b/internal/controller/component/component_adapter.go index 28c10ff4f..e91bc0371 100644 --- a/internal/controller/component/component_adapter.go +++ b/internal/controller/component/component_adapter.go @@ -89,7 +89,10 @@ func (a *Adapter) EnsureComponentIsCleanedUp() (controller.OperationResult, erro for _, individualComponent := range *applicationComponents { component := individualComponent if a.component.Name != component.Name { - containerImage := component.Spec.ContainerImage + containerImage := component.Status.LastPromotedImage + if containerImage == "" { + containerImage = component.Spec.ContainerImage + } componentSource := gitops.GetComponentSourceFromComponent(&component) snapshotComponents = append(snapshotComponents, applicationapiv1alpha1.SnapshotComponent{ Name: component.Name, diff --git a/internal/controller/snapshot/snapshot_adapter.go b/internal/controller/snapshot/snapshot_adapter.go index 825aaec17..28541af58 100644 --- a/internal/controller/snapshot/snapshot_adapter.go +++ b/internal/controller/snapshot/snapshot_adapter.go @@ -951,7 +951,10 @@ func (a *Adapter) prepareGroupSnapshot(application *applicationapiv1alpha1.Appli a.logger.Info("can't find snapshot with open pull/merge request for component, try to find snapshotComponent from Global Candidate List", "component", applicationComponent.Name) // if there is no component snapshot found for open PR/MR, we get snapshotComponent from gcl componentSource := gitops.GetComponentSourceFromComponent(&applicationComponent) - containerImage := applicationComponent.Spec.ContainerImage + containerImage := applicationComponent.Status.LastPromotedImage + if containerImage == "" { + containerImage = applicationComponent.Spec.ContainerImage + } if containerImage == "" { a.logger.Info("component cannot be added to snapshot for application due to missing containerImage", "component.Name", applicationComponent.Name) continue