Skip to content

Commit

Permalink
Use a different method of propogating information about delayed servi…
Browse files Browse the repository at this point in the history
…ce swaps

Signed-off-by: Jack Andersen <[email protected]>
  • Loading branch information
jandersen-plaid committed Nov 8, 2022
1 parent 10f7a09 commit 4c69edd
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 14 deletions.
6 changes: 0 additions & 6 deletions rollout/canary.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package rollout

import (
"errors"
"sort"

appsv1 "k8s.io/api/apps/v1"
Expand Down Expand Up @@ -51,11 +50,6 @@ func (c *rolloutContext) rolloutCanary() error {
}

if err := c.reconcileStableAndCanaryService(); err != nil {
// if we cannot reconcile the stable and canary services then
// we should not continue to adjust traffic routing
if errors.Is(err, DelayServiceSelectorSwapError) {
return nil
}
return err
}

Expand Down
4 changes: 4 additions & 0 deletions rollout/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ type rolloutContext struct {
// (e.g. a setWeight step, after a blue-green active switch, after stable service switch),
// since we do not want to continually verify weight in case it could incur rate-limiting or other expenses.
targetsVerified *bool

// skippedSelectorSwap indicates that we have skipped swapping selectors
// and are not ready to perform any final actions of moving to 100%
skippedSelectorSwap *bool
}

func (c *rolloutContext) reconcile() error {
Expand Down
4 changes: 3 additions & 1 deletion rollout/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,8 +290,10 @@ func (c *rolloutContext) ensureSVCTargets(svcName string, rs *appsv1.ReplicaSet,
if checkRsAvailability && !replicasetutil.IsReplicaSetAvailable(rs) {
logCtx := c.log.WithField(logutil.ServiceKey, svc.Name)
logCtx.Infof("delaying service switch from %s to %s: ReplicaSet not fully available", currSelector, desiredSelector)
return DelayServiceSelectorSwapError
c.skippedSelectorSwap = pointer.BoolPtr(true)
return nil
}
c.skippedSelectorSwap = pointer.BoolPtr(false)
err = c.switchServiceSelector(svc, desiredSelector, c.rollout)
if err != nil {
return err
Expand Down
13 changes: 6 additions & 7 deletions rollout/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -781,12 +781,16 @@ func TestDelayCanaryStableServiceLabelInjection(t *testing.T) {
roCtx.stableRS = newReplicaSetWithStatus(ro2, 3, 0)

err = roCtx.reconcileStableAndCanaryService()
// an error is returned because we are delaying
assert.Equal(t, err, DelayServiceSelectorSwapError)
assert.NoError(t, err)
_, canaryInjected := canarySvc.Spec.Selector[v1alpha1.DefaultRolloutUniqueLabelKey]
assert.False(t, canaryInjected)
_, stableInjected := stableSvc.Spec.Selector[v1alpha1.DefaultRolloutUniqueLabelKey]
assert.False(t, stableInjected)

assert.NotNil(t, roCtx.skippedSelectorSwap)
if roCtx.skippedSelectorSwap != nil {
assert.True(t, *roCtx.skippedSelectorSwap)
}
}
{
// next ensure we do update service because new/stable are now available
Expand All @@ -806,8 +810,3 @@ func TestDelayCanaryStableServiceLabelInjection(t *testing.T) {
}

}

func TestDelayServiceSelectorSwapError(t *testing.T) {
assert.Error(t, DelayServiceSelectorSwapError)
assert.NotEqual(t, DelayServiceSelectorSwapError.Error(), "")
}
4 changes: 4 additions & 0 deletions rollout/trafficrouting.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,10 @@ func (c *rolloutContext) reconcileTrafficRouting() error {
return err
}

if c.skippedSelectorSwap != nil && *c.skippedSelectorSwap {
continue
}

err = reconciler.SetWeight(desiredWeight, weightDestinations...)
if err != nil {
c.recorder.Warnf(c.rollout, record.EventOptions{EventReason: "TrafficRoutingError"}, err.Error())
Expand Down

0 comments on commit 4c69edd

Please sign in to comment.