@@ -809,6 +809,11 @@ func (proxier *Proxier) syncProxyRules() {
809
809
localAddrSet := utilnet.IPSet {}
810
810
localAddrSet .Insert (localAddrs ... )
811
811
812
+ nodeAddresses , err := utilproxy .GetNodeAddresses (proxier .nodePortAddresses , proxier .networkInterfacer )
813
+ if err != nil {
814
+ klog .Errorf ("Failed to get node ip address matching nodeport cidrs %v, services with nodeport may not work as intended: %v" , proxier .nodePortAddresses , err )
815
+ }
816
+
812
817
// We assume that if this was called, we really want to sync them,
813
818
// even if nothing changed in the meantime. In other words, callers are
814
819
// responsible for detecting no-op changes and not calling this function.
@@ -1195,14 +1200,12 @@ func (proxier *Proxier) syncProxyRules() {
1195
1200
if svcInfo .NodePort () != 0 {
1196
1201
// Hold the local port open so no other process can open it
1197
1202
// (because the socket might open but it would never work).
1198
- addresses , err := utilproxy .GetNodeAddresses (proxier .nodePortAddresses , proxier .networkInterfacer )
1199
- if err != nil {
1200
- klog .Errorf ("Failed to get node ip address matching nodeport cidr: %v" , err )
1203
+ if len (nodeAddresses ) == 0 {
1201
1204
continue
1202
1205
}
1203
1206
1204
1207
lps := make ([]utilproxy.LocalPort , 0 )
1205
- for address := range addresses {
1208
+ for address := range nodeAddresses {
1206
1209
lp := utilproxy.LocalPort {
1207
1210
Description : "nodePort for " + svcNameString ,
1208
1211
IP : address ,
@@ -1464,36 +1467,31 @@ func (proxier *Proxier) syncProxyRules() {
1464
1467
1465
1468
// Finally, tail-call to the nodeports chain. This needs to be after all
1466
1469
// other service portal rules.
1467
- addresses , err := utilproxy .GetNodeAddresses (proxier .nodePortAddresses , proxier .networkInterfacer )
1468
- if err != nil {
1469
- klog .Errorf ("Failed to get node ip address matching nodeport cidr" )
1470
- } else {
1471
- isIPv6 := proxier .iptables .IsIPv6 ()
1472
- for address := range addresses {
1473
- // TODO(thockin, m1093782566): If/when we have dual-stack support we will want to distinguish v4 from v6 zero-CIDRs.
1474
- if utilproxy .IsZeroCIDR (address ) {
1475
- args = append (args [:0 ],
1476
- "-A" , string (kubeServicesChain ),
1477
- "-m" , "comment" , "--comment" , `"kubernetes service nodeports; NOTE: this must be the last rule in this chain"` ,
1478
- "-m" , "addrtype" , "--dst-type" , "LOCAL" ,
1479
- "-j" , string (kubeNodePortsChain ))
1480
- writeLine (proxier .natRules , args ... )
1481
- // Nothing else matters after the zero CIDR.
1482
- break
1483
- }
1484
- // Ignore IP addresses with incorrect version
1485
- if isIPv6 && ! utilnet .IsIPv6String (address ) || ! isIPv6 && utilnet .IsIPv6String (address ) {
1486
- klog .Errorf ("IP address %s has incorrect IP version" , address )
1487
- continue
1488
- }
1489
- // create nodeport rules for each IP one by one
1470
+ isIPv6 := proxier .iptables .IsIPv6 ()
1471
+ for address := range nodeAddresses {
1472
+ // TODO(thockin, m1093782566): If/when we have dual-stack support we will want to distinguish v4 from v6 zero-CIDRs.
1473
+ if utilproxy .IsZeroCIDR (address ) {
1490
1474
args = append (args [:0 ],
1491
1475
"-A" , string (kubeServicesChain ),
1492
1476
"-m" , "comment" , "--comment" , `"kubernetes service nodeports; NOTE: this must be the last rule in this chain"` ,
1493
- "-d " , address ,
1477
+ "-m " , "addrtype" , "--dst-type" , "LOCAL" ,
1494
1478
"-j" , string (kubeNodePortsChain ))
1495
1479
writeLine (proxier .natRules , args ... )
1480
+ // Nothing else matters after the zero CIDR.
1481
+ break
1482
+ }
1483
+ // Ignore IP addresses with incorrect version
1484
+ if isIPv6 && ! utilnet .IsIPv6String (address ) || ! isIPv6 && utilnet .IsIPv6String (address ) {
1485
+ klog .Errorf ("IP address %s has incorrect IP version" , address )
1486
+ continue
1496
1487
}
1488
+ // create nodeport rules for each IP one by one
1489
+ args = append (args [:0 ],
1490
+ "-A" , string (kubeServicesChain ),
1491
+ "-m" , "comment" , "--comment" , `"kubernetes service nodeports; NOTE: this must be the last rule in this chain"` ,
1492
+ "-d" , address ,
1493
+ "-j" , string (kubeNodePortsChain ))
1494
+ writeLine (proxier .natRules , args ... )
1497
1495
}
1498
1496
1499
1497
// Drop the packets in INVALID state, which would potentially cause
0 commit comments