From b337b4946d35f5acac905cac1f2bebd2f56e27d1 Mon Sep 17 00:00:00 2001 From: Abhishek Bansal Date: Tue, 8 Oct 2024 13:25:56 +0530 Subject: [PATCH] fix: unexpected downtime --- rollout/trafficrouting.go | 1 - rollout/trafficrouting_test.go | 86 +++++++++++++++++----------------- 2 files changed, 43 insertions(+), 44 deletions(-) diff --git a/rollout/trafficrouting.go b/rollout/trafficrouting.go index 9e2b345890..4df5715af2 100644 --- a/rollout/trafficrouting.go +++ b/rollout/trafficrouting.go @@ -410,4 +410,3 @@ func (c *rolloutContext) calculateWeightDestinationsFromExperiment() []v1alpha1. } return weightDestinations } - diff --git a/rollout/trafficrouting_test.go b/rollout/trafficrouting_test.go index 71ee47c60c..8f73639585 100644 --- a/rollout/trafficrouting_test.go +++ b/rollout/trafficrouting_test.go @@ -1346,8 +1346,8 @@ func TestDontWeightToZeroWhenDynamicallyRollingBackToStable(t *testing.T) { // This test verifies that if we are shifting traffic to stable replicaset without the stable replicaset being available proportional to the weight, the traffic shouldn't be switched immediately to the stable replicaset. func TestCheckReplicaSetAvailable(t *testing.T) { - f := newFixture(t) - defer f.Close() + fix := newFixture(t) + defer fix.Close() steps := []v1alpha1.CanaryStep{ { @@ -1357,56 +1357,56 @@ func TestCheckReplicaSetAvailable(t *testing.T) { Pause: &v1alpha1.RolloutPause{}, }, } - r1 := newCanaryRollout("foo", 10, nil, steps, pointer.Int32(1), intstr.FromInt(1), intstr.FromInt(1)) - r1.Spec.Strategy.Canary.DynamicStableScale = true - r1.Spec.Strategy.Canary.TrafficRouting = &v1alpha1.RolloutTrafficRouting{ + + rollout1 := newCanaryRollout("test-rollout", 10, nil, steps, pointer.Int32(1), intstr.FromInt(1), intstr.FromInt(1)) + rollout1.Spec.Strategy.Canary.DynamicStableScale = true + rollout1.Spec.Strategy.Canary.TrafficRouting = &v1alpha1.RolloutTrafficRouting{ SMI: &v1alpha1.SMITrafficRouting{}, } - r1.Spec.Strategy.Canary.CanaryService = "canary" - r1.Spec.Strategy.Canary.StableService = "stable" - r1.Status.ReadyReplicas = 10 - r1.Status.AvailableReplicas = 10 - r2 := bumpVersion(r1) - - rs1 := newReplicaSetWithStatus(r1, 1, 1) - rs2 := newReplicaSetWithStatus(r2, 9, 9) - - rs1PodHash := rs1.Labels[v1alpha1.DefaultRolloutUniqueLabelKey] - rs2PodHash := rs2.Labels[v1alpha1.DefaultRolloutUniqueLabelKey] - canarySelector := map[string]string{v1alpha1.DefaultRolloutUniqueLabelKey: rs2PodHash} - stableSelector := map[string]string{v1alpha1.DefaultRolloutUniqueLabelKey: rs1PodHash} - canarySvc := newService("canary", 80, canarySelector, r1) - stableSvc := newService("stable", 80, stableSelector, r1) - - // simulate rollback to stable - r2.Spec = r1.Spec - r2.Status.StableRS = rs1PodHash - r2.Status.CurrentPodHash = rs1PodHash // will cause IsFullyPromoted() to be true - r2.Status.Canary.Weights = &v1alpha1.TrafficWeights{ + rollout1.Spec.Strategy.Canary.CanaryService = "canary-service" + rollout1.Spec.Strategy.Canary.StableService = "stable-service" + rollout1.Status.ReadyReplicas = 10 + rollout1.Status.AvailableReplicas = 10 + + rollout2 := bumpVersion(rollout1) + + replicaSet1 := newReplicaSetWithStatus(rollout1, 1, 1) + replicaSet2 := newReplicaSetWithStatus(rollout2, 9, 9) + + replicaSet1Hash := replicaSet1.Labels[v1alpha1.DefaultRolloutUniqueLabelKey] + replicaSet2Hash := replicaSet2.Labels[v1alpha1.DefaultRolloutUniqueLabelKey] + canarySelector := map[string]string{v1alpha1.DefaultRolloutUniqueLabelKey: replicaSet2Hash} + stableSelector := map[string]string{v1alpha1.DefaultRolloutUniqueLabelKey: replicaSet1Hash} + canarySvc := newService("canary-service", 80, canarySelector, rollout1) + stableSvc := newService("stable-service", 80, stableSelector, rollout1) + + rollout2.Spec = rollout1.Spec + rollout2.Status.StableRS = replicaSet1Hash + rollout2.Status.CurrentPodHash = replicaSet1Hash + rollout2.Status.Canary.Weights = &v1alpha1.TrafficWeights{ Canary: v1alpha1.WeightDestination{ Weight: 10, - ServiceName: "canary", - PodTemplateHash: rs2PodHash, + ServiceName: "canary-service", + PodTemplateHash: replicaSet2Hash, }, Stable: v1alpha1.WeightDestination{ Weight: 90, - ServiceName: "stable", - PodTemplateHash: rs1PodHash, + ServiceName: "stable-service", + PodTemplateHash: replicaSet1Hash, }, } - f.kubeobjects = append(f.kubeobjects, rs1, rs2, canarySvc, stableSvc) - f.replicaSetLister = append(f.replicaSetLister, rs1, rs2) + fix.kubeobjects = append(fix.kubeobjects, replicaSet1, replicaSet2, canarySvc, stableSvc) + fix.replicaSetLister = append(fix.replicaSetLister, replicaSet1, replicaSet2) - f.rolloutLister = append(f.rolloutLister, r2) - f.objects = append(f.objects, r2) + fix.rolloutLister = append(fix.rolloutLister, rollout2) + fix.objects = append(fix.objects, rollout2) - f.expectUpdateReplicaSetAction(rs1) // Updates the revision annotation from 1 to 3 from func isScalingEvent - f.expectUpdateRolloutAction(r2) // Update the rollout revision from 1 to 3 - f.expectUpdateReplicaSetAction(rs1) // Scale The replicaset from 1 to 10 from func scaleReplicaSet - f.expectPatchRolloutAction(r2) // Updates the rollout status from the scaling to 10 action - - f.fakeTrafficRouting = newUnmockedFakeTrafficRoutingReconciler() - f.fakeTrafficRouting.On("RemoveManagedRoutes", mock.Anything, mock.Anything, mock.Anything).Return(nil) - f.run(getKey(r1, t)) -} \ No newline at end of file + fix.expectUpdateReplicaSetAction(replicaSet1) + fix.expectUpdateRolloutAction(rollout2) + fix.expectUpdateReplicaSetAction(replicaSet1) + fix.expectPatchRolloutAction(rollout2) + fix.fakeTrafficRouting = newUnmockedFakeTrafficRoutingReconciler() + fix.fakeTrafficRouting.On("RemoveManagedRoutes", mock.Anything, mock.Anything, mock.Anything).Return(nil) + fix.run(getKey(rollout1, t)) +}