diff --git a/gitops/snapshot.go b/gitops/snapshot.go index b83d3c1c0..2ea7a901f 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