Commit Graph

792 Commits

Author SHA1 Message Date
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
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