Commit Graph

40 Commits

Author SHA1 Message Date
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
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
mprahl
2176e80333 Stop the RetryWatcher when failing due to permissions issue
When the client does not have permission to watch a resource, the
RetryWatcher continuously retried. In this case, it's better to send an
error and stop retrying to let the caller handle this case since this is
not a transient error that can be recovered without user intervention.

This is particularly helpful in applications that leverage a user
provided service account and the application needs to notify the user to
set the correct permissions for the service account.

This also accounts for invalid credentials from the watch client.

Signed-off-by: mprahl <mprahl@users.noreply.github.com>

Kubernetes-commit: db2218d16e3fb2a30b21ffa0f307beb515d8394b
2024-07-11 13:50:52 -04:00
mprahl
001900e4e9 Allow calling Stop multiple times on RetryWatcher
This makes the Stop method idempotent so that if Stop is called multiple
times, it does not cause a panic due to closing a closed channel.

Signed-off-by: mprahl <mprahl@users.noreply.github.com>

Kubernetes-commit: a54ba917be42c941edf1a0359dced04e1a5e1d6f
2024-07-16 10:55:26 -04:00
Karl Isenberg
7c5e9038dd Update TestNewInformerWatcher for WatchListClient
- Switch to using the ProxyWatcher to validate the dance between
  closing the stop channel and closing the result channel.
- Use the new clientfeaturestesting.SetFeatureDuringTest to test with
  the WatchListClient enabled and disabled. These should result in
  almost the exact same output events from the informer
  (list ordering not garenteed), but with different input events
  recieved from the apiserver.

Kubernetes-commit: 28e3a728e5e6fe651d7a17839d33ce42204c0b4e
2024-06-03 17:31:59 -07:00
Msk233
5d5619d392 stop watcher when error occurs
Kubernetes-commit: da3e7e3781650024e4cc7cb65082908c531e8efa
2023-04-26 09:04:33 +08:00
Hao Ruan
ef522cc423 replace spew methods with dump methods
Kubernetes-commit: c4e1b01416ec05e6a520a181d4ce3b4333adb4e4
2023-04-13 09:41:07 +08:00
Tim Hockin
12553015e2 Replace uses of ObjectReflectDiff with cmp.Diff
ObjectReflectDiff is already a shim over cmp.Diff, so no actual output
or behavior changes

Kubernetes-commit: bc302fa4144d21a338683cd83701661f97be4aba
2023-03-23 11:34:03 -07:00
Hao Ruan
db3650d98f replaced spew.Sprintf with a util pretty print function
Kubernetes-commit: f638e2849fbddeb201b8290586a4747af99086bf
2023-01-04 14:12:56 +08:00
Clayton Coleman
250fc3d6b4 wait: Update tests to reference the constant error
The structure of the error is changing, and we don't guarantee
reflect.DeepEqual(...) will remain true for ErrWaitTimeout currently.

Kubernetes-commit: 8d4004bbc77d012642db97e09238f4f65a926bca
2023-03-10 11:02:59 -06:00
Arda Güçlü
21fffc1153 Embed context deadline exceeded in error to let errors.Is can work
Currently, watch package embeds context deadlineexceeded error
in it's own error using `%v`, as can be seen in here;

`fmt.Errorf("UntilWithSync: unable to sync caches: %v", ctx.Err())`

However, consumers of this function can not use
`errors.Is(err, context.DeadlineExceeded)` due this `%v`.

To let consumers can distinguish context deadlineexceeded errors,
this PR changes error embedding format to `%w`.

Kubernetes-commit: 6b7c365f8f6d50280c2dab171efdd4b93d964f32
2022-12-19 15:26:08 +03:00
Jordan Liggitt
422fe1f61e Fix indentation/spacing in comments to render correctly in godoc
Kubernetes-commit: 78cb3862f11225135afdf76f3424e2d7b33104c7
2022-12-17 17:31:05 -05:00
Davanum Srinivas
2a6c116e40 Generate and format files
- Run hack/update-codegen.sh
- Run hack/update-generated-device-plugin.sh
- Run hack/update-generated-protobuf.sh
- Run hack/update-generated-runtime.sh
- Run hack/update-generated-swagger-docs.sh
- Run hack/update-openapi-spec.sh
- Run hack/update-gofmt.sh

Signed-off-by: Davanum Srinivas <davanum@gmail.com>

Kubernetes-commit: a9593d634c6a053848413e600dadbf974627515f
2022-07-19 20:54:13 -04:00
Mikhail Mazurskiy
7a08020ed2 Make sleep interruptible
Kubernetes-commit: b705a521d8814b38faabea218097cac65d6ab5c5
2021-08-21 12:20:30 +10:00
Dean Coakley
53da6da2bc Remove outdated comment on wait.Until
Kubernetes-commit: 53fef4a04598c3b1ee04c4930a29dbad5bb9ca63
2020-08-20 02:08:17 +01:00
pacoxu
06efd86142 Migrate client-go retry-watcher to structured logging
Co-authored-by: Marek Siarkowicz <marek.siarkowicz@protonmail.com>

Kubernetes-commit: c4dc34e8cbad41968c50763f79280e7cd14dabee
2021-02-18 19:06:34 +08:00
Chotiwat Chawannakul
a35bc8fe7a Fix stale object causing a panic on DELETE event
Kubernetes-commit: 1f4f78ac414b7a1666e908670c5e447015bdc6b9
2021-01-06 10:38:31 -08:00
knight42
a922620591 test(watch-tool): deflake TestRetryWatcherToFinishWithUnreadEvents
Signed-off-by: knight42 <anonymousknight96@gmail.com>

Kubernetes-commit: 1d92314f262548b6b24e309943274e0d9d196a41
2020-09-05 17:19:47 +08:00
Davanum Srinivas
75fea27a27 switch over k/k to use klog v2
Signed-off-by: Davanum Srinivas <davanum@gmail.com>

Kubernetes-commit: 442a69c3bdf6fe8e525b05887e57d89db1e2f3a5
2020-04-17 15:25:06 -04:00
wojtekt
16393a6dc7 Remove ListWatchUntil
Kubernetes-commit: ead12b02fed9e8c3a8ebf693f71fa452115d923b
2020-05-07 20:21:46 +02:00
wojtekt
c16c96a7f1 Request for bookmarks in RetryWatcher
Kubernetes-commit: 7a65760f6e914e5421b443980831b2965c6954c7
2020-05-06 19:37:57 +02:00
Jordan Liggitt
33c1f9f2a4 Fix client watch reestablishment handling of client-side timeouts
Kubernetes-commit: 343c1e7636fe5c75cdd378c0b170b26935806de5
2020-03-30 10:36:01 -04:00
Mike Danese
60a0346672 generated: run refactor
Kubernetes-commit: 3aa59f7f3077642592dc8a864fcef8ba98699894
2020-02-07 18:16:47 -08:00
RainbowMango
532b6f676e Cleanup staticcheck issues for package in client-go.
Kubernetes-commit: c8c055b3163dd2661b3f9dd1b0ffb718a61aba24
2019-08-26 20:55:32 +08:00
Mike Danese
ba0da5aa4d NewIndexerInformerWatcher: fix goroutine leak
There was some weird queuing going on. The queue was implement by
spawning goroutines that would block on the "ticketer" until it was
their turn to write to the output channel. If N events where in the
watch when the consumer of the watch stopped reading events, N
goroutines would leak. In unit tests of the certificate manager, this
was causing ~10k goroutines to leak.

Fix it with a buffering event processor that uses only one routine and
cancels correctly.

Kubernetes-commit: cafc640bfa0f7362b178b1b896085962d018afe3
2019-05-03 23:50:53 -04:00
fansong.cfs
94d52886d7 add watch bookmark
Kubernetes-commit: d70edd3d39d4430d71c4b7c9adba8df5ba7f16c8
2019-03-19 18:16:23 +08:00
Tomas Nozicka
54b354c5dc Handle unstructured status in RetryWatcher
Kubernetes-commit: 8302b5b262c506ff7d363338f980ce204d574354
2019-03-08 09:34:56 +01:00
Tomas Nozicka
c04fc653fa Fix race in RetryWatcher's unit tests
Kubernetes-commit: b39d079b69a9ae6063204278dcd44d98d2315aa1
2019-02-27 16:35:55 +01:00
Tomas Nozicka
8ecda4e5ed Upgrade ListWatchUntil
Kubernetes-commit: 603dd254ac91b3581f9b431ff91a95d929a97e04
2019-02-18 18:20:23 +01:00
Tomas Nozicka
ce00ab47ae Add Until based on RetryWatcher
Kubernetes-commit: 09af8485f253421cdf0c20a40d12784e8fcffd5a
2019-01-03 13:45:46 +01:00
Jordan Liggitt
e6881e4a02 Update client callers to use explicit versions
Kubernetes-commit: d1e865ee341ba37469efed8c935e22e2b483eec2
2019-02-22 10:27:46 -05:00
Tomas Nozicka
36160aac1b Make UntilWithSync wait for integrated informers to stop
Kubernetes-commit: b762d2c0d7977a93ee9aab4cefb9363bc0c79ea5
2019-01-21 18:30:00 +01:00
Yang Li
f3619f04f1 Call cancel functions to avoid context leaks
Kubernetes-commit: 8dc9619d44ce2074696a4036b2acdc21f3cd0662
2018-11-18 17:40:35 +08:00
Davanum Srinivas
74cd8bbeee Move from glog to klog
- Move from the old github.com/golang/glog to k8s.io/klog
- klog as explicit InitFlags() so we add them as necessary
- we update the other repositories that we vendor that made a similar
change from glog to klog
  * github.com/kubernetes/repo-infra
  * k8s.io/gengo/
  * k8s.io/kube-openapi/
  * github.com/google/cadvisor
- Entirely remove all references to glog
- Fix some tests by explicit InitFlags in their init() methods

Change-Id: I92db545ff36fcec83afe98f550c9e630098b3135

Kubernetes-commit: 954996e231074dc7429f7be1256a579bedd8344c
2018-11-09 13:49:10 -05:00
Tomas Nozicka
4528feba43 Add UntilWithSync (informer based)
Kubernetes-commit: 866cc1acab6c1c30a7550b2de7160c8052be884d
2018-08-03 16:45:41 +02:00
Tomas Nozicka
6dac86f710 Deprecate ListWatchUntil, fix it and call places
Kubernetes-commit: e434f3189e81e473aa89e3589ca81545d1341cf8
2018-08-03 16:08:28 +02:00
Tomas Nozicka
82acb64076 Move ListWatchUntil to its kin
Kubernetes-commit: 07b8373ab393547239ed4fe227758a1715480f22
2018-08-03 15:22:42 +02:00
Tomas Nozicka
cbdb98d74d Rename Until to UntilWithoutRetry and move to using context so it's
cancelable

Kubernetes-commit: 3d4a02abb54244861f9f05b8db2fdfdaa2c6f67c
2018-08-02 14:11:59 +02:00
Tomas Nozicka
5764fa1b79 Move Until from apimachinery to client-go
Kubernetes-commit: ccb92f6ef867c9e2ede91b7877a492a161986623
2018-08-01 19:35:46 +02:00