From 7a4492caa3ec3467839ee2e4d398ef94efb4d4e1 Mon Sep 17 00:00:00 2001 From: zachaller Date: Fri, 19 Aug 2022 09:00:53 -0500 Subject: [PATCH] fix unit tests Signed-off-by: zachaller --- rollout/controller_test.go | 4 +++- rollout/service_test.go | 8 +------- rollout/sync.go | 8 +++++--- 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/rollout/controller_test.go b/rollout/controller_test.go index a2bcbed2a0..412d8ba0ce 100644 --- a/rollout/controller_test.go +++ b/rollout/controller_test.go @@ -195,13 +195,15 @@ func newPausedCondition(isPaused bool) (v1alpha1.RolloutCondition, string) { func newHealthyCondition(isCompleted bool) (v1alpha1.RolloutCondition, string) { status := corev1.ConditionTrue + msg := conditions.RolloutHealthyAndCompletedMessage if !isCompleted { status = corev1.ConditionFalse + msg = conditions.RolloutNotHealthyAndCompletedMessage } condition := v1alpha1.RolloutCondition{ LastTransitionTime: timeutil.MetaNow(), LastUpdateTime: timeutil.MetaNow(), - Message: conditions.RolloutHealthyAndCompletedReason, + Message: msg, Reason: conditions.RolloutHealthyAndCompletedReason, Status: status, Type: v1alpha1.HealthyAndCompleted, diff --git a/rollout/service_test.go b/rollout/service_test.go index 371b2faeab..2ebe578dc3 100644 --- a/rollout/service_test.go +++ b/rollout/service_test.go @@ -324,7 +324,6 @@ func TestBlueGreenAWSVerifyTargetGroupsNotYetReady(t *testing.T) { assert.Equal(t, expectedPatch, patch) f.assertEvents([]string{ conditions.TargetGroupUnverifiedReason, - conditions.RolloutHealthyAndCompletedReason, }) } @@ -411,7 +410,6 @@ func TestBlueGreenAWSVerifyTargetGroupsReady(t *testing.T) { f.assertEvents([]string{ conditions.TargetGroupVerifiedReason, conditions.RolloutCompletedReason, - conditions.RolloutHealthyAndCompletedReason, }) } @@ -509,7 +507,6 @@ func TestCanaryAWSVerifyTargetGroupsNotYetReady(t *testing.T) { f.run(getKey(r2, t)) f.assertEvents([]string{ conditions.TargetGroupUnverifiedReason, - conditions.RolloutHealthyAndCompletedReason, }) } @@ -608,7 +605,6 @@ func TestCanaryAWSVerifyTargetGroupsReady(t *testing.T) { f.verifyPatchedReplicaSet(scaleDownRSIndex, 30) f.assertEvents([]string{ conditions.TargetGroupVerifiedReason, - conditions.RolloutHealthyAndCompletedReason, }) } @@ -665,9 +661,7 @@ func TestCanaryAWSVerifyTargetGroupsSkip(t *testing.T) { f.ingressLister = append(f.ingressLister, ingressutil.NewLegacyIngress(ing)) f.run(getKey(r2, t)) // there should be no api calls - f.assertEvents([]string{ - conditions.RolloutHealthyAndCompletedReason, - }) + f.assertEvents(nil) } // TestShouldVerifyTargetGroups returns whether or not we should verify the target group diff --git a/rollout/sync.go b/rollout/sync.go index 53dfdce1c6..80c109b108 100644 --- a/rollout/sync.go +++ b/rollout/sync.go @@ -926,10 +926,12 @@ func (c *rolloutContext) promoteStable(newStatus *v1alpha1.RolloutStatus, reason } newStatus.StableRS = newStatus.CurrentPodHash revision, _ := replicasetutil.Revision(c.rollout) - c.recorder.Eventf(c.rollout, record.EventOptions{EventReason: conditions.RolloutCompletedReason}, - conditions.RolloutCompletedMessage, revision, newStatus.CurrentPodHash, reason) if conditions.RolloutComplete(c.rollout, newStatus) { - updateCompletedCond := conditions.NewRolloutCondition(v1alpha1.RolloutCompleted, corev1.ConditionTrue, conditions.RolloutCompletedReason, conditions.RolloutCompletedReason) + c.recorder.Eventf(c.rollout, record.EventOptions{EventReason: conditions.RolloutCompletedReason}, + conditions.RolloutCompletedMessage, revision, newStatus.CurrentPodHash, reason) + + updateCompletedCond := conditions.NewRolloutCondition(v1alpha1.RolloutCompleted, corev1.ConditionTrue, + conditions.RolloutCompletedReason, fmt.Sprintf(conditions.RolloutCompletedMessage, revision, newStatus.CurrentPodHash, reason)) conditions.SetRolloutCondition(newStatus, *updateCompletedCond) } }