Skip to content

Commit ff49ae7

Browse files
committed
Use PolicySettings to express what Policy is in effect
Signed-off-by: Sunjay Bhatia <[email protected]>
1 parent fa7282d commit ff49ae7

File tree

3 files changed

+55
-8
lines changed

3 files changed

+55
-8
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,4 @@ require (
4545
sigs.k8s.io/kustomize/kyaml v0.10.17
4646
)
4747

48-
replace sigs.k8s.io/gateway-api => github.com/sunjayBhatia/gateway-api v0.0.0-20221111001054-0cf3fa56af68
48+
replace sigs.k8s.io/gateway-api => github.com/sunjayBhatia/gateway-api v0.0.0-20221111013255-20e2f70ba9cd

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1100,8 +1100,8 @@ github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PK
11001100
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
11011101
github.com/subosito/gotenv v1.2.0 h1:Slr1R9HxAlEKefgq5jn9U+DnETlIUa6HfgEzj0g5d7s=
11021102
github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw=
1103-
github.com/sunjayBhatia/gateway-api v0.0.0-20221111001054-0cf3fa56af68 h1:VXb1UC0933STso1KO/97s6ZOzsxqtedK7eH8Rwd4kIg=
1104-
github.com/sunjayBhatia/gateway-api v0.0.0-20221111001054-0cf3fa56af68/go.mod h1:x0AP6gugkFV8fC/oTlnOMU0pnmuzIR8LfIPRVUjxSqA=
1103+
github.com/sunjayBhatia/gateway-api v0.0.0-20221111013255-20e2f70ba9cd h1:vTnbx8oOVZTFPq6rEDZxgArUACu8nim4Vs6uLZ7pS/w=
1104+
github.com/sunjayBhatia/gateway-api v0.0.0-20221111013255-20e2f70ba9cd/go.mod h1:x0AP6gugkFV8fC/oTlnOMU0pnmuzIR8LfIPRVUjxSqA=
11051105
github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
11061106
github.com/tmc/grpc-websocket-proxy v0.0.0-20170815181823-89b8d40f7ca8/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
11071107
github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=

internal/dag/gatewayapi_processor.go

Lines changed: 52 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
package dag
1515

1616
import (
17-
"encoding/json"
1817
"fmt"
1918
"net/http"
19+
"strconv"
2020
"strings"
2121
"time"
2222

@@ -1115,6 +1115,12 @@ func (p *GatewayAPIProcessor) computeHTTPRoute(route *gatewayapi_v1beta1.HTTPRou
11151115
// Note: Using this at the moment as a hack so we can use the existing conversion helpers.
11161116
finalLocalRLP := new(contour_api_v1.LocalRateLimitPolicy)
11171117

1118+
type policyValue struct {
1119+
policyName string
1120+
value string
1121+
}
1122+
fields := map[string]policyValue{}
1123+
11181124
// Cycle through defaults first, and apply them on top of each other in
11191125
// forwards list order.
11201126
for _, rlp := range allRLPs {
@@ -1124,15 +1130,31 @@ func (p *GatewayAPIProcessor) computeHTTPRoute(route *gatewayapi_v1beta1.HTTPRou
11241130

11251131
if rlp.Spec.Default.Local.Requests != 0 {
11261132
finalLocalRLP.Requests = rlp.Spec.Default.Local.Requests
1133+
fields["local.requests"] = policyValue{
1134+
policyName: rlp.Name,
1135+
value: strconv.FormatUint(uint64(rlp.Spec.Default.Local.Requests), 10),
1136+
}
11271137
}
11281138
if rlp.Spec.Default.Local.Unit != "" {
11291139
finalLocalRLP.Unit = rlp.Spec.Default.Local.Unit
1140+
fields["local.unit"] = policyValue{
1141+
policyName: rlp.Name,
1142+
value: rlp.Spec.Default.Local.Unit,
1143+
}
11301144
}
11311145
if rlp.Spec.Default.Local.Burst != 0 {
11321146
finalLocalRLP.Burst = rlp.Spec.Default.Local.Burst
1147+
fields["local.burst"] = policyValue{
1148+
policyName: rlp.Name,
1149+
value: strconv.FormatUint(uint64(rlp.Spec.Default.Local.Burst), 10),
1150+
}
11331151
}
11341152
if rlp.Spec.Default.Local.ResponseStatusCode != 0 {
11351153
finalLocalRLP.ResponseStatusCode = rlp.Spec.Default.Local.ResponseStatusCode
1154+
fields["local.responseStatusCode"] = policyValue{
1155+
policyName: rlp.Name,
1156+
value: strconv.FormatUint(uint64(rlp.Spec.Default.Local.ResponseStatusCode), 10),
1157+
}
11361158
}
11371159
// TODO: skipped headers for now.
11381160
}
@@ -1148,15 +1170,31 @@ func (p *GatewayAPIProcessor) computeHTTPRoute(route *gatewayapi_v1beta1.HTTPRou
11481170

11491171
if rlp.Spec.Override.Local.Requests != 0 {
11501172
finalLocalRLP.Requests = rlp.Spec.Override.Local.Requests
1173+
fields["local.requests"] = policyValue{
1174+
policyName: rlp.Name,
1175+
value: strconv.FormatUint(uint64(rlp.Spec.Override.Local.Requests), 10),
1176+
}
11511177
}
11521178
if rlp.Spec.Override.Local.Unit != "" {
11531179
finalLocalRLP.Unit = rlp.Spec.Override.Local.Unit
1180+
fields["local.unit"] = policyValue{
1181+
policyName: rlp.Name,
1182+
value: rlp.Spec.Override.Local.Unit,
1183+
}
11541184
}
11551185
if rlp.Spec.Override.Local.Burst != 0 {
11561186
finalLocalRLP.Burst = rlp.Spec.Override.Local.Burst
1187+
fields["local.burst"] = policyValue{
1188+
policyName: rlp.Name,
1189+
value: strconv.FormatUint(uint64(rlp.Spec.Override.Local.Burst), 10),
1190+
}
11571191
}
11581192
if rlp.Spec.Override.Local.ResponseStatusCode != 0 {
11591193
finalLocalRLP.ResponseStatusCode = rlp.Spec.Override.Local.ResponseStatusCode
1194+
fields["local.responseStatusCode"] = policyValue{
1195+
policyName: rlp.Name,
1196+
value: strconv.FormatUint(uint64(rlp.Spec.Override.Local.ResponseStatusCode), 10),
1197+
}
11601198
}
11611199
// TODO: skipped headers for now.
11621200
}
@@ -1172,11 +1210,20 @@ func (p *GatewayAPIProcessor) computeHTTPRoute(route *gatewayapi_v1beta1.HTTPRou
11721210

11731211
p.WithField("ratelimitpolicy", finalLocalRLP).Info("about to add effective policy")
11741212
// Add EffectivePolicyConfiguration to Status.
1175-
policyContent, _ := json.Marshal(finalLocalRLP)
1213+
policySettings := []gatewayapi_v1beta1.PolicySetting{}
1214+
for field, value := range fields {
1215+
if value.value != "" {
1216+
policySettings = append(policySettings, gatewayapi_v1beta1.PolicySetting{
1217+
Field: field,
1218+
Value: value.value,
1219+
PolicyName: value.policyName,
1220+
})
1221+
}
1222+
}
11761223
routeAccessor.AddEffectivePolicyConfig(gatewayapi_v1beta1.RouteEffectivePolicyConfiguration{
1177-
PolicyType: "projectcontour.io/RateLimitPolicy",
1178-
SectionName: gatewayapi_v1beta1.SectionName("unsupportedfornow"),
1179-
PolicyValue: string(policyContent),
1224+
PolicyType: "projectcontour.io/RateLimitPolicy",
1225+
SectionName: gatewayapi_v1beta1.SectionName("unsupportedfornow"),
1226+
PolicySettings: policySettings,
11801227
})
11811228

11821229
}

0 commit comments

Comments
 (0)