Skip to content

Commit

Permalink
fix: pass promotion name to AnalysisRun on non-user verification requ…
Browse files Browse the repository at this point in the history
…est (#1847)

Signed-off-by: Sunghoon Kang <[email protected]>
  • Loading branch information
Sunghoon Kang authored Apr 16, 2024
1 parent b175247 commit 4ada872
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 9 deletions.
13 changes: 6 additions & 7 deletions internal/controller/stages/verification.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
41 changes: 39 additions & 2 deletions internal/controller/stages/verification_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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)
},
},
}
Expand Down

0 comments on commit 4ada872

Please sign in to comment.