@@ -1201,31 +1201,36 @@ func Test_buildTargetGroupProtocolVersion(t *testing.T) {
12011201
12021202func Test_buildTargetGroupHealthCheckPort (t * testing.T ) {
12031203 testCases := []struct {
1204- name string
1205- targetGroupProps * elbv2gw.TargetGroupProps
1206- targetType elbv2model.TargetType
1207- svc * corev1.Service
1208- expected intstr.IntOrString
1209- expectErr bool
1204+ name string
1205+ isServiceExternalTrafficPolicyTypeLocal bool
1206+ targetGroupProps * elbv2gw.TargetGroupProps
1207+ targetType elbv2model.TargetType
1208+ svc * corev1.Service
1209+ expected intstr.IntOrString
1210+ expectErr bool
12101211 }{
12111212 {
1212- name : "nil props" ,
1213- expected : intstr .FromString (shared_constants .HealthCheckPortTrafficPort ),
1213+ name : "nil props" ,
1214+ isServiceExternalTrafficPolicyTypeLocal : false ,
1215+ expected : intstr .FromString (shared_constants .HealthCheckPortTrafficPort ),
12141216 },
12151217 {
1216- name : "nil hc props" ,
1217- targetGroupProps : & elbv2gw.TargetGroupProps {},
1218- expected : intstr .FromString (shared_constants .HealthCheckPortTrafficPort ),
1218+ name : "nil hc props" ,
1219+ isServiceExternalTrafficPolicyTypeLocal : false ,
1220+ targetGroupProps : & elbv2gw.TargetGroupProps {},
1221+ expected : intstr .FromString (shared_constants .HealthCheckPortTrafficPort ),
12191222 },
12201223 {
1221- name : "nil hc port" ,
1224+ name : "nil hc port" ,
1225+ isServiceExternalTrafficPolicyTypeLocal : false ,
12221226 targetGroupProps : & elbv2gw.TargetGroupProps {
12231227 HealthCheckConfig : & elbv2gw.HealthCheckConfiguration {},
12241228 },
12251229 expected : intstr .FromString (shared_constants .HealthCheckPortTrafficPort ),
12261230 },
12271231 {
1228- name : "explicit is use traffic port hc port" ,
1232+ name : "explicit is use traffic port hc port" ,
1233+ isServiceExternalTrafficPolicyTypeLocal : false ,
12291234 targetGroupProps : & elbv2gw.TargetGroupProps {
12301235 HealthCheckConfig : & elbv2gw.HealthCheckConfiguration {
12311236 HealthCheckPort : awssdk .String (shared_constants .HealthCheckPortTrafficPort ),
@@ -1234,7 +1239,8 @@ func Test_buildTargetGroupHealthCheckPort(t *testing.T) {
12341239 expected : intstr .FromString (shared_constants .HealthCheckPortTrafficPort ),
12351240 },
12361241 {
1237- name : "explicit port" ,
1242+ name : "explicit port" ,
1243+ isServiceExternalTrafficPolicyTypeLocal : false ,
12381244 targetGroupProps : & elbv2gw.TargetGroupProps {
12391245 HealthCheckConfig : & elbv2gw.HealthCheckConfiguration {
12401246 HealthCheckPort : awssdk .String ("80" ),
@@ -1243,7 +1249,8 @@ func Test_buildTargetGroupHealthCheckPort(t *testing.T) {
12431249 expected : intstr .FromInt32 (80 ),
12441250 },
12451251 {
1246- name : "resolve str port" ,
1252+ name : "resolve str port" ,
1253+ isServiceExternalTrafficPolicyTypeLocal : false ,
12471254 svc : & corev1.Service {
12481255 Spec : corev1.ServiceSpec {
12491256 Ports : []corev1.ServicePort {
@@ -1262,8 +1269,9 @@ func Test_buildTargetGroupHealthCheckPort(t *testing.T) {
12621269 expected : intstr .FromInt32 (80 ),
12631270 },
12641271 {
1265- name : "resolve str port - instance" ,
1266- targetType : elbv2model .TargetTypeInstance ,
1272+ name : "resolve str port - instance" ,
1273+ isServiceExternalTrafficPolicyTypeLocal : false ,
1274+ targetType : elbv2model .TargetTypeInstance ,
12671275 svc : & corev1.Service {
12681276 Spec : corev1.ServiceSpec {
12691277 Ports : []corev1.ServicePort {
@@ -1283,7 +1291,8 @@ func Test_buildTargetGroupHealthCheckPort(t *testing.T) {
12831291 expected : intstr .FromInt32 (1000 ),
12841292 },
12851293 {
1286- name : "resolve str port - resolves to other str port (error)" ,
1294+ name : "resolve str port - resolves to other str port (error)" ,
1295+ isServiceExternalTrafficPolicyTypeLocal : false ,
12871296 svc : & corev1.Service {
12881297 Spec : corev1.ServiceSpec {
12891298 Ports : []corev1.ServicePort {
@@ -1303,8 +1312,9 @@ func Test_buildTargetGroupHealthCheckPort(t *testing.T) {
13031312 expectErr : true ,
13041313 },
13051314 {
1306- name : "resolve str port - resolves to other str port but instance mode" ,
1307- targetType : elbv2model .TargetTypeInstance ,
1315+ name : "resolve str port - resolves to other str port but instance mode" ,
1316+ isServiceExternalTrafficPolicyTypeLocal : false ,
1317+ targetType : elbv2model .TargetTypeInstance ,
13081318 svc : & corev1.Service {
13091319 Spec : corev1.ServiceSpec {
13101320 Ports : []corev1.ServicePort {
@@ -1324,8 +1334,9 @@ func Test_buildTargetGroupHealthCheckPort(t *testing.T) {
13241334 expected : intstr .FromInt32 (1000 ),
13251335 },
13261336 {
1327- name : "resolve str port - cant find configured port" ,
1328- targetType : elbv2model .TargetTypeInstance ,
1337+ name : "resolve str port - cant find configured port" ,
1338+ isServiceExternalTrafficPolicyTypeLocal : false ,
1339+ targetType : elbv2model .TargetTypeInstance ,
13291340 svc : & corev1.Service {
13301341 Spec : corev1.ServiceSpec {
13311342 Ports : []corev1.ServicePort {
@@ -1344,12 +1355,23 @@ func Test_buildTargetGroupHealthCheckPort(t *testing.T) {
13441355 },
13451356 expectErr : true ,
13461357 },
1358+ {
1359+ name : "with ExternalTrafficPolicyTypeLocal and HealthCheckNodePort specified" ,
1360+ isServiceExternalTrafficPolicyTypeLocal : true ,
1361+ svc : & corev1.Service {
1362+ Spec : corev1.ServiceSpec {
1363+ HealthCheckNodePort : 32000 ,
1364+ ExternalTrafficPolicy : corev1 .ServiceExternalTrafficPolicyTypeLocal ,
1365+ },
1366+ },
1367+ expected : intstr .FromInt32 (32000 ),
1368+ },
13471369 }
13481370
13491371 for _ , tc := range testCases {
13501372 t .Run (tc .name , func (t * testing.T ) {
13511373 builder := targetGroupBuilderImpl {}
1352- res , err := builder .buildTargetGroupHealthCheckPort (tc .targetGroupProps , tc .targetType , tc .svc )
1374+ res , err := builder .buildTargetGroupHealthCheckPort (tc .targetGroupProps , tc .targetType , tc .svc , tc . isServiceExternalTrafficPolicyTypeLocal )
13531375 if tc .expectErr {
13541376 assert .Error (t , err , res )
13551377 return
@@ -1421,7 +1443,7 @@ func Test_buildTargetGroupHealthCheckProtocol(t *testing.T) {
14211443 loadBalancerType : tc .lbType ,
14221444 }
14231445
1424- res := builder .buildTargetGroupHealthCheckProtocol (tc .targetGroupProps , tc .tgProtocol )
1446+ res := builder .buildTargetGroupHealthCheckProtocol (tc .targetGroupProps , tc .tgProtocol , false )
14251447 assert .Equal (t , tc .expected , res )
14261448 })
14271449 }
@@ -1470,7 +1492,7 @@ func Test_buildTargetGroupHealthCheckPath(t *testing.T) {
14701492 defaultHealthCheckPathGRPC : grpcDefaultPath ,
14711493 }
14721494
1473- res := builder .buildTargetGroupHealthCheckPath (tc .targetGroupProps , tc .tgProtocolVersion , tc .hcProtocol )
1495+ res := builder .buildTargetGroupHealthCheckPath (tc .targetGroupProps , tc .tgProtocolVersion , tc .hcProtocol , false )
14741496 assert .Equal (t , tc .expected , res )
14751497 })
14761498 }
@@ -1575,10 +1597,10 @@ func Test_basicHealthCheckParams(t *testing.T) {
15751597 }
15761598
15771599 for _ , prop := range defaultProps {
1578- assert .Equal (t , int32 (1 ), builder .buildTargetGroupHealthCheckIntervalSeconds (prop ))
1579- assert .Equal (t , int32 (2 ), builder .buildTargetGroupHealthCheckTimeoutSeconds (prop ))
1580- assert .Equal (t , int32 (3 ), builder .buildTargetGroupHealthCheckHealthyThresholdCount (prop ))
1581- assert .Equal (t , int32 (4 ), builder .buildTargetGroupHealthCheckUnhealthyThresholdCount (prop ))
1600+ assert .Equal (t , int32 (1 ), builder .buildTargetGroupHealthCheckIntervalSeconds (prop , false ))
1601+ assert .Equal (t , int32 (2 ), builder .buildTargetGroupHealthCheckTimeoutSeconds (prop , false ))
1602+ assert .Equal (t , int32 (3 ), builder .buildTargetGroupHealthCheckHealthyThresholdCount (prop , false ))
1603+ assert .Equal (t , int32 (4 ), builder .buildTargetGroupHealthCheckUnhealthyThresholdCount (prop , false ))
15821604 }
15831605
15841606 filledInProps := & elbv2gw.TargetGroupProps {
@@ -1593,10 +1615,10 @@ func Test_basicHealthCheckParams(t *testing.T) {
15931615 Matcher : nil ,
15941616 }}
15951617
1596- assert .Equal (t , int32 (10 ), builder .buildTargetGroupHealthCheckIntervalSeconds (filledInProps ))
1597- assert .Equal (t , int32 (20 ), builder .buildTargetGroupHealthCheckTimeoutSeconds (filledInProps ))
1598- assert .Equal (t , int32 (30 ), builder .buildTargetGroupHealthCheckHealthyThresholdCount (filledInProps ))
1599- assert .Equal (t , int32 (40 ), builder .buildTargetGroupHealthCheckUnhealthyThresholdCount (filledInProps ))
1618+ assert .Equal (t , int32 (10 ), builder .buildTargetGroupHealthCheckIntervalSeconds (filledInProps , false ))
1619+ assert .Equal (t , int32 (20 ), builder .buildTargetGroupHealthCheckTimeoutSeconds (filledInProps , false ))
1620+ assert .Equal (t , int32 (30 ), builder .buildTargetGroupHealthCheckHealthyThresholdCount (filledInProps , false ))
1621+ assert .Equal (t , int32 (40 ), builder .buildTargetGroupHealthCheckUnhealthyThresholdCount (filledInProps , false ))
16001622}
16011623
16021624func Test_targetGroupAttributes (t * testing.T ) {
0 commit comments