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