Commit Graph

34 Commits

Author SHA1 Message Date
Dan Winship
e2900da46a Remove unnecessary utiliptables.Interface arg from local detectors
getLocalDetector() used to pass a utiliptables.Interface to
NewDetectLocalByCIDR() so that NewDetectLocalByCIDR() could verify
that the passed-in CIDR was of the same family as the iptables
interface. It would make more sense for getLocalDetector() to verify
this itself and just *not call NewDetectLocalByCIDR* if the families
don't match, and that's what the code does now. So there's no longer
any need to pass the utiliptables.Interface to the local detector.
2023-07-05 09:11:23 -04:00
Dan Winship
cefd50a753 Improve the single-stack LocalDetector behavior
1. When bringing up a single-stack kube-proxy in a dual-stack cluster,
allow using either the primary or secondary IP family.

2. Since the earlier config-checking code will already have bailed out
if the single-stack configuration is unusably broken, we don't need to
do that here. Instead, just return a no-op local detector if there are
no usable CIDRs of the expected IP family.
2023-07-05 09:06:25 -04:00
Dan Winship
bfccfa7016 Add names to the getLocalDetector unit tests, use t.Run 2023-07-05 09:06:25 -04:00
Dan Winship
8abfa89e82 Move proxy platformSetup call, and do LocalDetector setup from there 2023-06-30 17:39:36 -04:00
Dan Winship
a74b9fde3a Don't pass around full node in proxy constructor, just pass PodCIDRs 2023-06-30 11:30:17 -04:00
Dan Winship
4962e6eacb Squash detectNodeIP and nodeIPTuple together 2023-06-06 20:48:00 -04:00
Dan Winship
b69b34bec6 Move a kube-proxy unit test to the correct file 2023-06-06 16:01:03 -04:00
Antonio Ojea
26801d6541 kube-proxy avoid race condition using LocalModeNodeCIDR
Since kube-proxy in LocalModeNodeCIDR needs to obtain the PodCIDR
assigned to the node it watches for the Node object.

However, kube-proxy startup process requires to have these watches in
different places, that opens the possibility of having a race condition
if the same node is recreated and a different PodCIDR is assigned.

Initializing the second watch with the value obtained in the first one
allows us to detect this situation.

Change-Id: I6adeedb6914ad2afd3e0694dcab619c2a66135f8
Signed-off-by: Antonio Ojea <aojea@google.com>
2023-06-06 15:03:22 +00:00
Dan Winship
08ce580576 Add ProxyServer.platformSetup
Move the Linux-specific conntrack setup code into a new
"platformSetup" rather than trying to fit it into the generic setup
code.

Also move metrics registration there.
2023-05-23 16:17:04 -04:00
Dan Winship
10a869fc75 Remove duplicated config fields from ProxyServer
Rather than duplicating some of the KubeProxyConfiguration into
ProxyServer, just store the KubeProxyConfiguration itself so later
code can reference it directly.

For the fields that get platform-specific defaults (Mode,
DetectLocalMode), fill the defaults directly into the
KubeProxyConfiguration rather than keeping the original there and the
defaulted version in the ProxyServer.
2023-05-03 10:15:37 -04:00
Dan Winship
c4575c3438 Fix up detect-local-mode validation
Validate the --detect-local-mode value in the API object validation
rather than doing it separately later. Also, remove runtime checks and
unit tests for cases that would be blocked by validation
2023-05-03 08:22:49 -04:00
Paco Xu
e28f3de656
Revert "proxy startup-time config handling cleanup" 2023-04-30 09:05:42 +08:00
Dan Winship
258c4c4251 Remove duplicated config fields from ProxyServer
Rather than duplicating some of the KubeProxyConfiguration into
ProxyServer, just store the KubeProxyConfiguration itself so later
code can reference it directly.

For the fields that get platform-specific defaults (Mode,
DetectLocalMode), fill the defaults directly into the
KubeProxyConfiguration rather than keeping the original there and the
defaulted version in the ProxyServer.
2023-04-27 15:43:35 -04:00
Dan Winship
9d4f10f5d2 Fix up detect-local-mode validation
Validate the --detect-local-mode value in the API object validation
rather than doing it separately later. Also, remove runtime checks and
unit tests for cases that would be blocked by validation
2023-04-27 15:43:35 -04:00
Antonio Ojea
75913e9949 kube-proxy wait for cluster cidr skip delete events 2022-10-18 19:29:09 +00:00
Claudiu Belu
af77381e01 unit tests: Skip Windows-unrelated tests on Windows
Some of the unit tests cannot pass on Windows due to various reasons:

- fsnotify does not have a Windows implementation.
- Proxy Mode IPVS not supported on Windows.
- Seccomp not supported on Windows.
- VolumeMode=Block is not supported on Windows.
- iSCSI volumes are mounted differently on Windows, and iscsiadm is a
  Linux utility.
2022-10-18 12:43:07 +03:00
Dan Winship
1609017f2b kube-proxy: remove ipvs-to-iptables fallback
If the user passes "--proxy-mode ipvs", and it is not possible to use
IPVS, then error out rather than falling back to iptables.

There was never any good reason to be doing fallback; this was
presumably erroneously added to parallel the iptables-to-userspace
fallback (which only existed because we had wanted iptables to be the
default but not all systems could support it).

In particular, if the user passed configuration options for ipvs, then
they presumably *didn't* pass configuration options for iptables, and
so even if the iptables proxy is able to run, it is likely to be
misconfigured.
2022-08-16 09:30:08 -04:00
Surya Seetharaman
7d480d8ac8 Enable local traffic detection using the interface options
This commit adds the framework for the new local detection
modes BridgeInterface and InterfaceNamePrefix to work.

Signed-off-by: Surya Seetharaman <suryaseetharaman.9@gmail.com>
2022-03-25 20:06:12 +01:00
Stephen Augustus
481cf6fbe7
generated: Run hack/update-gofmt.sh
Signed-off-by: Stephen Augustus <foo@auggie.dev>
2021-08-24 15:47:49 -04:00
Antonio Ojea
0cd75e8fec run hack/update-netparse-cve.sh 2021-08-20 10:42:09 +02:00
Christopher M. Luciano
51ed242194
ipvs: check for existence of scheduler module and fail if not found
Signed-off-by: Christopher M. Luciano <cmluciano@us.ibm.com>
2020-10-23 17:17:44 -04:00
Christopher M. Luciano
65ff4e8227
ipvs: log error if scheduler does not exist and fallback to rr
Signed-off-by: Christopher M. Luciano <cmluciano@us.ibm.com>
2020-07-23 13:58:02 -04:00
Christopher M. Luciano
e2a0eddaf0
ipvs: ensure selected scheduler kernel modules are loaded
Signed-off-by: Christopher M. Luciano <cmluciano@us.ibm.com>
2020-07-16 13:21:54 -04:00
Antonio Ojea
56df70b639 kube-proxy detect IP family based on nodeIP
We were detecting the IP family that kube-proxy should use
based on the bind address, however, this is not valid when
using an unspecified address, because on those cases
kube-proxy adopts the IP family of the address reported
in the Node API object.

The IP family will be determined by the nodeIP used by the proxier
The order of precedence is:
1. config.bindAddress if bindAddress is not 0.0.0.0 or ::
2. the primary IP from the Node object, if set
3. if no IP is found it defaults to 127.0.0.1 and IPv4

Signed-off-by: Antonio Ojea <antonio.ojea.garcia@gmail.com>
2020-06-17 14:51:35 +02:00
Tim Hockin
9551ecb7c3 Cleanup: Change "Ip" to "IP" in func and var names 2020-04-10 15:29:50 -07:00
louisgong
d6ea9d7c4c remove duplicate ipvs check 2020-04-07 23:12:09 +08:00
Satyadeep Musuvathy
e053fdd08a Add NodeCIDR for detect-local-mode 2020-03-09 13:44:34 -07:00
Satyadeep Musuvathy
8c6956e5bb Refactor handling of local traffic detection. 2020-02-21 17:57:34 -08:00
Dan Winship
a735c97356 kube-proxy: drop iptables version check
Kube-proxy's iptables mode used to care whether utiliptables's
EnsureRule was able to use "iptables -C" or if it had to implement it
hackily using "iptables-save". But that became irrelevant when
kube-proxy was reimplemented using "iptables-restore", and no one ever
noticed. So remove that check.
2019-08-01 12:05:31 -04:00
Emrecan BATI
90ce2d50d3 Add GetKernelVersion to ipvs.KernelHandler interface
ipvs `getProxyMode` test fails on mac as `utilipvs.GetRequiredIPVSMods`
try to reach `/proc/sys/kernel/osrelease` to find version of the running
linux kernel. Linux kernel version is used to determine the list of required
kernel modules for ipvs.

Logic to determine kernel version is moved to GetKernelVersion
method in LinuxKernelHandler which implements ipvs.KernelHandler.
Mock KernelHandler is used in the test cases.

Read and parse file is converted to go function instead of execing cut.
2019-07-31 22:10:44 +03:00
Àbéjídé Àyodélé
109f1c479e Clean up kube-proxy.
These are based on recommendation from
[staticcheck](http://staticcheck.io/).

- Removes dead type/function along with the import that the function
introduced.
- Removes unused struct fields.
- Removes select nested in a tight for loop, the select does not have a
default, so it will be blocking.
2019-05-09 14:39:03 +00:00
Vallery Lancey
3bb5914548 Updated kube-proxy error strings to not use capitals/punctuation 2019-01-27 14:08:54 -08:00
m1093782566
674a31e4d6 remove ipvs feature gateway 2018-05-30 10:43:16 +08:00
Ryan Hitchman
01a9f83028 Move linux-only getProxyMode tests to a linux-only file. 2018-02-27 13:53:32 -08:00