Skip to content

Commit

Permalink
fix: nil pointer err during hash load balancing build (#3886)
Browse files Browse the repository at this point in the history
fix nil pointer err in buildHashPolicy

Signed-off-by: shawnh2 <shawnhxh@outlook.com>
  • Loading branch information
shawnh2 authored Jul 17, 2024
1 parent 953a8d8 commit f9eac40
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 5 deletions.
10 changes: 5 additions & 5 deletions internal/xds/translator/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -505,12 +505,12 @@ func buildHashPolicy(httpRoute *ir.HTTPRoute) []*routev3.RouteAction_HashPolicy
hashPolicy.GetCookie().Ttl = durationpb.New(ch.Cookie.TTL.Duration)
}
if ch.Cookie.Attributes != nil {
attributes := make([]*routev3.RouteAction_HashPolicy_CookieAttribute, len(ch.Cookie.Attributes))
i := 0
attributes := make([]*routev3.RouteAction_HashPolicy_CookieAttribute, 0, len(ch.Cookie.Attributes))
for name, value := range ch.Cookie.Attributes {
attributes[i].Name = name
attributes[i].Value = value
i++
attributes = append(attributes, &routev3.RouteAction_HashPolicy_CookieAttribute{
Name: name,
Value: value,
})
}
hashPolicy.GetCookie().Attributes = attributes
}
Expand Down
15 changes: 15 additions & 0 deletions internal/xds/translator/testdata/in/xds-ir/load-balancer.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,18 @@ http:
- endpoints:
- host: "1.2.3.4"
port: 50000
- name: "tenth-route"
hostname: "*"
traffic:
loadBalancer:
consistentHash:
cookie:
name: "test"
attributes:
foo: bar
destination:
name: "tenth-route-dest"
settings:
- endpoints:
- host: "1.2.3.4"
port: 50000
Original file line number Diff line number Diff line change
Expand Up @@ -157,3 +157,20 @@
outlierDetection: {}
perConnectionBufferLimitBytes: 32768
type: EDS
- circuitBreakers:
thresholds:
- maxRetries: 1024
commonLbConfig:
localityWeightedLbConfig: {}
connectTimeout: 10s
dnsLookupFamily: V4_ONLY
edsClusterConfig:
edsConfig:
ads: {}
resourceApiVersion: V3
serviceName: tenth-route-dest
lbPolicy: MAGLEV
name: tenth-route-dest
outlierDetection: {}
perConnectionBufferLimitBytes: 32768
type: EDS
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,15 @@
loadBalancingWeight: 1
locality:
region: ninth-route-dest/backend/0
- clusterName: tenth-route-dest
endpoints:
- lbEndpoints:
- endpoint:
address:
socketAddress:
address: 1.2.3.4
portValue: 50000
loadBalancingWeight: 1
loadBalancingWeight: 1
locality:
region: tenth-route-dest/backend/0
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,16 @@
name: test
upgradeConfigs:
- upgradeType: websocket
- match:
prefix: /
name: tenth-route
route:
cluster: tenth-route-dest
hashPolicy:
- cookie:
attributes:
- name: foo
value: bar
name: test
upgradeConfigs:
- upgradeType: websocket

0 comments on commit f9eac40

Please sign in to comment.