Commit Graph

765 Commits

Author SHA1 Message Date
Patrick Ohly
804ee8c42e client-go remotecommand: avoid "unexpected error" log when there is no error
Normal execution always started to trigger this after adding more logging in
the E2E framework's exec_util.go:

     I0506 21:23:56.781188 6341 exec_util.go:201] unexpected error trying to use websockets for pod exec: <nil>

That the "should fall back" implementation gets called when there is no error
and thus no reason to even consider falling back is odd. Now the execute
implementation checks for nil first.

This is the same approach taken also in the portforward code:
b35c5c0a30/staging/src/k8s.io/client-go/tools/portforward/fallback_dialer.go (L52)

Kubernetes-commit: 35870c480d64a8ae35c0e5839cc40b0115b7328a
2025-05-07 14:51:18 +02:00
Huan Yan
115024100c cleanup: remove error comment of AddIndexers func
Kubernetes-commit: a271d3e5339fa60b661b316a0e2f378f3afc51af
2025-03-16 23:39:33 +08:00
Maciej Szulik
5334fcaa9c Deprecate kubeconfig's preference field in favor of kuberc
Signed-off-by: Maciej Szulik <soltysh@gmail.com>

Kubernetes-commit: 8cf5e8db78deb186ef362f64ab779c09e9520156
2025-05-13 13:39:13 +02:00
Karl Isenberg
921628ecd6 chore: Add VeryShortWatchError typed error
- Add a new VeryShortWatchError struct for error matching, returned
  by `handleAnyWatch`, up through `Reflector.ListAndWatch`.
- Update test expectations to match exact errors.

Kubernetes-commit: 6eff9db0f10db72f2c64390e106a80621d136439
2025-04-15 11:48:57 -07:00
Karl Isenberg
e9ce1dd558 fix: Watcher deadlock from Stop not being called
Change:
- refactor Reflector.ListAndWatch and Reflector.watch to always call
  watcher.Stop.
- refactor Reflector.handleAnyWatch to always call watcher.Stop,
  EXCEPT when exitOnWatchListBookmarkReceived &&
  watchListBookmarkReceived.
- Update unit tests with these new expectations.

Effect:
- ensures watcher.Stop is always called at least once
- avoids deadlocks in watcher implementations when watcher.Watch is
  called, but watcher.Stop is never called.

Note: It's impossible to guarantee that Stop will only be called once.
So watch.Interface implementations must tollerate Stop being called
multiple times.

Kubernetes-commit: 3e609ecf6e945bf4562bddfc563fde9a4c3d0d90
2025-04-11 14:30:29 -07:00
Jordan Liggitt
a3cad0dc91 Clean up leaked goroutines in cache unit tests
Kubernetes-commit: 6747bf7a9cb3009aae4cba1e1d249d56a66a981b
2025-04-01 13:59:32 -04:00
Antonio Ojea
21dc3b4441 benchmark to show inefficient linear search lookup
goos: linux
goarch: amd64
pkg: k8s.io/client-go/tools/cache
cpu: Intel(R) Xeon(R) CPU @ 2.60GHz
BenchmarkLister_Match_1k_100
BenchmarkLister_Match_1k_100-48      	   41910	     28255 ns/op	   16384 B/op	       1 allocs/op
BenchmarkLister_Match_10k_100
BenchmarkLister_Match_10k_100-48     	    3487	    337728 ns/op	  163848 B/op	       1 allocs/op
BenchmarkLister_Match_100k_100
BenchmarkLister_Match_100k_100-48    	     222	   7040793 ns/op	 1605659 B/op	       1 allocs/op
BenchmarkLister_Match_1M_100
BenchmarkLister_Match_1M_100-48      	      12	  97962328 ns/op	16007172 B/op	       1 allocs/op
PASS
ok  	k8s.io/client-go/tools/cache	10.480s

Kubernetes-commit: 33fbce73ae203ffeb1b9ea63ac43d567d1bdb1ad
2025-03-21 06:09:23 +00:00
Sean Sullivan
c77f9e4f9e Websocket HTTPS proxy support
Kubernetes-commit: f73945aae56b51078318199ff2f0ecae91bc489e
2025-01-29 03:56:55 +00:00
Huan Yan
4ba25ca711 fix: shared informer typos
Kubernetes-commit: b38bfaa2ac99deb28eb8c70fcd9466492b292a01
2025-03-11 20:00:16 +08:00
Jefftree
dbe73bc712 Add LeaseCandidate v1beta1
Kubernetes-commit: 5ba4a90fdad6bf9cdfa69e166aff9786efc9430c
2025-02-19 21:43:35 +00:00
novahe
5c7f206b25 Fix test cases that may potentially cause a panic.
Kubernetes-commit: 9e53371ddaaeab4083fde45e43c803071238e686
2025-03-11 17:41:37 +08:00
Joe Betz
bcd36428c5 Revert PR 125102: Add unit tests to client-go/tools/cache/listers.go
Kubernetes-commit: 37ddc637f55af547862ac41452ade42ed15b778b
2025-03-12 11:43:15 -04:00
0xMALVEE
8410e24e31 testes written for cache/listers.go
Kubernetes-commit: 8e8770961616369ac47149c69e7dc29562578d51
2024-05-23 23:40:18 +06:00
Tim Hockin
4a6072d89f Use randfill, do API renames
Kubernetes-commit: e54719bb6674fac228671e0786d19c2cf27b08a3
2025-02-20 09:45:22 -08:00
Maciej Zimnoch
c1ee4cc22c Return correct error upon websocket message read failure
This fixes variable passed as error reason upon websocker message read failure.
Previously a wrong variable was passed resulting in returning failure with nil error reason.

Kubernetes-commit: e1d3aaf8612c490fae965272a304d74fccf7e294
2025-03-07 12:53:47 +01:00
Jefftree
41d7de3d5a Revert "LeaseCandidate alpha -> beta,"
This reverts commit ac7a95efb092944ad9be0ceecb94a868342af1f1.

Kubernetes-commit: 1a1b566d61f7dd6f7b4b577369a6c3b471c9d239
2025-03-01 14:14:19 +00:00
Jefftree
e6e6fcf176 LeaseCandidate alpha -> beta,
Kubernetes-commit: ac7a95efb092944ad9be0ceecb94a868342af1f1
2025-02-19 21:50:31 +00:00
xin.li
d8b34c3ab2 fix wrong assertion on tests
Signed-off-by: xin.li <xin.li@daocloud.io>

Kubernetes-commit: bc4ae15d77beab23f321bf6547f82c04ba27c3fa
2025-02-22 12:39:01 +08:00
Antonio Ojea
023460f5a8 events: ensure the name is valid
The event Object is created from the referenced Object name, however,
there is no guarantee that the name from the referenced Object will be a
valid Event Name.

For those Objects with name not valid for an Event, generate a new valid
name using an UUID.

Kubernetes-commit: ee36b817df06f84ce1a48ef4d65ed559c3775404
2025-02-20 09:13:56 +00:00
Sean Sullivan
3ead27a3a2 Update websocket logging levels for better debuggability
Kubernetes-commit: d3feb5080c18fa73aa87c81a78d5cac82c6ed06d
2025-02-11 20:20:23 +00:00
Patrick Ohly
57bc261e52 client-go watch: NewIndexerInformerWatcherWithContext -> WithLogger
The ability to automatically stop on context cancellation was new functionality
that adds complexity and wasn't really used in Kubernetes. If someone wants
this, they can add it outside of the function.

A *WithLogger variant avoids the complexity and is consistent with
NewStreamWatcherWithLogger over in apimachinery.

Kubernetes-commit: 1a8d8c9b4a33daf9330434e1ad544ef3571722a3
2025-01-31 10:18:04 +01:00
Patrick Ohly
bad1caabde client-go + apimachinery watch: context support
The Lister and Watcher interfaces only supported methods without context, but
were typically implemented with client-go API calls which need a context. New
interfaces get added using the same approach as in
https://github.com/kubernetes/kubernetes/pull/129109.

Kubernetes-commit: 6688adae142e37114d9dfa8d94cd1d8a91fbcc13
2024-12-20 13:55:47 +01:00
David Eads
f2d9cfb8c8 switch to using the real FIFO
Kubernetes-commit: a9aab298b4738f4ea9111131cdf193a3b1ba14e5
2025-01-10 16:23:23 -05:00
David Eads
43bf1a1b0a make a real FIFO implementation
Kubernetes-commit: 24b43ea96ec60ca2c574ccc6b51c989488ca3210
2025-01-10 16:23:07 -05:00
David Eads
52af3bdc0f Remove cache.ErrRequeue
cache.ErrRequeue advertised itself as a way to requeue failures on a
FIFO, but it suffers the same problems as AddIfNotPresent.  If we do
requeue an item at the end, we'll move the informer back in time.  If we
requeue at the beginning we'll simply wedge FIFO.

We didn't find examples in the wild, but by removing the error type
those impacted will get a compile error and get to decide what action is
most appropriate for their failure.  Most of the time, proceeding to the
next item is best.

Kubernetes-commit: 238c32a1d9b2c72d648193fa8642a53a2884975f
2025-01-20 13:59:43 -05:00
David Eads
d853ccf18c Remove Queue.AddIfNotPresent
Logically a cache.Queue.AddIfNotPresent means that the informer can move
back in time since an older item is placed after newer items.  The
alternative of placing errors at the head of the queue leads to
indefinite memory growth and repeated failures on retry.

Luckily this behavior was behind RetryOnError, which was always set to
false and impossible for normal users to set to true.  By removing the
function and setting, impacted users (none found in a github search)
will get a compile failure.

Kubernetes-commit: 8e77ac000131019d5aa49c19aa1f477f6dac4d59
2025-01-20 13:54:32 -05:00
David Eads
f29637f7f2 shrink the cache.Queue interface to what is actually used
Kubernetes-commit: 0ddab1694579d523e3865c75ca44d6cdf1b0ef93
2025-01-08 15:31:47 -05:00
Tiago Silva
9f1cce41d5 client-go: transform watchErrorStream to wrap the underlying error (#129765)
* `client-go`: transform `watchErrorStream` to wrap the underlying error

This PR transforms the `client-go`'s `watchErrorStream` to wrap the error instead of transforming it into a single string. This enables clients to use `errors.Is/As/Unwrap` with the errors that come out of `StreamWithContext`

Fixes https://github.com/kubernetes/kubernetes/issues/129763

* adjust unit tests

Kubernetes-commit: 067012f5844b7390e7279f575342ae0536f80520
2025-01-23 20:07:37 +00:00
Patrick Ohly
40cace856c client-go/tools/cache: fix TestAddWhileActive
4638ba971661497b147906b8977ae206c9dd6e44 added tracking of the goroutine which
executes informer.Run. In the TestAddWhileActive the original `go
informer.Run()` was left in place, causing a data race between the two
`informer.Run` instances:

==================
WARNING: DATA RACE
Read at 0x00c000262398 by goroutine 5302:
  k8s.io/client-go/tools/cache.(*controller).RunWithContext()
      /home/prow/go/src/k8s.io/kubernetes/staging/src/k8s.io/client-go/tools/cache/controller.go:162 +0x1ad
  k8s.io/client-go/tools/cache.(*sharedIndexInformer).RunWithContext()
      /home/prow/go/src/k8s.io/kubernetes/staging/src/k8s.io/client-go/tools/cache/shared_informer.go:584 +0x6c5
  k8s.io/client-go/tools/cache.(*sharedIndexInformer).Run()
      /home/prow/go/src/k8s.io/kubernetes/staging/src/k8s.io/client-go/tools/cache/shared_informer.go:527 +0x48
  k8s.io/client-go/tools/cache.TestAddWhileActive.gowrap1()
      /home/prow/go/src/k8s.io/kubernetes/staging/src/k8s.io/client-go/tools/cache/shared_informer_test.go:1080 +0x17

Previous write at 0x00c000262398 by goroutine 5301:
  k8s.io/client-go/tools/cache.New()
      /home/prow/go/src/k8s.io/kubernetes/staging/src/k8s.io/client-go/tools/cache/controller.go:142 +0x9de
  k8s.io/client-go/tools/cache.(*sharedIndexInformer).RunWithContext.func1()
      /home/prow/go/src/k8s.io/kubernetes/staging/src/k8s.io/client-go/tools/cache/shared_informer.go:562 +0xa78
  k8s.io/client-go/tools/cache.(*sharedIndexInformer).RunWithContext()
      /home/prow/go/src/k8s.io/kubernetes/staging/src/k8s.io/client-go/tools/cache/shared_informer.go:565 +0x119
  k8s.io/client-go/tools/cache.(*sharedIndexInformer).Run()
      /home/prow/go/src/k8s.io/kubernetes/staging/src/k8s.io/client-go/tools/cache/shared_informer.go:527 +0x44
  k8s.io/client-go/tools/cache.(*sharedIndexInformer).Run-fm()
      <autogenerated>:1 +0x17
  k8s.io/client-go/tools/cache.TestAddWhileActive.(*Group).StartWithChannel.func2()
      /home/prow/go/src/k8s.io/kubernetes/staging/src/k8s.io/apimachinery/pkg/util/wait/wait.go:55 +0x38
  k8s.io/apimachinery/pkg/util/wait.(*Group).Start.func1()
      /home/prow/go/src/k8s.io/kubernetes/staging/src/k8s.io/apimachinery/pkg/util/wait/wait.go:72 +0x86

Goroutine 5302 (running) created at:
  k8s.io/client-go/tools/cache.TestAddWhileActive()
      /home/prow/go/src/k8s.io/kubernetes/staging/src/k8s.io/client-go/tools/cache/shared_informer_test.go:1080 +0x93e
  testing.tRunner()
      /usr/local/go/src/testing/testing.go:1690 +0x226
  testing.(*T).Run.gowrap1()
      /usr/local/go/src/testing/testing.go:1743 +0x44

Goroutine 5301 (running) created at:
  k8s.io/apimachinery/pkg/util/wait.(*Group).Start()
      /home/prow/go/src/k8s.io/kubernetes/staging/src/k8s.io/apimachinery/pkg/util/wait/wait.go:70 +0xe4
  k8s.io/apimachinery/pkg/util/wait.(*Group).StartWithChannel()
      /home/prow/go/src/k8s.io/kubernetes/staging/src/k8s.io/apimachinery/pkg/util/wait/wait.go:54 +0x7e6
  k8s.io/client-go/tools/cache.TestAddWhileActive()
      /home/prow/go/src/k8s.io/kubernetes/staging/src/k8s.io/client-go/tools/cache/shared_informer_test.go:1074 +0x6a1
  testing.tRunner()
      /usr/local/go/src/testing/testing.go:1690 +0x226
  testing.(*T).Run.gowrap1()
      /usr/local/go/src/testing/testing.go:1743 +0x44
==================

Kubernetes-commit: d66ced5730fa60c04b0a39df58a156b7045585f6
2025-01-14 14:06:31 +01:00
Patrick Ohly
498e3efe74 client-go cache: fix TestHammerController
The test relied on a 100ms sleep to ensure that controller was done.  If that
race was lost, one goroutine was intentionally prevented from completing by
locking a mutex permanently. A TODO was left about detecting that.

Adding goroutine leak checking in
https://github.com/kubernetes/kubernetes/pull/126387 revealed that this race
indeed sometimes is lost because the goroutine
leaked (https://github.com/kubernetes/kubernetes/issues/129400).

Waiting for controller shutdown instead of relying on timing should fix this.

Kubernetes-commit: 8e1403563a60f3b7a258e3bbb64b5c3a7f6548fb
2024-12-29 12:18:50 +01:00
Patrick Ohly
5d289bc44c client-go/tools/cache: add APIs with context parameter
The context is used for cancellation and to support contextual logging.

In most cases, alternative *WithContext APIs get added, except for
NewIntegerResourceVersionMutationCache where code searches indicate that the
API is not used downstream.

An API break around SharedInformer couldn't be avoided because the
alternative (keeping the interface unchanged and adding a second one with
the new method) would have been worse. controller-runtime needs to be updated
because it implements that interface in a test package. Downstream consumers of
controller-runtime will work unless they use those test package.

Converting Kubernetes to use the other new alternatives will follow. In the
meantime, usage of the new alternatives cannot be enforced via logcheck
yet (see https://github.com/kubernetes/kubernetes/issues/126379 for the
process).

Passing context through and checking it for cancellation is tricky for event
handlers. A better approach is to map the context cancellation to the normal
removal of an event handler via a helper goroutine. Thanks to the new
HandleErrorWithLogr and HandleCrashWithLogr, remembering the logger is
sufficient for handling problems at runtime.

Kubernetes-commit: 4638ba971661497b147906b8977ae206c9dd6e44
2024-07-26 15:26:00 +02:00
Patrick Ohly
b836a27b07 client-go/tools/cache: goroutine leak checking
Several tests leaked goroutines. All of those get fixed where possible
without API changes. Goleak is used to prevent regressions.

One new test specifically covers shutdown of an informer and its event
handlers.

Kubernetes-commit: 0ba43734b4c8998b4aaeb1fa2bec8dee609fa50a
2024-11-28 17:59:36 +01:00
Patrick Ohly
70a4950f35 remove import doc comments
The "// import <path>" comment has been superseded by Go modules.
We don't have to remove them, but doing so has some advantages:

- They are used inconsistently, which is confusing.
- We can then also remove the (currently broken) hack/update-vanity-imports.sh.
- Last but not least, it would be a first step towards avoiding the k8s.io domain.

This commit was generated with
   sed -i -e 's;^package \(.*\) // import.*;package \1;' $(git grep -l '^package.*// import' | grep -v 'vendor/')

Everything was included, except for
   package labels // import k8s.io/kubernetes/pkg/util/labels
because that package is marked as "read-only".

Kubernetes-commit: 8a908e0c0bd96a3455edf7e3b5f5af90564e65b0
2024-12-02 14:43:58 +01:00
Jefftree
bf1a6eed35 v1alpha2 LeaseCandidate API
Kubernetes-commit: 0ce7b688a65a65031c6ee8c616989e4b0be4ce9f
2024-10-04 14:43:11 +00:00
Abu Kashem
e132ac21c9 handle watch for unsafe delete
Kubernetes-commit: 25efc8f2d136a9574166be02789ac727c5b4a3fd
2024-11-05 20:36:56 -05:00
Maciej Szulik
bf414551df Clean error handling in port-forward
This commit introduces:
1. Cleanups in port-forwarding error handling code, which ensures that
   we only compare lowercased text always.
2. E2E verifying that when a pod is removed a port-forward is stopped.

Signed-off-by: Maciej Szulik <soltysh@gmail.com>

Kubernetes-commit: 0b1617ccefbc6ea61c0e7c2b0b4052703f11c51c
2024-10-16 14:02:01 +02:00
Nic
d6404c8d76 fix: draining remote stream after port-forward connection broken
Signed-off-by: Nic <qianyong@api7.ai>

Kubernetes-commit: dbe6b6657bacc846656f4009ee869ca996dde1da
2024-10-04 14:48:15 +08:00
Davanum Srinivas
6c84382029 Use k8s.io/utils/lru instead of github.com/golang/groupcache/lru
Signed-off-by: Davanum Srinivas <davanum@gmail.com>

Kubernetes-commit: 2b0592ee77d0a0bb3017df042066ecb8c83d2fb3
2024-11-01 22:19:11 -04:00
googs1025
1b8aded77b chore(leader-election): modify leader-election comment to OnStoppedLeading callback is always called when the LeaderElector exits, even if it did not start leading.
Kubernetes-commit: 7d2fbc7cfd49bca7d58160ed25dfd1f838629bb9
2024-09-30 09:38:10 +08:00
Federico Bongiovanni
65ed08a834 Update OWNERS
Adding  jefftree also to the reviewers list

Kubernetes-commit: 5f052ada19c43471bdcbb6da4e6f72405ca46bd7
2024-10-22 16:26:30 -07:00
Federico Bongiovanni
29ce700614 Update staging/src/k8s.io/client-go/tools/leaderelection/OWNERS
Co-authored-by: Benjamin Elder <bentheelder@google.com>

Kubernetes-commit: d20bc10645e716034e91d365d17d8b1011d3f1cd
2024-08-14 13:21:52 -07:00
Federico Bongiovanni
3c2f0814df Update OWNERS
Adding jefftree to the owners file for leaderelection

Kubernetes-commit: b5bbc1508f986df7811dd79e7b5116bbede784e8
2024-08-14 12:16:59 -07:00
Alexander Stephan
ce42c297f4 Make getter names for reflector fields idiomatic
Kubernetes-commit: fdabcb5141094cb99afde24ec1df15026b4ba349
2024-10-13 20:53:25 +00:00
Alexander Stephan
146d03f559 Export name and typeDescription members of reflector struct
Kubernetes-commit: 154b8aa8806d743c41d1acf0b498bdecf1767872
2024-09-26 15:09:59 +00:00
Jordan Liggitt
a398951ea1 Implement limited merge function
Kubernetes-commit: 4d8cbad58e21e701af735c5ffa1a9fd3393de096
2024-08-17 21:27:26 -04:00
Jordan Liggitt
56b7eaf344 Narrow merge interface to merging the same types
Kubernetes-commit: 9fde1c6a85c1390c7be7705385eb99b3ebc8e06a
2024-08-17 20:43:53 -04:00
Jordan Liggitt
b3dca7eb8a Isolate mergo use, add test coverage and error checking
Kubernetes-commit: 3b3886a4509a83aff0afe7ad42da9b7819a17aed
2024-08-17 16:42:11 -04:00
Matthieu MOREL
baf58c3d79 fix: enable error-is-as rule from testifylint in module k8s.io/client-go
Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>

Kubernetes-commit: a28c2b6bf8657889c18b683dd42044559a96c304
2024-09-22 12:21:05 +02:00
Stephen Kitt
e996fa7a55 Drop references to auth-path and kubernetes_auth
These are long gone, removed in 2016:
* AuthPath removal: https://github.com/kubernetes/kubernetes/pull/29216
* Flag removal: https://github.com/kubernetes/kubernetes/pull/40048

This removes the remnants from clientcmd, mostly in the comments
describing how the configuration is loaded.

Since getServerIdentificationPartialConfig can no longer fail (it
copies fields from one struct to another), this drops the error
return, along with the error handling in the caller.

Signed-off-by: Stephen Kitt <skitt@redhat.com>

Kubernetes-commit: 8a8238ba7f850241de9c5cc4b22fa1a6b6a19480
2024-07-05 14:55:44 +02:00
guozheng-shen
4d28b8364c endpointsLeasesResourceLock and configMapsLeasesResourceLock are removed too
Kubernetes-commit: a302abb32fc94842c421a4082dfb52be07b16c34
2024-09-19 14:02:52 +08:00