@@ -2,6 +2,7 @@ package ingress
2
2
3
3
import (
4
4
"context"
5
+ awssdk "github.com/aws/aws-sdk-go/aws"
5
6
"github.com/stretchr/testify/assert"
6
7
corev1 "k8s.io/api/core/v1"
7
8
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -283,3 +284,229 @@ func Test_defaultModelBuildTask_buildTargetGroupTags(t *testing.T) {
283
284
})
284
285
}
285
286
}
287
+
288
+ func Test_defaultModelBuildTask_buildTargetGroupHealthCheckPath (t * testing.T ) {
289
+ type fields struct {
290
+ defaultHealthCheckPathHTTP string
291
+ defaultHealthCheckPathGRPC string
292
+ }
293
+ type args struct {
294
+ svcAndIngAnnotations map [string ]string
295
+ tgProtocolVersion elbv2model.ProtocolVersion
296
+ }
297
+ tests := []struct {
298
+ name string
299
+ fields fields
300
+ args args
301
+ want string
302
+ }{
303
+ {
304
+ name : "HTTP1, without annotation configured" ,
305
+ fields : fields {
306
+ defaultHealthCheckPathHTTP : "/" ,
307
+ defaultHealthCheckPathGRPC : "/AWS.ALB/healthcheck" ,
308
+ },
309
+ args : args {
310
+ svcAndIngAnnotations : nil ,
311
+ tgProtocolVersion : elbv2model .ProtocolVersionHTTP1 ,
312
+ },
313
+ want : "/" ,
314
+ },
315
+ {
316
+ name : "HTTP2, without annotation configured" ,
317
+ fields : fields {
318
+ defaultHealthCheckPathHTTP : "/" ,
319
+ defaultHealthCheckPathGRPC : "/AWS.ALB/healthcheck" ,
320
+ },
321
+ args : args {
322
+ svcAndIngAnnotations : nil ,
323
+ tgProtocolVersion : elbv2model .ProtocolVersionHTTP2 ,
324
+ },
325
+ want : "/" ,
326
+ },
327
+ {
328
+ name : "GRPC, without annotation configured" ,
329
+ fields : fields {
330
+ defaultHealthCheckPathHTTP : "/" ,
331
+ defaultHealthCheckPathGRPC : "/AWS.ALB/healthcheck" ,
332
+ },
333
+ args : args {
334
+ svcAndIngAnnotations : nil ,
335
+ tgProtocolVersion : elbv2model .ProtocolVersionGRPC ,
336
+ },
337
+ want : "/AWS.ALB/healthcheck" ,
338
+ },
339
+ {
340
+ name : "HTTP1, with annotation configured" ,
341
+ fields : fields {
342
+ defaultHealthCheckPathHTTP : "/" ,
343
+ defaultHealthCheckPathGRPC : "/AWS.ALB/healthcheck" ,
344
+ },
345
+ args : args {
346
+ svcAndIngAnnotations : map [string ]string {
347
+ "alb.ingress.kubernetes.io/healthcheck-path" : "/ping" ,
348
+ },
349
+ tgProtocolVersion : elbv2model .ProtocolVersionHTTP1 ,
350
+ },
351
+ want : "/ping" ,
352
+ },
353
+ {
354
+ name : "HTTP2, with annotation configured" ,
355
+ fields : fields {
356
+ defaultHealthCheckPathHTTP : "/" ,
357
+ defaultHealthCheckPathGRPC : "/AWS.ALB/healthcheck" ,
358
+ },
359
+ args : args {
360
+ svcAndIngAnnotations : map [string ]string {
361
+ "alb.ingress.kubernetes.io/healthcheck-path" : "/ping" ,
362
+ },
363
+ tgProtocolVersion : elbv2model .ProtocolVersionHTTP2 ,
364
+ },
365
+ want : "/ping" ,
366
+ },
367
+ {
368
+ name : "GRPC, with annotation configured" ,
369
+ fields : fields {
370
+ defaultHealthCheckPathHTTP : "/" ,
371
+ defaultHealthCheckPathGRPC : "/AWS.ALB/healthcheck" ,
372
+ },
373
+ args : args {
374
+ svcAndIngAnnotations : map [string ]string {
375
+ "alb.ingress.kubernetes.io/healthcheck-path" : "/package.service/method" ,
376
+ },
377
+ tgProtocolVersion : elbv2model .ProtocolVersionGRPC ,
378
+ },
379
+ want : "/package.service/method" ,
380
+ },
381
+ }
382
+ for _ , tt := range tests {
383
+ t .Run (tt .name , func (t * testing.T ) {
384
+ task := & defaultModelBuildTask {
385
+ annotationParser : annotations .NewSuffixAnnotationParser ("alb.ingress.kubernetes.io" ),
386
+ defaultHealthCheckPathHTTP : tt .fields .defaultHealthCheckPathHTTP ,
387
+ defaultHealthCheckPathGRPC : tt .fields .defaultHealthCheckPathGRPC ,
388
+ }
389
+ got := task .buildTargetGroupHealthCheckPath (context .Background (), tt .args .svcAndIngAnnotations , tt .args .tgProtocolVersion )
390
+ assert .Equal (t , tt .want , got )
391
+ })
392
+ }
393
+ }
394
+
395
+ func Test_defaultModelBuildTask_buildTargetGroupHealthCheckMatcher (t * testing.T ) {
396
+ type fields struct {
397
+ defaultHealthCheckMatcherHTTPCode string
398
+ defaultHealthCheckMatcherGRPCCode string
399
+ }
400
+ type args struct {
401
+ svcAndIngAnnotations map [string ]string
402
+ tgProtocolVersion elbv2model.ProtocolVersion
403
+ }
404
+ tests := []struct {
405
+ name string
406
+ fields fields
407
+ args args
408
+ want elbv2model.HealthCheckMatcher
409
+ }{
410
+ {
411
+ name : "HTTP1, without annotation configured" ,
412
+ fields : fields {
413
+ defaultHealthCheckMatcherHTTPCode : "200" ,
414
+ defaultHealthCheckMatcherGRPCCode : "12" ,
415
+ },
416
+ args : args {
417
+ svcAndIngAnnotations : nil ,
418
+ tgProtocolVersion : elbv2model .ProtocolVersionHTTP1 ,
419
+ },
420
+ want : elbv2model.HealthCheckMatcher {
421
+ HTTPCode : awssdk .String ("200" ),
422
+ },
423
+ },
424
+ {
425
+ name : "HTTP2, without annotation configured" ,
426
+ fields : fields {
427
+ defaultHealthCheckMatcherHTTPCode : "200" ,
428
+ defaultHealthCheckMatcherGRPCCode : "12" ,
429
+ },
430
+ args : args {
431
+ svcAndIngAnnotations : nil ,
432
+ tgProtocolVersion : elbv2model .ProtocolVersionHTTP2 ,
433
+ },
434
+ want : elbv2model.HealthCheckMatcher {
435
+ HTTPCode : awssdk .String ("200" ),
436
+ },
437
+ },
438
+ {
439
+ name : "GRPC, without annotation configured" ,
440
+ fields : fields {
441
+ defaultHealthCheckMatcherHTTPCode : "200" ,
442
+ defaultHealthCheckMatcherGRPCCode : "12" ,
443
+ },
444
+ args : args {
445
+ svcAndIngAnnotations : nil ,
446
+ tgProtocolVersion : elbv2model .ProtocolVersionGRPC ,
447
+ },
448
+ want : elbv2model.HealthCheckMatcher {
449
+ GRPCCode : awssdk .String ("12" ),
450
+ },
451
+ },
452
+ {
453
+ name : "HTTP1, with annotation configured" ,
454
+ fields : fields {
455
+ defaultHealthCheckMatcherHTTPCode : "200" ,
456
+ defaultHealthCheckMatcherGRPCCode : "12" ,
457
+ },
458
+ args : args {
459
+ svcAndIngAnnotations : map [string ]string {
460
+ "alb.ingress.kubernetes.io/success-codes" : "200-300" ,
461
+ },
462
+ tgProtocolVersion : elbv2model .ProtocolVersionHTTP1 ,
463
+ },
464
+ want : elbv2model.HealthCheckMatcher {
465
+ HTTPCode : awssdk .String ("200-300" ),
466
+ },
467
+ },
468
+ {
469
+ name : "HTTP2, with annotation configured" ,
470
+ fields : fields {
471
+ defaultHealthCheckMatcherHTTPCode : "200" ,
472
+ defaultHealthCheckMatcherGRPCCode : "12" ,
473
+ },
474
+ args : args {
475
+ svcAndIngAnnotations : map [string ]string {
476
+ "alb.ingress.kubernetes.io/success-codes" : "200-300" ,
477
+ },
478
+ tgProtocolVersion : elbv2model .ProtocolVersionHTTP2 ,
479
+ },
480
+ want : elbv2model.HealthCheckMatcher {
481
+ HTTPCode : awssdk .String ("200-300" ),
482
+ },
483
+ },
484
+ {
485
+ name : "GRPC, with annotation configured" ,
486
+ fields : fields {
487
+ defaultHealthCheckMatcherHTTPCode : "200" ,
488
+ defaultHealthCheckMatcherGRPCCode : "12" ,
489
+ },
490
+ args : args {
491
+ svcAndIngAnnotations : map [string ]string {
492
+ "alb.ingress.kubernetes.io/success-codes" : "0" ,
493
+ },
494
+ tgProtocolVersion : elbv2model .ProtocolVersionGRPC ,
495
+ },
496
+ want : elbv2model.HealthCheckMatcher {
497
+ GRPCCode : awssdk .String ("0" ),
498
+ },
499
+ },
500
+ }
501
+ for _ , tt := range tests {
502
+ t .Run (tt .name , func (t * testing.T ) {
503
+ task := & defaultModelBuildTask {
504
+ annotationParser : annotations .NewSuffixAnnotationParser ("alb.ingress.kubernetes.io" ),
505
+ defaultHealthCheckMatcherHTTPCode : tt .fields .defaultHealthCheckMatcherHTTPCode ,
506
+ defaultHealthCheckMatcherGRPCCode : tt .fields .defaultHealthCheckMatcherGRPCCode ,
507
+ }
508
+ got := task .buildTargetGroupHealthCheckMatcher (context .Background (), tt .args .svcAndIngAnnotations , tt .args .tgProtocolVersion )
509
+ assert .Equal (t , tt .want , got )
510
+ })
511
+ }
512
+ }
0 commit comments