14
14
package dag
15
15
16
16
import (
17
- "encoding/json"
18
17
"fmt"
19
18
"net/http"
19
+ "strconv"
20
20
"strings"
21
21
"time"
22
22
@@ -1115,6 +1115,12 @@ func (p *GatewayAPIProcessor) computeHTTPRoute(route *gatewayapi_v1beta1.HTTPRou
1115
1115
// Note: Using this at the moment as a hack so we can use the existing conversion helpers.
1116
1116
finalLocalRLP := new (contour_api_v1.LocalRateLimitPolicy )
1117
1117
1118
+ type policyValue struct {
1119
+ policyName string
1120
+ value string
1121
+ }
1122
+ fields := map [string ]policyValue {}
1123
+
1118
1124
// Cycle through defaults first, and apply them on top of each other in
1119
1125
// forwards list order.
1120
1126
for _ , rlp := range allRLPs {
@@ -1124,15 +1130,31 @@ func (p *GatewayAPIProcessor) computeHTTPRoute(route *gatewayapi_v1beta1.HTTPRou
1124
1130
1125
1131
if rlp .Spec .Default .Local .Requests != 0 {
1126
1132
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
+ }
1127
1137
}
1128
1138
if rlp .Spec .Default .Local .Unit != "" {
1129
1139
finalLocalRLP .Unit = rlp .Spec .Default .Local .Unit
1140
+ fields ["local.unit" ] = policyValue {
1141
+ policyName : rlp .Name ,
1142
+ value : rlp .Spec .Default .Local .Unit ,
1143
+ }
1130
1144
}
1131
1145
if rlp .Spec .Default .Local .Burst != 0 {
1132
1146
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
+ }
1133
1151
}
1134
1152
if rlp .Spec .Default .Local .ResponseStatusCode != 0 {
1135
1153
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
+ }
1136
1158
}
1137
1159
// TODO: skipped headers for now.
1138
1160
}
@@ -1148,15 +1170,31 @@ func (p *GatewayAPIProcessor) computeHTTPRoute(route *gatewayapi_v1beta1.HTTPRou
1148
1170
1149
1171
if rlp .Spec .Override .Local .Requests != 0 {
1150
1172
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
+ }
1151
1177
}
1152
1178
if rlp .Spec .Override .Local .Unit != "" {
1153
1179
finalLocalRLP .Unit = rlp .Spec .Override .Local .Unit
1180
+ fields ["local.unit" ] = policyValue {
1181
+ policyName : rlp .Name ,
1182
+ value : rlp .Spec .Override .Local .Unit ,
1183
+ }
1154
1184
}
1155
1185
if rlp .Spec .Override .Local .Burst != 0 {
1156
1186
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
+ }
1157
1191
}
1158
1192
if rlp .Spec .Override .Local .ResponseStatusCode != 0 {
1159
1193
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
+ }
1160
1198
}
1161
1199
// TODO: skipped headers for now.
1162
1200
}
@@ -1172,11 +1210,20 @@ func (p *GatewayAPIProcessor) computeHTTPRoute(route *gatewayapi_v1beta1.HTTPRou
1172
1210
1173
1211
p .WithField ("ratelimitpolicy" , finalLocalRLP ).Info ("about to add effective policy" )
1174
1212
// 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
+ }
1176
1223
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 ,
1180
1227
})
1181
1228
1182
1229
}
0 commit comments