Skip to content

Commit

Permalink
do not ignore subsets in soft sticky sessions (#6822)
Browse files Browse the repository at this point in the history
* add consistenthash support for httpheader

* wires up source ip for hash policy

* add support for port level traffic policies

* only support port number for traffic policies

port name is deprecated. traffic policies at the port level should only
be inspected for port number when updating a route to use a hash policy.

* bump istio/api

Co-authored-by: Zachary Gershman <zgershman@pivotal.io>

* stop ignoring port level settings on the subset

* subset port level settings override top level

* do not return hash policy when not requested

Co-authored-by: Zachary Gershman <zgershman@pivotal.io>
  • Loading branch information
2 people authored and rshriram committed Jul 6, 2018
1 parent ce843e3 commit 33998c2
Show file tree
Hide file tree
Showing 17 changed files with 625 additions and 241 deletions.
2 changes: 1 addition & 1 deletion Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

90 changes: 76 additions & 14 deletions pilot/pkg/networking/core/v1alpha3/route/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ func translateRoute(in *networking.HTTPRoute,
Weight: weight,
})

hashPolicy := getHashPolicy(configStore, hostname)
hashPolicy := getHashPolicy(configStore, dst)
if hashPolicy != nil {
action.HashPolicy = append(action.HashPolicy, hashPolicy)
}
Expand Down Expand Up @@ -621,30 +621,92 @@ func translateFault(in *networking.HTTPFaultInjection) *xdshttpfault.HTTPFault {
return &out
}

func getHashPolicy(configStore model.IstioConfigStore, hostname model.Hostname) *route.RouteAction_HashPolicy {
func portLevelSettingsConsistentHash(dst *networking.Destination,
pls []*networking.TrafficPolicy_PortTrafficPolicy) *networking.LoadBalancerSettings_ConsistentHashLB {
if dst.Port != nil {
switch dst.Port.Port.(type) {
case *networking.PortSelector_Name:
log.Warnf("using deprecated name on port selector - ignoring")
case *networking.PortSelector_Number:
portNumber := dst.GetPort().GetNumber()
for _, setting := range pls {
number := setting.GetPort().GetNumber()
if number == portNumber {
return setting.GetLoadBalancer().GetConsistentHash()
}
}
}
}

return nil
}

func getHashPolicy(configStore model.IstioConfigStore, dst *networking.DestinationWeight) *route.RouteAction_HashPolicy {
if configStore == nil {
return nil
}

destinationRule := configStore.DestinationRule(hostname)
destination := dst.GetDestination()
destinationRule := configStore.DestinationRule(model.Hostname(destination.GetHost()))
if destinationRule == nil {
return nil
}

rule := destinationRule.Spec.(*networking.DestinationRule)

consistentHash := rule.GetTrafficPolicy().GetLoadBalancer().GetConsistentHash()
if consistentHash == nil {
return nil
portLevelSettings := rule.GetTrafficPolicy().GetPortLevelSettings()
plsHash := portLevelSettingsConsistentHash(destination, portLevelSettings)

var subsetHash, subsetPLSHash *networking.LoadBalancerSettings_ConsistentHashLB
for _, subset := range rule.GetSubsets() {
if subset.GetName() == destination.GetSubset() {
subsetPortLevelSettings := subset.GetTrafficPolicy().GetPortLevelSettings()
subsetHash = subset.GetTrafficPolicy().GetLoadBalancer().GetConsistentHash()
subsetPLSHash = portLevelSettingsConsistentHash(destination, subsetPortLevelSettings)

break
}
}

switch {
case subsetPLSHash != nil:
consistentHash = subsetPLSHash
case subsetHash != nil:
consistentHash = subsetHash
case plsHash != nil:
consistentHash = plsHash
}

cookie := consistentHash.GetHttpCookie()
return &route.RouteAction_HashPolicy{
PolicySpecifier: &route.RouteAction_HashPolicy_Cookie_{
Cookie: &route.RouteAction_HashPolicy_Cookie{
Name: cookie.GetName(),
Ttl: cookie.GetTtl(),
Path: cookie.GetPath(),
switch consistentHash.GetHashKey().(type) {
case *networking.LoadBalancerSettings_ConsistentHashLB_HttpHeaderName:
return &route.RouteAction_HashPolicy{
PolicySpecifier: &route.RouteAction_HashPolicy_Header_{
Header: &route.RouteAction_HashPolicy_Header{
HeaderName: consistentHash.GetHttpHeaderName(),
},
},
},
}
case *networking.LoadBalancerSettings_ConsistentHashLB_HttpCookie:
cookie := consistentHash.GetHttpCookie()

return &route.RouteAction_HashPolicy{
PolicySpecifier: &route.RouteAction_HashPolicy_Cookie_{
Cookie: &route.RouteAction_HashPolicy_Cookie{
Name: cookie.GetName(),
Ttl: cookie.GetTtl(),
Path: cookie.GetPath(),
},
},
}
case *networking.LoadBalancerSettings_ConsistentHashLB_UseSourceIp:
return &route.RouteAction_HashPolicy{
PolicySpecifier: &route.RouteAction_HashPolicy_ConnectionProperties_{
ConnectionProperties: &route.RouteAction_HashPolicy_ConnectionProperties{
SourceIp: consistentHash.GetUseSourceIp(),
},
},
}
}

return nil
}
Loading

0 comments on commit 33998c2

Please sign in to comment.