@@ -193,6 +193,109 @@ func TestTranslateKongUpstreamPolicy(t *testing.T) {
193
193
HashFallbackHeader : lo .ToPtr ("bar" ),
194
194
},
195
195
},
196
+ {
197
+ name : "KongUpstreamPolicySpec with hash-on header and hash-on fallback cookie" ,
198
+ policySpec : configurationv1beta1.KongUpstreamPolicySpec {
199
+ HashOn : & configurationv1beta1.KongUpstreamHash {
200
+ Header : lo .ToPtr ("foo" ),
201
+ },
202
+ HashOnFallback : & configurationv1beta1.KongUpstreamHash {
203
+ Cookie : lo .ToPtr ("cookie-name" ),
204
+ CookiePath : lo .ToPtr ("/cookie-path" ),
205
+ },
206
+ },
207
+ expectedUpstream : & kong.Upstream {
208
+ HashOn : lo .ToPtr ("header" ),
209
+ HashOnHeader : lo .ToPtr ("foo" ),
210
+ HashFallback : lo .ToPtr ("cookie" ),
211
+ HashOnCookie : lo .ToPtr ("cookie-name" ),
212
+ HashOnCookiePath : lo .ToPtr ("/cookie-path" ),
213
+ },
214
+ },
215
+ {
216
+ name : "KongUpstreamPolicySpec with hash-on query-arg and hash-on fallback cookie" ,
217
+ policySpec : configurationv1beta1.KongUpstreamPolicySpec {
218
+ HashOn : & configurationv1beta1.KongUpstreamHash {
219
+ QueryArg : lo .ToPtr ("foo" ),
220
+ },
221
+ HashOnFallback : & configurationv1beta1.KongUpstreamHash {
222
+ Cookie : lo .ToPtr ("cookie-name" ),
223
+ CookiePath : lo .ToPtr ("/cookie-path" ),
224
+ },
225
+ },
226
+ expectedUpstream : & kong.Upstream {
227
+ HashOn : lo .ToPtr ("query_arg" ),
228
+ HashOnQueryArg : lo .ToPtr ("foo" ),
229
+ HashFallback : lo .ToPtr ("cookie" ),
230
+ HashOnCookie : lo .ToPtr ("cookie-name" ),
231
+ HashOnCookiePath : lo .ToPtr ("/cookie-path" ),
232
+ },
233
+ },
234
+ {
235
+ name : "KongUpstreamPolicySpec with hash-on uri-capture and hash-on fallback cookie" ,
236
+ policySpec : configurationv1beta1.KongUpstreamPolicySpec {
237
+ HashOn : & configurationv1beta1.KongUpstreamHash {
238
+ URICapture : lo .ToPtr ("foo" ),
239
+ },
240
+ HashOnFallback : & configurationv1beta1.KongUpstreamHash {
241
+ Cookie : lo .ToPtr ("cookie-name" ),
242
+ CookiePath : lo .ToPtr ("/cookie-path" ),
243
+ },
244
+ },
245
+ expectedUpstream : & kong.Upstream {
246
+ HashOn : lo .ToPtr ("uri_capture" ),
247
+ HashOnURICapture : lo .ToPtr ("foo" ),
248
+ HashFallback : lo .ToPtr ("cookie" ),
249
+ HashOnCookie : lo .ToPtr ("cookie-name" ),
250
+ HashOnCookiePath : lo .ToPtr ("/cookie-path" ),
251
+ },
252
+ },
253
+ {
254
+ // This will be blocked by CRD validation rules because according to
255
+ // https://developer.konghq.com/gateway/entities/upstream/#consistent-hashing
256
+ // if the primary hash_on is set to cookie, the hash_fallback is invalid
257
+ // and cannot be used.
258
+ name : "KongUpstreamPolicySpec with hash-on cookie and hash-on fallback cookie is incorrect and should not happen" ,
259
+ policySpec : configurationv1beta1.KongUpstreamPolicySpec {
260
+ HashOn : & configurationv1beta1.KongUpstreamHash {
261
+ Cookie : lo .ToPtr ("cookie-name" ),
262
+ CookiePath : lo .ToPtr ("/cookie-path" ),
263
+ },
264
+ HashOnFallback : & configurationv1beta1.KongUpstreamHash {
265
+ Cookie : lo .ToPtr ("cookie-name-2" ),
266
+ CookiePath : lo .ToPtr ("/cookie-path-2" ),
267
+ },
268
+ },
269
+ expectedUpstream : & kong.Upstream {
270
+ HashOn : lo .ToPtr ("cookie" ),
271
+ HashOnCookie : lo .ToPtr ("cookie-name" ),
272
+ HashOnCookiePath : lo .ToPtr ("/cookie-path" ),
273
+ HashFallback : lo .ToPtr ("cookie" ),
274
+ },
275
+ },
276
+ {
277
+ // This will be blocked by CRD validation rules because according to
278
+ // https://developer.konghq.com/gateway/entities/upstream/#consistent-hashing
279
+ // if the primary hash_on is set to cookie, the hash_fallback is invalid
280
+ // and cannot be used.
281
+ name : "KongUpstreamPolicySpec with hash-on cookie and hash-on fallback header is incorrect and should not happen" ,
282
+ policySpec : configurationv1beta1.KongUpstreamPolicySpec {
283
+ HashOn : & configurationv1beta1.KongUpstreamHash {
284
+ Cookie : lo .ToPtr ("cookie-name" ),
285
+ CookiePath : lo .ToPtr ("/cookie-path" ),
286
+ },
287
+ HashOnFallback : & configurationv1beta1.KongUpstreamHash {
288
+ Header : lo .ToPtr ("header-name" ),
289
+ },
290
+ },
291
+ expectedUpstream : & kong.Upstream {
292
+ HashOn : lo .ToPtr ("cookie" ),
293
+ HashOnCookie : lo .ToPtr ("cookie-name" ),
294
+ HashOnCookiePath : lo .ToPtr ("/cookie-path" ),
295
+ HashFallback : lo .ToPtr ("header" ),
296
+ HashFallbackHeader : lo .ToPtr ("header-name" ),
297
+ },
298
+ },
196
299
{
197
300
name : "KongUpstreamPolicySpec with hash-on cookie" ,
198
301
policySpec : configurationv1beta1.KongUpstreamPolicySpec {
0 commit comments