Commit Graph

810 Commits

Author SHA1 Message Date
Lukasz Szaszkiewicz
2fe4ac239c downgrade reflector watchlist fallback log to V(4)
Kubernetes-commit: 3f42ca14011e972ee439a27d47415bc7574f2317
2025-12-04 16:14:19 +01:00
Jordan Liggitt
171ef8cd00 Use transformer in consistency checker
Kubernetes-commit: 91368adbb556286942d996c60ab6cc39306415b7
2025-11-26 15:19:00 -05:00
Valerian Roche
7cf6a05732 Add unit tests for Data Consistency Detector
Kubernetes-commit: 76da8d6de027a4bf62601d45b8d72f8fa627ab5c
2025-07-28 13:53:34 -04:00
Valerian Roche
f466f58eea [client-go #1415] Embed proper interface in TransformingStore to ensure DeltaFIFO and RealFIFO are implementing it
Signed-off-by: Valerian Roche <valerian.roche@datadoghq.com>

Kubernetes-commit: 88c20d46a4e5ca8db7519c81856a358c919ae262
2025-07-28 13:53:34 -04:00
Peter Engelbert
c529a209c2 Add client-go credential plugin to kuberc
Remove reference to internal types in kuberc types

* Remove unserialized types from public APIs

Also remove defaulting

* Don't do conversion gen for plugin policy types

Because the plugin policy types are explicitly allowed to be empty, they
should not affect conversion. The autogenerated conversion functions for
the `Preference` type will leave those fields empty.

* Remove defaulting tests

Comments and simplifications (h/t jordan liggitt)

Signed-off-by: Peter Engelbert <pmengelbert@gmail.com>

Kubernetes-commit: fab280950dabfefabe6a8578b7a76372a9b21874
2025-10-24 16:06:33 -04:00
Min Jin
d5cd2dd65f Adding batch handling for popping items from RealFIFO
Signed-off-by: Min Jin <minkimzz@amazon.com>

Update staging/src/k8s.io/client-go/tools/cache/the_real_fifo.go

optimizing fifo loop

Co-authored-by: Marek Siarkowicz <marek.siarkowicz@protonmail.com>
Signed-off-by: Min Jin <minkimzz@amazon.com>

refactoring PopBatch to accept []Delta

Signed-off-by: Min Jin <minkimzz@amazon.com>

Kubernetes-commit: 611b4c1408f529de4d4e94e6dd33be2ed1df9276
2025-10-24 18:07:32 -07:00
Lukasz Szaszkiewicz
562096cc40 k8s.io/client-go/tools/cache/test: wrap the LW with toListWatcherWithUnSupportedWatchListSemantics
Kubernetes-commit: ae201951a8a39316d4154a07592f464293764a83
2025-09-20 22:57:14 +02:00
Lukasz Szaszkiewicz
83eab51fe2 client-go/tools/watch/test: wrap the LW with toListWatcherWithUnSupportedWatchListSemantics
Kubernetes-commit: 9e462123d6495f6f7ed6e0a7c40c2ddf04ba10fc
2025-09-29 13:59:40 +02:00
Marek Siarkowicz
5ac9ec00af Benchmark SharedIndexInformer
Kubernetes-commit: 7a9d718cdf5e26f83ce45cd5b24f06ef7e678bea
2025-10-22 16:22:40 +02:00
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