Skip to content

Commit c31245a

Browse files
reduce complexity
Signed-off-by: Andrew Brown <andrew.brown@wealthsimple.com>
1 parent 935f703 commit c31245a

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

rollout/replicaset.go

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -401,23 +401,34 @@ func (c *rolloutContext) isReplicaSetReferenced(rs *appsv1.ReplicaSet) bool {
401401
return false
402402
}
403403

404+
// getIstioDestinationRuleSpec returns the Istio DestinationRule spec from the rollout if configured,
405+
// or nil if Istio traffic routing with a DestinationRule is not configured.
406+
func getIstioDestinationRuleSpec(ro *v1alpha1.Rollout) *v1alpha1.IstioDestinationRule {
407+
if ro.Spec.Strategy.Canary == nil {
408+
return nil
409+
}
410+
if ro.Spec.Strategy.Canary.TrafficRouting == nil {
411+
return nil
412+
}
413+
if ro.Spec.Strategy.Canary.TrafficRouting.Istio == nil {
414+
return nil
415+
}
416+
return ro.Spec.Strategy.Canary.TrafficRouting.Istio.DestinationRule
417+
}
418+
404419
// isReplicaSetReferencedByIstioDestinationRule checks if the given pod template hash is still
405420
// referenced by any subset in the Istio DestinationRule. This prevents scaling down a ReplicaSet
406421
// that is still receiving traffic via Istio subset-level routing.
407422
func (c *rolloutContext) isReplicaSetReferencedByIstioDestinationRule(rsPodHash string) bool {
408-
ro := c.rollout
409-
if ro.Spec.Strategy.Canary == nil || ro.Spec.Strategy.Canary.TrafficRouting == nil ||
410-
ro.Spec.Strategy.Canary.TrafficRouting.Istio == nil ||
411-
ro.Spec.Strategy.Canary.TrafficRouting.Istio.DestinationRule == nil {
423+
dRuleSpec := getIstioDestinationRuleSpec(c.rollout)
424+
if dRuleSpec == nil {
412425
return false
413426
}
414427

415428
if c.IstioController == nil || c.IstioController.DestinationRuleLister == nil {
416429
return false
417430
}
418-
419-
dRuleSpec := ro.Spec.Strategy.Canary.TrafficRouting.Istio.DestinationRule
420-
dRuleUn, err := c.IstioController.DestinationRuleLister.Namespace(ro.Namespace).Get(dRuleSpec.Name)
431+
dRuleUn, err := c.IstioController.DestinationRuleLister.Namespace(c.rollout.Namespace).Get(dRuleSpec.Name)
421432
if err != nil {
422433
if k8serrors.IsNotFound(err) {
423434
return false

0 commit comments

Comments
 (0)