@@ -584,13 +584,16 @@ func (r *templateRouter) createServiceAliasConfig(route *routeapi.Route, routeKe
584
584
Path : route .Spec .Path ,
585
585
IsWildcard : wildcard ,
586
586
Annotations : route .Annotations ,
587
- ServiceUnitNames : make ( map [ string ] int32 ),
587
+ ServiceUnitNames : getServiceUnits ( route ),
588
588
}
589
589
590
590
if route .Spec .Port != nil {
591
591
config .PreferPort = route .Spec .Port .TargetPort .String ()
592
592
}
593
593
594
+ key := fmt .Sprintf ("%s %s" , config .TLSTermination , routeKey )
595
+ config .RoutingKeyName = fmt .Sprintf ("%x" , md5 .Sum ([]byte (key )))
596
+
594
597
tls := route .Spec .TLS
595
598
if tls != nil && len (tls .Termination ) > 0 {
596
599
config .TLSTermination = tls .Termination
@@ -633,16 +636,6 @@ func (r *templateRouter) createServiceAliasConfig(route *routeapi.Route, routeKe
633
636
}
634
637
}
635
638
636
- key := fmt .Sprintf ("%s %s" , config .TLSTermination , routeKey )
637
- config .RoutingKeyName = fmt .Sprintf ("%x" , md5 .Sum ([]byte (key )))
638
-
639
- // Weight suggests the % of traffic that a given service will
640
- // receive compared to other services pointed to by the route.
641
- serviceKeys , weights := routeKeys (route )
642
- for i , key := range serviceKeys {
643
- config .ServiceUnitNames [key ] = weights [i ]
644
- }
645
-
646
639
return & config
647
640
}
648
641
@@ -824,22 +817,26 @@ func generateDestCertKey(config *ServiceAliasConfig) string {
824
817
return config .Host + destCertPostfix
825
818
}
826
819
827
- // routeKeys returns the internal router keys to use for the given Route.
828
- // A route can have several services that it can point to, now
829
- func routeKeys (route * routeapi.Route ) ([]string , []int32 ) {
830
- keys := make ([]string , 1 + len (route .Spec .AlternateBackends ))
831
- weights := make ([]int32 , 1 + len (route .Spec .AlternateBackends ))
832
- keys [0 ] = fmt .Sprintf ("%s/%s" , route .Namespace , route .Spec .To .Name )
833
- if route .Spec .To .Weight != nil {
834
- weights [0 ] = * route .Spec .To .Weight
820
+ // getServiceUnits returns a map of service keys to their weights.
821
+ // Weight suggests the % of traffic that a given service will receive
822
+ // compared to other services pointed to by the route.
823
+ func getServiceUnits (route * routeapi.Route ) map [string ]int32 {
824
+ serviceUnits := make (map [string ]int32 )
825
+ key := fmt .Sprintf ("%s/%s" , route .Namespace , route .Spec .To .Name )
826
+ if route .Spec .To .Weight == nil {
827
+ serviceUnits [key ] = 0
828
+ } else {
829
+ serviceUnits [key ] = * route .Spec .To .Weight
835
830
}
836
- for i , svc := range route .Spec .AlternateBackends {
837
- keys [i + 1 ] = fmt .Sprintf ("%s/%s" , route .Namespace , svc .Name )
838
- if svc .Weight != nil {
839
- weights [i + 1 ] = * svc .Weight
831
+ for _ , svc := range route .Spec .AlternateBackends {
832
+ key = fmt .Sprintf ("%s/%s" , route .Namespace , svc .Name )
833
+ if svc .Weight == nil {
834
+ serviceUnits [key ] = 0
835
+ } else {
836
+ serviceUnits [key ] = * svc .Weight
840
837
}
841
838
}
842
- return keys , weights
839
+ return serviceUnits
843
840
}
844
841
845
842
// configsAreEqual determines whether the given service alias configs can be considered equal.
0 commit comments