Commit Graph

801 Commits

Author SHA1 Message Date
xigang
00a491e0ce Add RealFIFOOptions struct to provide structured configuration for RealFIFO
Signed-off-by: xigang <wangxigang2014@gmail.com>

Kubernetes-commit: 26bbea8c07131080f763c4ccc1eda5daa66803a6
2025-06-12 08:19:21 +08:00
Lukasz Szaszkiewicz
3502696346 client-go/tools/cache/reflector: supports watchlist.DoesClientNotSupportWatchListSemantics
Kubernetes-commit: 4bb2bd05322e127658e55a06995c021b3c5fbc41
2025-09-25 15:36:17 +02:00
Lukasz Szaszkiewicz
6777feb020 client-go/tools/cache/listwatch: intro ToListWatcherWithWatchListSemantics
returns a ListerWatcher that knows whether the provided client explicitly
does NOT support the WatchList semantics. This allows Reflectors
to adapt their behavior based on client capabilities.

Kubernetes-commit: 3b93755c0c07ce898f1c2a3924adef6c3143f247
2025-10-12 00:29:31 +02:00
Jefftree
38c61c9925 Add nil scheme check in GetReference
Kubernetes-commit: 051b29bde3817ceb22b157dabf32615ce383f319
2025-09-25 14:28:17 +00:00
Nikita B
2ab8e3619f [client-go] [cli-runtime] [133916]: handle properly config override logic when override provides ClientKey, ClientCertificate: use values from overrides when one of the field (file or data) is present in inverrides
Signed-off-by: Nikita B <n2h9z4@gmail.com>

Kubernetes-commit: 6b908c192cc828abef39c35dcc4921281f950958
2025-09-08 07:01:44 +02:00
Nikita B
e703bc019f [client-go] [cli-runtime] [133916]: handle properly config override logic when override provides ClientKey, ClientCertificate
Signed-off-by: Nikita B <n2h9z4@gmail.com>

Kubernetes-commit: fc8907da38dc1a6af7d7b2c18d87c1dd35ca8c68
2025-09-06 14:05:59 +02:00
Max Celant
c28edcd52c Replace deprecated sets.String with sets.Set for Index type
updating to include initialization in func

Update store to use sets.Set

updating tests to use sets.New instead of sets.NewString

update store_test

update index_test

update controller_test file

update delta_fifo file

update expiration_cache_fakes file

update index_test file

update thread_safe_store file

update events_cache file

update thread_safe_store_test

update expiration_cache_test

small refactor of for loop

unexport the Index type -> index

Kubernetes-commit: c08b9ab3b5c78023e46ce03fde894b24533c68ef
2025-09-07 21:37:30 -05:00
yshngg
dc29e94395 refactor(event): simplify conditional logic in event handling for both v1 and eventsv1 APIs
Signed-off-by: yshngg <yshngg@outlook.com>

Kubernetes-commit: 7685612b9c24c3129e0e17a6f6874b5902de02a1
2025-08-29 17:02:56 +08:00
Patrick Ohly
b65019457b client-go leader-election: structured, contextual logging
Kubernetes-commit: 63f304708a0fab5078739415f589eff9f2e9dfc7
2025-08-25 16:28:53 +02:00
DerekFrank
048fbed845 gofmt and review feedback
Kubernetes-commit: 2180b441dd748bcaf9c1c8a28d20f6565e14f189
2025-08-18 09:52:15 -07:00
DerekFrank
706156ceaf fix: Update unit test to catch actual nil Labels case and fix functionality to handle nil Labels
Kubernetes-commit: 8d4108bf9355b086e7f8996e84723ca389db887a
2025-08-15 14:28:18 -07:00
David Bimmler
6294eedf76 cache: do not allocate chan for nothing (#133500)
* cache: do not allocate chan for nothing

The explicit purpose of this channel is to never be closed and nothing
to be sent down on it. Hence, there's no need to allocate a channel - a
nil channel has exactly the desired behaviour.

Additionally, this is more relevant now that testing/synctest gets
unhappy when goroutines are blocked on reading on channels which are
created outside of the synctest bubble. Since this is a package var, that's
hard to avoid when using this package. Synctest is fine with nil
channels though.

Reported-by: Jussi Maki <jussi@isovalent.com>
Signed-off-by: David Bimmler <david.bimmler@isovalent.com>

* handlers: do not allocate chan for nothing

Nil chan has the desired semantics already, and this breaks
testing/synctest because the channel is allocated outside of the bubble.

Signed-off-by: David Bimmler <david.bimmler@isovalent.com>

---------

Signed-off-by: David Bimmler <david.bimmler@isovalent.com>

Kubernetes-commit: 52b7d035f9655d0c6ebeaaafd60add99700bb468
2025-08-28 03:53:15 +00:00
Mikhail Mazurskiy
d21662ddfc Decouple term and remotecommand packages
This allows consumers of term to not pull in dependencies on
github.com/gorilla/websocket and github.com/moby/spdystream.

Kubernetes-commit: 640dabd58b04b72f646ed85947cb8b407b36dc08
2025-08-03 20:35:40 +10:00
Ethan Pini
af0e2a11af kubectl: Fix current-context being written to wrong file
This is what happens when writing back a OIDC refresh token:

 - plugin/pkg/client/auth/oidc/oidc.go:282
   Calls `Persist` to save the new refresh token.

 - tools/clientcmd/config.go:372
   Calls `ModifyConfig` to save the config.

 - tools/clientcmd/config.go:167
   Calls `configAccess.GetLoadingPrecedence()` to get the files
   listed from the `KUBECONFIG` environment variable.

 - tools/clientcmd/loader.go:334
   If the `ConfigAccess` was a `ClientConfigLoadingRules`, it
   directly returns the `Precedence` slice from its `rules`
   field.

   THE PROBLEM:
     The slice can be modified by the caller, unintentionally
     changing the value of the `ClientConfigLoadingRules`'
     `Precedence` field.

 - tools/clientcmd/config.go:170
   Then proceeds to in-place sort the slice returned by the
   `ConfigAccess`. This is the same slice (by identity)
   as the `ClientConfigLoadingRules`' `Precedence` field,
   destroying its intended order.

 - tools/clientcmd/config.go:179
   Calls `configAccess.GetStartingConfig` to read the original
   config so it can be compared with the new config.

 - tools/clientcmd/loader.go:339
   Calls `NewNonInteractiveDeferredLoadingClientConfig` with
   itself as a parameter.

   CONSEQUENCE:
     At this point, its the `Precedence` has been
     unintentionally sorted. When it loads the
     config again, it gives precedence to whichever
     file comes first in ascending alphabetical order.

 - tools/clientcmd/config.go:192
   If the file returned by `GetStartingConfig` has a
   different `current-context` than the new config,
   it calls `writeCurrentContext` to update the first
   kubeconfig file in the `KUBECONFIG` environment
   variable.

 - tools/clientcmd/config.go:403
   Calls `configAccess.GetDefaultFilename` to find the
   destination kubeconfig file.

 - tools/clientcmd/loader.go:358
   Iterates through the kubeconfig files returned by
   `GetLoadingPreferences` to find the first file
   that exists.

   CONSEQUENCE:
     With the slice being sorted earlier, the files
     returned by this call of `GetLoadingPreferences`
     will be sorted alphabetically, rather than by
     their intended order.

Kubernetes-commit: ffa084f81129ea685b176a282921c4d54906c539
2025-04-14 15:19:04 -07:00
Mayuka Channankaiah
753cfe1811 client-go, kubectl: Replace deprecated ErrWaitTimeout with recommended method (#132718)
* client-go: Replace depracted ErrWaitTimeout with recommended method

* Fix UT and Integration tests

* IT test

Kubernetes-commit: ffe306d67958297202e9492ea644b42c0e7e694d
2025-07-24 20:26:27 +05:30
Šimon Lukašík
2d84553721 ci cleanup: make sure to remove test KUBECONFIGs
Calling os.Exit() skipped the

    `defer os.RemoveAll(tmp)`

above and thus dangling files & dirs would appear in their $TMPDIR.

Since go1.15 we can safely remove os.Exit() from TestMain() function.
As this exact issue was common enough so that go1.15 changed[1] the API of
TestMain to no longer require os.Exit to be called.

Reproducer:

    $ (cd staging/src/k8s.io/client-go; go test ./tools/clientcmd)
    $ ls -d /tmp/testkubeconfig*
    /tmp/testkubeconfig1015943687

[1]: https://go-review.googlesource.com/c/go/+/219639

Kubernetes-commit: 457df1cf9817e29381609fbf2d85854a6b6a52ac
2025-07-21 10:46:37 +02:00
Keisuke Ishigami
e36950929b set the timeout to Get method
Kubernetes-commit: 300c7b815a2eb9598c53c0b386715650f5052804
2025-07-17 22:33:32 +09:00
Keisuke Ishigami
be4c8bc002 fix test
Kubernetes-commit: 9a7dddf5a713e109418f3726514fdf60246ada3b
2025-07-15 01:07:43 +09:00
Keisuke Ishigami
3633ea23d3 chore
Kubernetes-commit: 09ec6f744833fb72a319013ae25cf0286cdd125e
2025-07-15 01:07:25 +09:00
Keisuke Ishigami
b62c1cc29f add test which checks release method calls Get
Kubernetes-commit: f20be4c094cdc037e54d755dcd6292991cee701d
2025-07-14 23:17:19 +09:00
Keisuke Ishigami
500bfe00cd Prevent the failure of releasing the lock by updating the resource version in case of a resource conflict
Kubernetes-commit: 271233a62aeab02eb0f7a6567d3ddba6d09a4f21
2025-07-10 02:59:21 +09:00
Lukasz Szaszkiewicz
c1d15a3638 reflector: detects unsupported meta.Table gvks for watchlist
Kubernetes-commit: da7c55e0d2f962c8493864a069be5acb8902579f
2025-07-14 13:13:44 +02:00
xuzhenglun
2f016580ef make sure all streams are created before starting demux websocket
Kubernetes-commit: 3379d5ac4b6a1afbbaead06689a8584ce546a275
2025-07-08 18:31:30 +08:00
Keisuke Ishigami
d9cda8802e resolve linter check
Kubernetes-commit: 5cca03792748714547c39330ac9cb8cb9c7c60ae
2025-06-27 00:49:02 +09:00
Keisuke Ishigami
fc748aa158 Revert "pop respects the context"
This reverts commit 1c33d98762511c10f89c40358a1935250b03b0c8.

Kubernetes-commit: 74af3ac8ad1122528bb9971c3a2d282eff529beb
2025-06-26 23:49:34 +09:00
Keisuke Ishigami
bc19363821 Revert "modify tests"
This reverts commit 2cd5dbbdaab98020b37df7125f622db7a6dd885a.

Kubernetes-commit: 2dcce93336e52eb16aab595fcc75254f4abfa5ae
2025-06-26 23:49:25 +09:00
Keisuke Ishigami
00429ab356 modify tests
Kubernetes-commit: 2cd5dbbdaab98020b37df7125f622db7a6dd885a
2025-06-14 22:04:22 +09:00
Keisuke Ishigami
d56ed5816f pop respects the context
Kubernetes-commit: 1c33d98762511c10f89c40358a1935250b03b0c8
2025-06-14 21:59:56 +09:00
Keisuke Ishigami
03728c1ebe handle context in process loop
Kubernetes-commit: f67d30b3529ea970dd5fd069eaddfc7f61d74169
2025-05-29 00:34:43 +09:00
PatrickLaabs
735f105e54 chore: depr. pointer pkg replacement for the reflactor
Kubernetes-commit: 9345552274d2999c59a609488d0673edbb3a246e
2025-07-03 11:27:00 +02:00
Arthur Befumo
6980728f27 Fix AuthInfo godoc for Token / TokenFile precedence (#132659)
* Fix AuthInfo godoc for Token / TokenFile precedence

* nit

* update

Kubernetes-commit: 33cd2e1ba08bf6b936c0c2c29bcabe502ce75851
2025-07-02 11:55:24 -04:00
Valerian Roche
71776a84bd [client-go #1415] Use transformer from provided store within internal stores in reflector to limit memory usage bursts
Signed-off-by: Valerian Roche <valerian.roche@datadoghq.com>

Kubernetes-commit: 585ed0a5cb378e794e4775bc846d5309ca65f2c6
2025-06-26 22:00:41 -04:00
Lukasz Szaszkiewicz
1785b5afec client-go/reflector: stop exposing UseWatchList (#132453)
* client-go/reflector: stop exposing UseWatchList

* apiserver/cacher: stop setting reflector.UseWatchList

* test/integration/watchlist: fix TestReflectorWatchListFallback

Kubernetes-commit: b8b3984874e930c92057589fd1a7668dbdffc117
2025-06-25 13:04:29 +02:00
likakuli
d158bb37c5 feat: optimize ListAll and ListAllByNamespace to return directly when nothing to select
Signed-off-by: likakuli <1154584512@qq.com>

Kubernetes-commit: 5a7e04b6cc70bd7624536e09b4e977e8f25cb476
2025-06-12 17:33:32 +08:00
Patrick Ohly
4e28a08da3 client-go: call out WithContext inconsistency
This raises awareness so that developers hopefully get it right without having to
learn about it from compile errors. It also explains that creating a PR to
fix the naming is not desired.

Kubernetes-commit: f40892f4813f29fc305d59073d2464a1fd7d6fe5
2025-05-08 14:29:21 +02:00
Derek Frank
34f791d2b1 feat: Allow leases to have custom labels set when a new holder has the lease
Kubernetes-commit: 109ae1bacadfa5c8655adb4594762c77b135f446
2025-05-06 10:43:05 -07:00
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