Commit Graph

2298 Commits

Author SHA1 Message Date
Kubernetes Prow Robot
43bb11b5c1 Merge pull request #131534 from aroradaman/kube-proxy-ipt-init-error-2
kube-proxy: log iptables errors in platformCheckSupported
2025-06-06 21:08:38 -07:00
Daman Arora
858b88bcee kube-proxy: log ipt errors during platformCheckSupported
Signed-off-by: Daman Arora <aroradaman@gmail.com>
2025-06-07 01:14:33 +05:30
Kubernetes Prow Robot
2f94274c88 Merge pull request #131562 from logica0419/kube-proxy-string-concat
Add missing space in string concatenation (kube-proxy)
2025-05-27 13:36:22 -07:00
Kubernetes Prow Robot
ef66667c8e Merge pull request #131243 from danwinship/kube-proxy-cleanup
Improve `kube-proxy --cleanup` / cleanup on kube-proxy mode switch
2025-05-06 09:29:13 -07:00
Kubernetes Prow Robot
0b8133816b Merge pull request #131477 from pohly/golangci-lint@v2
golangci-lint v2
2025-05-02 23:03:55 -07:00
Matthieu MOREL
4adb58565c chore: bump golangci-lint to v2
Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
2025-05-02 12:51:02 +02:00
logica0419
43a0da5880 add missing space in string concatenation (kube-proxy) 2025-04-30 23:35:25 +09:00
Daman Arora
c7a870135a nftables: cleanup service chain checks
A packet can traverse the service-xxxx chains by matching on either
service-ips or service-nodeports verdict map. We masquerade off-cluster
traffic to ClusterIP (when masqueradeAll = false) by adding a rule in
service-xxxx which checks if destination IP is ClusterIP, port and
protocol matches with service specs and source IP doesn't belong to
PodCIDR and masquerade on match.

If the packet reaches the service chain by match on service-ips map,
then ClusterIP, port and protocol are already matching service specs.
If it comes via external-xxxx chain then the destination IP will
never be ClusterIP. Therefore, we can simplify the masquerade
off-cluster traffic to ClusterIP check by simply matching on
destination ip and source ip.

Signed-off-by: Daman Arora <aroradaman@gmail.com>
2025-04-27 01:05:45 +05:30
Kubernetes Prow Robot
b9d2c1b043 Merge pull request #131138 from princepereira/ppereira-130963-endpointcreation
Fix for HNS local endpoint was being deleted instead of the remote endpoint.
2025-04-23 16:00:11 -07:00
Kubernetes Prow Robot
13dd327f0d Merge pull request #130687 from tomma-a/master
Made the unsupportedError msg more readable
2025-04-23 13:31:21 -07:00
Dan Winship
f9c1876b45 Make proxy CleanupLeftovers methods quieter
To make switching to/from nftables easier, kube-proxy runs iptables
and ipvs cleanup when starting in nftables mode, and runs nftables
cleanup when starting in iptables or ipvs mode. But there's no
guarantee that the node actually supports the mode we're trying to
clean up, so don't log errors if it doesn't.
2025-04-10 14:58:37 -04:00
Dan Winship
b61ca041b4 Add some missing cleanup to "kube-proxy --cleanup"
iptables and ipvs were both leaving KUBE-MARK-MASQ behind (even though
the corresponding KUBE-POSTROUTING rule to actually do the masquerade
got deleted).

iptables was failing to clean up its KUBE-PROXY-FIREWALL chain (the
cleanup rules never got updated when that was split out of
KUBE-FIREWALL), and also not cleaning up its canary chain.
2025-04-10 14:58:35 -04:00
Dan Winship
30f1bcadea Add a unit test for iptables.CleanupLeftovers, improve ipvs test 2025-04-10 09:05:23 -04:00
Dan Winship
94530dad7b Move iptables/ipvs/ipset interface creation into CleanupLeftovers
This also fixes it so that ipvs.CleanupLeftovers only deletes
ipvs/ipset stuff once, rather than first deleting all of it on behalf
of the IPv4 Proxier and then no-op "deleting" it all again on behalf
of the IPv6 Proxier.
2025-04-10 09:03:25 -04:00
Prince Pereira
cc42846187 Fix for HNS local endpoint was being deleted instead of the remote endpoint. 2025-04-08 07:10:13 -07:00
Dan Winship
88f8e6697d Implement PreferSameNode traffic distribution in kube-proxy 2025-03-19 08:46:17 -04:00
Dan Winship
c85083589c Clarify hostname vs node name in kube-proxy
Various parts of kube-proxy passed around a "hostname", but it is
actually the name of the *node* kube-proxy is running on, which is not
100% guaranteed to be exactly the same as the hostname. Rename it
everywhere to make it clearer that (a) it is definitely safe to use
that name to refer to the Node, (b) it is not necessarily safe to use
that name with DNS, etc.
2025-03-19 08:46:15 -04:00
Dan Winship
ff640c3679 Minor updates to kube-proxy topology code
Clarify the comments around terminating endpoints.

Remove stale references to the ProxyTerminatingEndpoints feature gate
in the unit tests.
2025-03-19 08:39:13 -04:00
Kubernetes Prow Robot
fe27448ee4 Merge pull request #130833 from rzlink/master
Add Unit Tests for Windows DSR and Overlay Support
2025-03-18 12:45:56 -07:00
Dawei Wei
6186303580 Adding Unit tests for windows-dsr and overlay support 2025-03-17 14:36:39 -07:00
Gaurav Ghildiyal
9aeeb53095 Remove usage of TopologyAwareHints feature-gate from kube-proxy packages.
TopologyAwareHints feature-gate is GA'd and enabled by default since 1.33. Since
it is also locked-to-default, we can remove flag-usages in kube-proxy.

NOTE that as per
https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/feature-gates.md#disablement-tests:
_"Disablement tests are only required to be preserved for components and
libraries that support compatibility version. Tests for node and kubelet are
unaffected by compatibility version."_
2025-03-14 12:06:40 -07:00
Kubernetes Prow Robot
caf541857f Merge pull request #130673 from gauravkghildiyal/kep-4444-ga
Promote ServiceTrafficDistribution feature-gate to GA and update docs with latest descriptions
2025-03-12 08:23:47 -07:00
Kubernetes Prow Robot
e9a3d99f37 Merge pull request #129826 from danwinship/iptables-constructors
fix up iptables construction, kubelet iptables startup messages
2025-03-11 01:17:45 -07:00
Gaurav Ghildiyal
4e317265c7 Remove usage of ServiceTrafficDistribution feature-gate from kube-proxy packages.
ServiceTrafficDistribution feature-gate is GA'd and enabled by default since
1.33. Since it is also locked-to-default, we can remove flag-usages in
kube-proxy.

NOTE that as per
https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/feature-gates.md#disablement-tests:
_"Disablement tests are only required to be preserved for components and
libraries that support compatibility version. Tests for node and kubelet are
unaffected by compatibility version."_
2025-03-09 17:02:20 -07:00
Tim Hockin
e54719bb66 Use randfill, do API renames 2025-03-08 15:18:00 -08:00
Dan Winship
8c98dee1ed Add utiliptables.NewDualStack
Basically all callers want dual-stack-if-possible, so simplify that.

Also, tweak the startup-time checking in kubelet to treat "no iptables
support" as interesting but not an error.
2025-03-08 10:14:17 -05:00
Dan Winship
b62503dd66 Remove a dead error check in winkernel
The cmd/kube-proxy code never passes nil for the node IP any more.
2025-03-07 10:43:58 -05:00
Dan Winship
f001b3916d Remove a stale comment in metaproxier.go
(NodeHandler was implemented in metaProxier a long time ago.)
2025-03-07 10:43:56 -05:00
Dan Winship
303593cafe Fix some pkg/proxy comments
Remove a bunch of comments that are either inaccurate ("the proxier
can only be tested by e2e tests") or weirdly overspecific about
obvious details ("the proxier will not exit if an iptables call
fails").
2025-03-07 10:43:55 -05:00
Dan Winship
b5e9a8262e Remove exec arg from utilipset.New
Historically it took an exec argument so you could pass a FakeExec to
mock its behavior in unit tests, but it has a fake implementation now
that is much more useful for unit tests than trying to use the real
implementation with a fake exec. (The unit tests still use fake execs,
but they don't need to use a public constructor.) So remove the exec
args from the public constructors.
2025-03-07 10:43:52 -05:00
Dan Winship
36f5820ad1 Remove some unused proxy args/fields
Remove the utilexec.Interface args from the iptables/ipvs constructors
(which have been unused since the conntrack cleanup code was ported to
netlink).

Remove the EventRecorder fields from the iptables/ipvs Proxiers, which
have been unused since we removed the port-opener code in 2022.

Remove the strictARP field from the ipvs Proxier, which has apparently
always been unused (strictARP is only looked at at construct time).
2025-03-07 10:43:45 -05:00
Dan Winship
13f0449e4c Fix up kube-proxy import ordering/organization. 2025-03-07 10:43:43 -05:00
Kubernetes Prow Robot
80026570aa Merge pull request #130119 from npinaeva/nft-restart
[kube-proxy: nftables] Optimize kube-proxy restart time
2025-03-04 10:17:44 -08:00
tomma
410ada0022 Made the unsupportedError msg more readable
The unsupportedError msg is little confusing , no space between the ARCH and the "is unsupported" ;  
for example "windows/amd64is unsupported"
2025-03-04 14:32:50 +08:00
Adrian Moisey
438d496555 Add test for ReconcileConntrackFlowsDeletedEntriesTotal metric 2025-03-02 15:58:40 +02:00
Kubernetes Prow Robot
ca22563752 Merge pull request #130484 from aojea/kube_proxy_reconciler_ports
conntrack reconciler must check the dst port
2025-03-01 14:54:55 -08:00
Antonio Ojea
e43de183cf conntrack reconciler must check the dst port
The conntrack reconciler maintains the consistency between the
conntrack table on each node and the desired state of Kubernetes UDP services.

A valid entry matches a service's ClusterIP, LoadBalancerIP, or ExternalIP and Service port,
or any ip matching a NodePort, and has a reverse source IP matching an active endpoint for
that service. Other entries are deleted.

Services without endpoints and traffic not handled by kube-proxy are ignored

Co-authored-by: Daman Arora <aroradaman@gmail.com>
2025-02-28 21:14:06 +00:00
Tim Hockin
c8111709e5 Add an error matcher, convert 2 tests
I fixed up the TestValidateEndpointsCreate path to show the matcher
instead of manual origin checking.

I picked TestValidateTopologySpreadConstraints because it was the last
failing test on my screen when I changed on of the commonly hard-coded
error strings. I fixed exactly those validation errors that were needed
to make this test pass.  Some of the Origin values can be debated.

The `field/testing.Matcher` interface allows tests to configure the
criteria by which they want to match expected and actual errors.  The
hope is that everyone will use Origin for Invalid errors.

There's some collateral impact for tests which use exact-comparisons and
don't expect origins.  These are all candidates for using the matcher.
2025-02-28 08:36:26 -08:00
Nadia Pinaeva
cc0faf086d [kube-proxy:nftables] Skip EP chain updates on startup.
Endpoint chain contents are fairly predictable from their name and
existing affinity sets. Skip endpoint chain updates, when we can be sure
that rules in that chain are still correct.

Add unit test to verify first transaction is optimized.
Change baseRules ordering to make it accepted by nft.ParseDump.

Signed-off-by: Nadia Pinaeva <npinaeva@redhat.com>
2025-02-27 10:07:22 +01:00
Ryota Sakamoto
f484ae5bcb Fix kernel version check condition in nftables proxier
Signed-off-by: Ryota Sakamoto <skmt@amazon.com>
2025-02-24 18:45:16 +00:00
Kubernetes Prow Robot
1b22629615 Merge pull request #130286 from marosset/windows-unit-tests-proxy-winkernel-tests
Fixing k8s.io/kubernetes/pkg/proxy/winkernel unit tests
2025-02-19 15:52:33 -08:00
Kubernetes Prow Robot
1aef26a7eb Merge pull request #130256 from adrianmoisey/netlink-without-tests
Add retries to some netlink calls - without tests
2025-02-19 15:52:26 -08:00
Kubernetes Prow Robot
9f8d5321f0 Merge pull request #130266 from princepereira/ppereira-winproxy-logformat
Introduced additional log formatting to windows kubeproxy.
2025-02-19 14:38:33 -08:00
Mark Rossetti
2b1b20b3b1 Fixing k8s.io/kubernetes/pkg/proxy/winkernel unit tests
Signed-off-by: Mark Rossetti <marosset@microsoft.com>
2025-02-19 11:49:53 -08:00
Prince Pereira
3d007532e0 Introduced additional log formatting to windows kubeproxy. 2025-02-19 01:44:39 -08:00
Adrian Moisey
faf6dc1313 Add retries to runner.List() 2025-02-19 08:29:06 +02:00
Adrian Moisey
b6f49d0728 Add retries to conntracker.ClearEntries()
Signed-off-by: Daman Arora <aroradaman@gmail.com>
2025-02-19 08:29:06 +02:00
Adrian Moisey
90a42e0dc0 Add retries to conntracker.ListEntries()
Signed-off-by: Daman Arora <aroradaman@gmail.com>
2025-02-19 08:29:05 +02:00
Nadia Pinaeva
7d5f3c5723 [kube-proxy:nftables] Read map/set elements on setup.
We used to flush and re-add all map/set elements on nftables
setup, but it is faster to read the existing elements and only
transact the diff.

Signed-off-by: Nadia Pinaeva <npinaeva@redhat.com>
2025-02-18 11:28:41 +01:00
Daman Arora
438df173e3 kube-proxy: metric to track entries deleted in conntrack reconciliation
kubeproxy_conntrack_reconciler_deleted_entries_total can be used
to track total entries deleted in conntrack reconciliation.

Signed-off-by: Daman Arora <aroradaman@gmail.com>
2025-02-17 00:06:20 +05:30