Commit Graph

682 Commits

Author SHA1 Message Date
Lukasz Szaszkiewicz
0280901a4d client-go/reflector: warns when the bookmark event for initial events hasn't been received
Kubernetes-commit: 93960f489069a744afda1be42f82349e25d7e4d7
2024-04-29 15:18:54 +02:00
jiuker
f9eba8e8c3 fix: Hang when canceling leader election information
Hang when canceling leader election information.
Occasionally, two leaders may run simultaneously.

Kubernetes-commit: b6b46a0e00682517d2ca7b7e9c2706b8e407e52e
2024-04-28 15:06:51 +08:00
Wojciech Tyczyński
2fe05741c1 Fix race in informer transformers
Kubernetes-commit: e9f74597a8e7104b26640614e952d4453654453b
2024-04-17 11:19:08 +02:00
Stephen Kitt
841e997e33 Improve the lister function documentation
In particular, document that ListAllByNamespace delegates to ListAll
if no namespace is specified.

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

Kubernetes-commit: 54e899317ef46e3b70827cacee244717022db0ad
2024-04-19 17:58:02 +02:00
Claudiu Belu
79c893df5a Replaces path.Operation with filepath.Operation (staging)
The path module has a few different functions:
Clean, Split, Join, Ext, Dir, Base, IsAbs. These functions do not
take into account the OS-specific path separator, meaning that they
won't behave as intended on Windows.

For example, Dir is supposed to return all but the last element of the
path. For the path "C:\some\dir\somewhere", it is supposed to return
"C:\some\dir\", however, it returns ".".

Instead of these functions, the ones in filepath should be used instead.

Kubernetes-commit: 856bb5c8f266f5276f1a576f47be622d7cb384e7
2022-06-15 15:17:24 +03:00
Wojciech Tyczyński
b9e952f4d7 Allow for configuring MinWatchTimeout in Reflector and Informer.
Kubernetes-commit: 29e38c19b853b6cc3950541b1727395acf5eb4d3
2024-04-09 09:12:54 +02:00
Wojciech Tyczyński
7da319745b Refactor informer constructors
Kubernetes-commit: 4da185a601e1f657a873dfd7e51efcc8a3b94c37
2024-04-09 09:06:38 +02:00
Lan Liang
fa185a21db cleanup: delete rand.Seed(time.Now().UnixNano()) and using global number generator.
see https://tip.golang.org/doc/go1.20

Signed-off-by: Lan Liang <gcslyp@gmail.com>

Kubernetes-commit: dc992adad385ab631e4a528ee6a342ea71e7a379
2024-03-18 08:10:12 +00:00
Lukasz Szaszkiewicz
45e17fede0 client-go/cache/reflector: use metav1.InitialEventsAnnotationKey
Kubernetes-commit: a953539fb57b2ee18337f323ef15425a4d6207ed
2024-03-11 12:56:40 +01:00
Nilekh Chaudhari
02f21344ac feat: implements svm controller
Signed-off-by: Nilekh Chaudhari <1626598+nilekhc@users.noreply.github.com>

Kubernetes-commit: 9161302e7fd3a5fb055b2f2572c6e1228240bb51
2024-01-04 19:34:05 +00:00
Sean Sullivan
62aace94ab Adds OWNERS files to client-go streaming dirs
Kubernetes-commit: 855bc74023900b31095de72ae49c79d5d391aad5
2024-03-05 20:21:48 +00:00
Mike Spreitzer
61be9f118e Add DeletionHandlingObjectToName
Signed-off-by: Mike Spreitzer <mspreitz@us.ibm.com>

Kubernetes-commit: d60a25b2db52d7e180b0962e23cc06e71f36fb29
2024-01-26 13:28:06 -05:00
Sean Sullivan
ae38726e6e extend deadlines to one minute
Kubernetes-commit: b04d1177efb0cfc84b76732848eef8f0ea89b25b
2024-03-04 11:31:56 -08:00
Sean Sullivan
4b03fda005 re-write fallback dialer unit test
Kubernetes-commit: 33af937b4a5f4eb5c5005bddb483317f042da515
2024-03-04 10:52:59 -08:00
Sean Sullivan
79f21dcaa8 removes extra upgrade aware proxy logging; returns tunneling connection close error
Kubernetes-commit: e8bbb221d36f1adf4116752990c0c4f17a9e5deb
2024-03-02 16:10:39 -08:00
Sean Sullivan
271d034e86 portforward: tunnel spdy through websockets
Kubernetes-commit: 8b447d8c97e8823b4308eb91cf7d75693e867c61
2024-02-21 08:56:07 +00:00
Sean Sullivan
f759d2e976 increases client-side websocket write deadline to 30 seconds
Kubernetes-commit: 1d4be7527f8b2d2c4eb6dcc7ef58b4c3133f6f19
2024-03-01 18:16:44 -08:00
Jordan Liggitt
27b1407865 Keep streams from being set up after closeAllStreamReaders is called
Kubernetes-commit: 6c1a935da2df8e6ccf1ea6afcf51cb288f355356
2024-02-29 15:31:55 -05:00
Jordan Liggitt
36a771f98c Make websocket heartbeat test timing less flaky
Kubernetes-commit: 26484df2108eff8ad6e06dfc960eae3bdfbf4663
2024-02-29 15:10:28 -05:00
Sean Sullivan
7eae79e001 remote command turn on feature gates
Kubernetes-commit: a147693deb2e7f040cf367aae4a7ae5d1cb3e7aa
2024-02-13 14:10:40 -08:00
Patrick Ohly
2231ff5ae4 client-go events: support context.Background() as context
If, for whatever reason, the context was context.Background(), the additional
goroutine was started and then got stuck forever because
context.Background().Done() is a nil channel. Found when indirectly
instantiating a broadcaster with such a context:

    found unexpected goroutines:
    [Goroutine 9106 in state chan receive (nil chan), with k8s.io/kubernetes/vendor/k8s.io/client-go/tools/record.NewBroadcaster.func1 on top of the stack:
	goroutine 9106 [chan receive (nil chan)]:
	k8s.io/kubernetes/vendor/k8s.io/client-go/tools/record.NewBroadcaster.func1()
		/home/prow/go/src/k8s.io/kubernetes/_output/local/go/src/k8s.io/kubernetes/vendor/k8s.io/client-go/tools/record/event.go:206 +0x2c
	created by k8s.io/kubernetes/vendor/k8s.io/client-go/tools/record.NewBroadcaster in goroutine 8957
		/home/prow/go/src/k8s.io/kubernetes/_output/local/go/src/k8s.io/kubernetes/vendor/k8s.io/client-go/tools/record/event.go:205 +0x1a5

This can be fixed by checking for a nil channel.

Another problem also gets addressed: if Shutdown was called without canceling
the context, the goroutine also didn't stop. Now it waits for the cancelation
context and thus terminates in both cases.

Kubernetes-commit: eed6e29a5b8cfaa20fbc426541d9c74105d430ee
2023-12-01 18:35:28 +01:00
José Carlos Chávez
76174b8af8 chore: adds consistent vanity import to files and provides tooling for verifying and updating them. (#120642)
* chore: drops update vanity imports from script.

* chore: changes copyright year to 2024.

* chore: makes lint happy.

Kubernetes-commit: 6d6398ef9266abce3518a4c9a3d4e4d8feeffdc1
2024-02-08 13:38:07 +00:00
Ivo Gosemann
89528c43be k8s.io/client-go: add OverridingClientConfig overriding RawConfig
Kubernetes-commit: 740b4c456d731922196f8231df9ab585198696d6
2023-07-18 13:40:12 +02:00
Ivo Gosemann
17b5405ddb k8s.io/client-go: add ClientConfig option to override raw config
Kubernetes-commit: db80aa56ed8bcf4115e30fc62d27c8a8d8ec7f92
2023-07-18 13:40:12 +02:00
Lukasz Szaszkiewicz
202c415847 client-go/reflector: make UseWatchList a pointer
until #115478(use streaming against the etcd storage)
is resolved the cacher need a way to disable the streaming.

Kubernetes-commit: 41e706600aea7468f486150d951d3b8948ce89d5
2024-01-19 13:48:29 +01:00
Patrick Ohly
8468c261bc client-go events: also support context for NewEventBroadcasterAdapter
27a68aee3a4834 introduced context support. In order to use that
also with NewEventBroadcasterAdapter, a variant of the call is needed to allow
the caller to specify the context.

The `logcheck:context` comment ensures that code which is meant to be
contextual uses the new call.

Kubernetes-commit: f8e25eff926c640c86daa46222bfaf8d625e75d7
2023-12-01 09:00:59 +01:00
Eric Lin
2a48f1ee02 leaderelection: Instrument for when slowpath is exercised
Signed-off-by: Eric Lin <exlin@google.com>

Kubernetes-commit: 1e54c050936be1a1e3e5758718ebca86096dbaea
2023-11-27 13:10:24 +00:00
Eric Lin
3c7c00d2d6 leaderelection: optimistically update leader lock
Signed-off-by: Eric Lin <exlin@google.com>

Kubernetes-commit: 1d9f7fd516b4787f5ef32692711d5ae3031e794e
2023-11-25 22:04:32 +00:00
John Howard
785e19661f client-go: allow adding indexes after informer starts
Kubernetes-commit: d96a9858d396d7f418d24ea47bdc92ef8429f707
2023-03-31 15:57:18 -07:00
Sean Sullivan
b7d73dd18c StreamTranslator and FallbackExecutor for WebSockets
Kubernetes-commit: 168998e87bfd49a1b0bc6402761fafd5ace3bb3b
2023-07-06 21:22:07 -07:00
tao.yang
0447e1f9ce cleanup: omit comparison with bool constants
Signed-off-by: tao.yang <tao.yang@daocloud.io>

Kubernetes-commit: b35357b6c08f21ba0fd312536051394c2567ec79
2023-09-04 16:59:23 +08:00
Lukasz Szaszkiewicz
0f984dc7fc client-go/reflector: introduce a data consistency mechanism for the watch-list feature.
checkWatchListConsistencyIfRequested performs a data consistency check only when
the KUBE_WATCHLIST_INCONSISTENCY_DETECTOR environment variable was set during a binary startup.

The consistency check is meant to be enforced only in the CI, not in production.
The check ensures that data retrieved by the watch-list api call
is exactly the same as data received by the standard list api call.

Note that this function will panic when data inconsistency is detected.
This is intentional because we want to catch it in the CI.

Kubernetes-commit: b31e7793d0d873a71c90caf8455556aa905cf88d
2023-10-06 14:26:47 +02:00
Arda Güçlü
583e50d008 Use timeout function to detect transient errors
Kubernetes-commit: a888fef242fd59bc3871c67099c7f5e9449873c2
2023-10-06 08:55:22 +03:00
Arda Güçlü
9a88950e38 revert back to IsUnexpectedCloseError check
Kubernetes-commit: 914210ee9a6df6927019f200e90534edd1460fea
2023-10-05 12:04:06 +03:00
Arda Güçlü
e95d92dbc6 Close websocket heartbeat explicitly when unexpected closure received
Kubernetes-commit: e1ae906048003145441fb1d4ecce4c13acf5cb19
2023-10-03 12:05:26 +03:00
Patrick Ohly
cf07629bfe k8s.io/client-go/tools/events: pass context into EventSink methods
Because the EventBroadcaster code now has a a context, changing the EventSink
interface so that the methods accepts a context instead of using context.TODO
becomes possible.

Kubernetes-commit: 5dc540ff57eed5d0e6bc8476f95fe03b7a983cf5
2023-09-18 12:17:14 +02:00
Patrick Ohly
3595e5242a k8s.io/client-go/tools: support context for event recording
Using StartRecordingToSinkWithContext instead of StartRecordingToSink and
StartLogging instead of StartStructuredLogging has several advantages:

- Spawned goroutines no longer get stuck for extended periods of
  time during shutdown when passing in a context that gets canceled.
- Log output can be directed towards a specific logger instead of the global
  default, for example one which writes to a testing.T instance.
- The new methods return an error when something went wrong instead of
  merely recording the error.

That last point is the reason for deprecating the old methods instead of merely
adding new alternatives.

Setting a context when constructing an EventBroadcaster makes calling Shutdown
optional. It can also be used to specify the logger.

Both EventRecorder interfaces in tools/events and tools/record now have a
WithLogger helper. Using that method is optional, but recommended to support
contextual logging properly. Without it, errors that occur while emitting an
event are not associated with the caller.

Kubernetes-commit: 27a68aee3a48340f7c14235f7fc24aa69aaeb8f6
2023-09-18 09:13:22 +02:00
Lukasz Szaszkiewicz
1e0855a7ac reflector: fallback to the previous mode on any error
originally we honored only apierrors.IsInvalid
but decided to fallback on every error
because it is better to make progress than deadlocking

Kubernetes-commit: 4b3915017950a114124a88c5d308bd8bfb9ec48e
2023-10-04 08:17:10 +02:00
Lukasz Szaszkiewicz
2c9d749027 reflector: close an established watcher when the StopCh was closed
Kubernetes-commit: 26f113be2fc71c7a41a59145eee5d4da9d062b9e
2023-10-03 13:49:21 +02:00
Antonio Ojea
011db228a8 deflake TestWebSocketClient_HeartbeatSucceeds
Change-Id: I1f3331255ed81183b25ec24084c00d0cf7dfb510

Kubernetes-commit: 4a74958b2df7ecd9e6a4867f7b10f1402cb2e215
2023-09-25 10:31:46 +00:00
Lukasz Szaszkiewicz
d0ea06d597 cache/reflector: check the value of the initial-events-end annotation
Kubernetes-commit: 04668c00432cbd552b08eb94f829643facbd2061
2023-09-19 12:59:23 +02:00
Antonio Ojea
ea6e035481 add loging and bump timers to avoid races
Change-Id: I6da35b6fb33c939f3f92f8ebf4c6a18bdf1644e4

Kubernetes-commit: 40618b765ccb1a0e75f7063534f9645d1df57f7a
2023-09-15 08:23:58 +00:00
devincd
f242a563ef fix typo in client-go package
Signed-off-by: devincd <505259926@qq.com>

Kubernetes-commit: 975da2fb2393350db504e50652b17c70206e1407
2023-09-08 10:31:07 +08:00
Sean Sullivan
fd1e22bd8f WebSocket Client and V5 RemoteCommand Subprotocol
Kubernetes-commit: a0d6a815fcc02cbfea1bb22d13a8e896ecbe116c
2023-07-06 21:22:07 -07:00
Dr. Stefan Schimanski
00f8b3aa35 client-go: log proper 'caches populated' message, with type and source and only once
Signed-off-by: Dr. Stefan Schimanski <stefan.schimanski@gmail.com>

Kubernetes-commit: a1809ffae377f3abbae12b137073ca4c473743cd
2023-08-07 12:56:32 +02:00
Stephen Kitt
caded3c2dc api-machinery: stop using deprecated io/ioutil
This replaces deprecated ioutil functions as follows:

* ioutil.ReadAll -> io.ReadAll
* ioutil.ReadFile -> os.ReadFile
* ioutil.TempDir -> os.MkdirTemp
* ioutil.TempFile -> os.CreateTemp
* ioutil.WriteFile -> os.WriteFile

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

Kubernetes-commit: b60a3a58df2791ae67764f6325be31aea5eca5a0
2023-05-02 15:08:18 +02:00
Michal Fojtik
0cde78477a client-go: add DNS resolver latency metrics (#115357)
* client-go: add DNS resolver latency metrics

* client-go: add locking to DNS latency metrics

* client-go: add locking for whole DNSStart and DNSDone

Signed-off-by: Vu Dinh <vudinh@outlook.com>

* Fix a mismatched ctx on the request

Signed-off-by: Vu Dinh <vudinh@outlook.com>

* Clean up request code and fix comments

Signed-off-by: Vu Dinh <vudinh@outlook.com>

---------

Signed-off-by: Vu Dinh <vudinh@outlook.com>
Co-authored-by: Vu Dinh <vudinh@outlook.com>

Kubernetes-commit: 1c7e87cff27aa009488a9d55342220e223d5c146
2023-06-28 22:56:45 +02:00
Sunil Shivanand
aea98eb150 combine conditional checks
Signed-off-by: Sunil Shivanand <sunil.shivanand@statnett.no>

Kubernetes-commit: 80480f8e21572cba152a4f6f171ebb5de8c6bafb
2023-01-11 09:45:37 +01:00
Sunil Shivanand
0d54cf50db handle event errors caused due to terminating namespaces
Create events are forbidden in terminating namespaces, use info
instead of error to log the failed event.

Signed-off-by: Sunil Shivanand <sunil.shivanand@statnett.no>

Kubernetes-commit: 7a6d58001b7d824f92601fd246b3aad9fbb9c583
2023-01-05 12:56:40 +01:00
Chris Bandy
3ffcfabea2 Replace os.Setenv with testing.T.Setenv in tests
T.Setenv ensures that the environment is returned to its prior state
when the test ends. It also panics when called from a parallel test to
prevent racy test interdependencies.

Kubernetes-commit: ac5ce5cbce7ddb6ffeff755d1cf670afadb8e1fb
2023-06-05 21:03:21 -05:00