diff --git a/internal/controller/stages/verification.go b/internal/controller/stages/verification.go index 49a72222f..568ab2304 100644 --- a/internal/controller/stages/verification.go +++ b/internal/controller/stages/verification.go @@ -396,13 +396,12 @@ func (r *reconciler) buildAnalysisRun( lbls[kargoapi.StageLabelKey] = stage.Name lbls[kargoapi.FreightLabelKey] = stage.Status.CurrentFreight.Name - // Check if the AnalysisRun is triggered manually (e.g. reverification). - // We can determine it by checking existence of Reverify key in annotations. - if _, ok := stage.GetAnnotations()[kargoapi.AnnotationKeyReverify]; ok { - // Add Actor who triggered the reverification to the annotations (if exists). - if actor, ok := stage.GetAnnotations()[kargoapi.AnnotationKeyReverifyActor]; ok { - annotations[kargoapi.AnnotationKeyReverifyActor] = actor - } + // Check if the AnalysisRun is triggered manually. + // When the promotion controller requests re-verification for the re-promotion, + // there should be no Reverify Actor key in annotations. However, if the re-verification + // is requested by the user, the Reverify Actor key should be added to annotations. + if actor, ok := stage.GetAnnotations()[kargoapi.AnnotationKeyReverifyActor]; ok { + annotations[kargoapi.AnnotationKeyReverifyActor] = actor } else { // Add Promotion name if the AnalysisRun is triggered by Promotion. if stage.Status.LastPromotion != nil { diff --git a/internal/controller/stages/verification_test.go b/internal/controller/stages/verification_test.go index 53df10f73..20ecd87f1 100644 --- a/internal/controller/stages/verification_test.go +++ b/internal/controller/stages/verification_test.go @@ -1204,12 +1204,13 @@ func TestBuildAnalysisRun(t *testing.T) { }, }, { - name: "Set promotion name only if AnalysisRun is a part of the promotion", + name: "Set actor annotation only if the user triggers re-verification", reconciler: &reconciler{}, stage: &kargoapi.Stage{ ObjectMeta: metav1.ObjectMeta{ Annotations: map[string]string{ - kargoapi.AnnotationKeyReverify: "fake-id", + kargoapi.AnnotationKeyReverify: "fake-id", + kargoapi.AnnotationKeyReverifyActor: "fake-user", }, }, Spec: &kargoapi.StageSpec{ @@ -1236,6 +1237,42 @@ func TestBuildAnalysisRun(t *testing.T) { require.NoError(t, err) require.NotNil(t, ar) require.NotContains(t, ar.Labels, kargoapi.PromotionLabelKey) + require.Equal(t, "fake-user", ar.Annotations[kargoapi.AnnotationKeyReverifyActor]) + }, + }, + { + name: "Set promotion name only if the controlplane components trigger re-verification", + reconciler: &reconciler{}, + stage: &kargoapi.Stage{ + ObjectMeta: metav1.ObjectMeta{ + Annotations: map[string]string{ + kargoapi.AnnotationKeyReverify: "fake-id", + }, + }, + Spec: &kargoapi.StageSpec{ + Verification: &kargoapi.Verification{}, + }, + Status: kargoapi.StageStatus{ + CurrentFreight: &kargoapi.FreightReference{Name: "fake-id"}, + LastPromotion: &kargoapi.PromotionInfo{ + Name: "fake-id", + Status: &kargoapi.PromotionStatus{ + Phase: kargoapi.PromotionPhaseSucceeded, + }, + }, + }, + }, + freight: freight, + assertions: func( + t *testing.T, + _ *kargoapi.Stage, + _ []*rollouts.AnalysisTemplate, + ar *rollouts.AnalysisRun, + err error, + ) { + require.NoError(t, err) + require.NotNil(t, ar) + require.Contains(t, ar.Labels, kargoapi.PromotionLabelKey) }, }, }