Commit Graph

216 Commits

Author SHA1 Message Date
Lukasz Szaszkiewicz 9bfd27dc1c apiserver/storage: use metav1.InitialEventsAnnotationKey const
Kubernetes-commit: ed2b92c3dfb7d56155021824f0d9a61609dac051
2024-03-11 11:40:21 +01:00
Marek Siarkowicz 7a3a726271 Undo double run of the TestWatchSemantics test to avoid hitting timeout
Kubernetes-commit: 225749eb68b3aa3485a1f2dc5d0cafb5dfe53421
2024-03-19 15:16:52 +01:00
Marek Siarkowicz 13a815b7c8 Serve watch without resourceVersion from cache and introduce a WatchFromStorageWithoutResourceVersion feature gate to allow serving watch from storage.
Kubernetes-commit: 0130072b053f85fb736c24d34552208cdd1bccfe
2024-03-14 15:20:29 +01:00
Marek Siarkowicz 67b6245fc3 Fix enabling consistent list from watch cache also works for resourceVersion=0
Kubernetes-commit: 0b8e79580eb3a63ca7707626b4894adfb9125586
2024-03-04 19:35:34 +01:00
Lukasz Szaszkiewicz b8c7d7868f apiserver/storage/cacher: deflake TestGetListNonRecursiveWithConsistentListFromCache
Kubernetes-commit: c44cc9a575f3bf1248b2fdc8e3a7ba61ab844618
2024-03-14 09:08:29 +01:00
Lukasz Szaszkiewicz a2c5722d64 apiserver/storage/cacher: decrease running time of TestWatchNotHangingOnStartupFailure
before:
go test -v -race -count 1 -run ^TestWatchNotHangingOnStartupFailure$
ok  	k8s.io/apiserver/pkg/storage/cacher	6.775s

after:
go test -v -race -count 1 -run ^TestWatchNotHangingOnStartupFailure$
ok  	k8s.io/apiserver/pkg/storage/cacher	2.781s

Kubernetes-commit: f5d945eb43c7bf8036a4bad8c22448e1146a7498
2024-03-14 08:59:47 +01:00
Lukasz Szaszkiewicz c14671349b apiserver/storage/cacher: decrease of running time of TestWaitUntilWatchCacheFreshAndForceAllEvents
The individual cases can be safely run in parallel.

Before
go test -race  -run TestWaitUntilWatchCacheFreshAndForceAllEvents
ok  	k8s.io/apiserver/pkg/storage/cacher	10.787s

After:
go test -race  -run TestWaitUntilWatchCacheFreshAndForceAllEvents
ok  	k8s.io/apiserver/pkg/storage/cacher	4.857s

Kubernetes-commit: 3ecbb4dee00a5dd1e43e24a5952c2a90ef507ef1
2024-03-12 10:50:44 +01:00
Lukasz Szaszkiewicz 80f9ab2a6a apiserver/storage/cacher: decrease of running time of TestEmptyWatchEventCache
updates the test to wait 300 ms instead of 3s
the watch was established otherwise
we would be blocking on a call to cache.Watch(...)
in addition to that, the tests are serial in nature,
meaning that there is no other actor
that could add items to the database,
which could result in receiving new items.

Before:
go test -race  -run TestEmptyWatchEventCache
ok  	k8s.io/apiserver/pkg/storage/cacher	8.450s

After:
go test -race  -run TestEmptyWatchEventCache
ok  	k8s.io/apiserver/pkg/storage/cacher	2.635s

Kubernetes-commit: 926122c035a4f47a880db24d1a0be7ec129dd44d
2024-03-12 13:34:04 +01:00
Marek Siarkowicz 483da2032d Fix non-recursive list when consistent list from cache is enabled
Kubernetes-commit: a527cab9fce0b0234db8b4e1e95a0fc20e135df1
2024-03-04 17:59:04 +01:00
Marek Siarkowicz 3a83dc12eb Fix SetFeatureGateDuringTest handling of Parallel tests
Stop using defer as parallel subtest will might result in main test
finishing before subtest.

Fatal when same flag is set twice.

Kubernetes-commit: 9fcf279e2b91e7549190a433373f256fb5aebe85
2024-03-05 21:56:40 +01:00
Lukasz Szaszkiewicz b3f5f43260 storage/cacher: mark the addition of a metric for waitUntilFreshAndBlock as completed
Kubernetes-commit: 221ad9f7c25cc4da36e97c5feca3fc60bbe5bbfa
2024-03-05 10:23:23 +01:00
Marek Siarkowicz 743b53428c Test that separation of streams work by using progress notifies
Kubernetes-commit: 1cf4cec449cb29718a694e25f4750452af3f491d
2024-02-29 17:51:46 +01:00
Marek Siarkowicz e810084a4b Prevent watch cache starvation, by moving its watch to separate RPC and add a SeparateCacheWatchRPC feature flag to disable this behavior
Kubernetes-commit: 31d404b182d2985ce0d3c43f75d80c29a708beda
2024-02-27 11:25:42 +01:00
Sunil Shivanand 9ffd1e2039 Add apiserver_watch_cache_read_wait metric to cache refresh time
Signed-off-by: Sunil Shivanand <padlar@live.com>

Kubernetes-commit: e6ed0f37c65fb22c16f5afa408bc4de166070ebc
2024-02-08 12:39:50 +01:00
xigang 2eff540b7c cleanup: if triggerValue has a value, fast break
Signed-off-by: xigang <wangxigang2014@gmail.com>

Kubernetes-commit: d72448a41c24911a57b24cabdef3ca63ee048bd4
2024-03-04 10:29:31 +08:00
Wojciech Tyczyński 45b7f21179 Ensure that initial events are sorted for WatchList
Kubernetes-commit: 92bdc7b3873800e6130176e49acdf5e17110e5b9
2023-09-26 18:39:44 +02:00
Lukasz Szaszkiewicz e53bac21d8 storage/watch_cache: rework getAllEventsSinceLocked
Kubernetes-commit: ecaf2093f51fed5f544520b0ac00fb33a474b7f5
2024-02-26 12:22:05 +01:00
Lukasz Szaszkiewicz 19bd56380e storage/cacher: add TestGetWatchCacheResourceVersion, TestGetBookmarkAfterResourceVersionLockedFunc
Kubernetes-commit: d629d3fa355ec90f618663b0933d28d335489c54
2024-02-21 10:06:42 +01:00
Lukasz Szaszkiewicz 76172aaa1f storage/cacher: ensure the cache is at the Most Recent ResourceVersion when streaming was requested
Kubernetes-commit: f90bcf649e0f3dc233f49882468f949b0f00ac4f
2024-01-17 14:10:04 +01:00
Lukasz Szaszkiewicz ca8d0aaf91 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
weilaaa febd537a31 use build-in max and min func to instead of k8s.io/utils/integer funcs
Kubernetes-commit: eb8f3f194fed16484162aebdaab69168e02f8cb4
2023-12-15 15:09:11 +08:00
Wojciech Tyczyński 2b59a3f14c Don't sort under lock
Kubernetes-commit: 3e1dbccf4d3de59b31596f1664ff5ac9c02d1eea
2023-11-23 18:13:43 +01:00
ahutsunshine 16536b9b63 support pod namespace indexer
fix comments

optimize code

small optimization for the namespace scope check

Kubernetes-commit: d8bd150784bb4825ae891dd0ec84625bdba0f2b8
2023-11-29 15:51:24 +08:00
Lukasz Szaszkiewicz 7c5f6db7bf cacher: when forgeting a watcher, call stopWatcherLocked multiple times
It's possible that the watcher is already not in the structure (e.g. in case of
simultaneous Stop() and terminateAllWatchers(), but it is safe to call stopLocked()
on a watcher multiple times.

Kubernetes-commit: 7e35823690df01bd019a88d3346bd3ac820afaca
2023-10-30 14:24:39 +01:00
Antonio Ojea bdad50b280 Revert "cacher: when forgeting a watcher, call stopWatcherLocked multiple times"
This reverts commit bbca4a4b9add0f6c58e132500fd89dd39ee077f4.

Kubernetes-commit: c2cb3209138d852520da2743b9bd3a9795b2b7fb
2023-10-31 15:28:01 +00:00
Lukasz Szaszkiewicz 3f81d0cca7 cacher: when forgeting a watcher, call stopWatcherLocked multiple times
It's possible that the watcher is already not in the structure (e.g. in case of
simultaneous Stop() and terminateAllWatchers(), but it is safe to call stopLocked()
on a watcher multiple times.

Kubernetes-commit: bbca4a4b9add0f6c58e132500fd89dd39ee077f4
2023-10-30 14:24:39 +01:00
Wojciech Tyczyński 324d2bc3cf Cleanup paging parameters in etcd3 store
Kubernetes-commit: 3f4d3b67682335db510f85deb65b322127a3a0a1
2023-10-20 15:38:59 +02:00
tao.yang 47998d1ee6 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
Siyuan Zhang 77032c52b8 k8s.io/apiserver/storage: add 3 new unit tests for delete.
Signed-off-by: Siyuan Zhang <sizhang@google.com>

Kubernetes-commit: 26a4e06c92c248748dd3c50c74d75f8adc3c6823
2023-10-11 10:38:01 -07:00
Lukasz Szaszkiewicz c8dcfeed34 storage/testing/watcher_tests: make TestCacherWatchSemantics storage agnostic
Kubernetes-commit: 91bb75883c613d45563f3b7c01a69dde8194bfdc
2023-09-15 12:28:36 +02:00
Lukasz Szaszkiewicz 957c305d94 storage/etcd: add TestWatchDispatchBookmarkEvents unit test
Kubernetes-commit: 875b00137fdfbc74756a0fc5b1c9b2adbeb78e55
2023-09-01 13:45:44 +02:00
Lukasz Szaszkiewicz d8d65bebc5 storage/util: introduce AnnotateInitialEventsEndBookmark function
// AnnotateInitialEventsEndBookmark adds a special annotation to the given object
// which indicates that the initial events have been sent.
//
// Note that this function assumes that the obj's annotation
// field is a reference type (i.e. a map).

Kubernetes-commit: 47d9a47a08856613e2e6ae6aa8a1bdeb1e281f97
2023-08-24 12:19:10 +02:00
Lukasz Szaszkiewicz f75c503352 storage/factory: extend the Create method by newList and resourcePrefix params
Kubernetes-commit: ccabc01093a1344ebb27c32c946e9da3b8e91fd2
2023-07-28 09:53:01 +02:00
Lukasz Szaszkiewicz 52849e2b21 storage/cacher: duplicate logging when a watch is closed due to unresponsiveness.
Kubernetes-commit: 1327a57aaf8f5ffaea3d33204dbe64dccef4e0ef
2023-08-23 12:51:50 +02:00
Wojciech Tyczyński 3030f660a8 Graduate APIListChunking to GA
Kubernetes-commit: 6acfa3cb4ac876e46ead5ba4772ba18e480435ce
2023-07-21 11:35:21 +02:00
Lukasz Szaszkiewicz 6f2daefacf storage/util: move GetCurrentResourceVersionFromStorage
Kubernetes-commit: 9a253d896a096b4e1ffccf4b1f84e5cac1e1aad0
2023-07-26 15:53:13 +02:00
Marek Siarkowicz 9002dac854 Implement ConsistentListFromCache feature gate
Request bookmark every 100ms when there is at least one request blocked on revision not present in watch cache.

Kubernetes-commit: 39bb8f4bb1d013937aceac6c387563ffe13545c5
2023-06-06 15:49:46 +02:00
Marek Siarkowicz 23cd6bbea9 Fix TestConditionalProgressRequester and TestWaitUntilFreshAndListTimeout flakes
Kubernetes-commit: c1decb6763d2abf76d96aee8641ad56a23e0ba52
2023-07-12 13:36:51 +02:00
Marek Siarkowicz cd751eb82e Implement conditionalProgressRequester that allows requesting watch progress notification if watch cache is not fresh
Kubernetes-commit: 98461be8ffa7383152c442414a16adb217e98080
2023-07-10 18:10:49 +02:00
Marek Siarkowicz df9896fd00 Test consistent List
Kubernetes-commit: b36fdd68b72cd5c64ea5be3917846067644da983
2023-07-03 17:22:22 +02:00
Wojciech Tyczyński b560936651 Generalize watch storage tests
Kubernetes-commit: 8266c4d934d42a5175a84bff10fda4bf36f13817
2023-06-27 18:12:30 +02:00
Marek Siarkowicz eda3579943 Test all cases for LIST request cache bypass
Kubernetes-commit: e4cf103c9b98391e5e135c3991cd8f380bfe22fe
2023-06-21 14:12:04 +02:00
Marek Siarkowicz 72bea89ab7 Refactor shouldDelegateList/shouldListFromStorage to better explain decisions
Kubernetes-commit: 406899360b55b3a0e28970f369288a2bb8a804fe
2023-06-21 14:02:46 +02:00
Madhav Jivrajani d79ec7e54a storage: Move cacher tests to reside with the cacher code
Doing this allows us to implement some more nuanced cacher manipulations
to be used in testing. For ex: implementing a test-only compaction method
for the watch cache.

Signed-off-by: Madhav Jivrajani <madhav.jiv@gmail.com>

Kubernetes-commit: 6d66fbc6b670f1120a9041873bb8d1a0655bbefc
2023-06-06 14:11:03 +05:30
Madhav Jivrajani 1fd6d59169 cacher: Move common testing utils to a single file
This commit prepares for when cacher tests are moved here
from the `tests` package. Tests in that package redeclare
some of the testing utils that exist here, so dedup-ing them.

This commit also adapts to any changes in test util signatures.
There are still some utils that can be reused but currently are
highly specific to some tests. (ex: watch_cache_test.go)

Signed-off-by: Madhav Jivrajani <madhav.jiv@gmail.com>

Kubernetes-commit: 70978e4af619819787a4eb544ffd732aa7954d76
2023-06-06 14:08:25 +05:30
Eric Lin edd537cbe3 Do not copy bytes for cached serializations
Since cachingObject has the encoded data cached and they are not
supposed to change. It's memory efficient to just copy the slice
references.

Signed-off-by: Eric Lin <exlin@google.com>

Kubernetes-commit: 3085b57869a2a7bf5290ab97facaf17fedfa88a0
2023-05-31 19:12:32 +00:00
Wojciech Tyczyński d9c1a1d082 Refactor some watchcache tests
Kubernetes-commit: 1eca720dcc727b5deeeeb1164689d42c6cc316eb
2023-04-27 11:59:33 +02:00
Wojciech Tyczyński 53b8c6919c Refactor cacher.ListerWatcher code structure
Kubernetes-commit: 3f247e59edfd4083242ad7271d076a38291760ff
2023-04-25 19:03:20 +02:00
Lukasz Szaszkiewicz 0df626818a cacher: do not popExpiredWatchers when the cacher hasn't dispatched any event
If the cacher hasn't seen any event (when lastProcessedResourceVersion is zero) and
the bookmarkTimer has ticked then we shouldn't popExpiredWatchers. This is
because the watchers wont' be re-added and will miss future bookmark events when
the cacher finally receives an event via the c.incoming chan.

Kubernetes-commit: 6db4cbfde7babfb34f5cd1059c769ec2d870f12a
2023-04-19 15:29:13 +02:00
Lukasz Szaszkiewicz 55dd2b5223 cacher avoid double locking (#117410)
* cacher: remove locking from watcherBookmarkTimeBuckets

it turns out that the watcherBookmarkTimeBuckets
is called from only three places/methods: startDispatching, finishDispatching and Watch.
All these methods acquire c.Lock() before touching watcherBookmarkTimeBuckets.

Thus we could remove explicit locking in
watcherBookmarkTimeBuckets since the access is already synced.

* cacher: rename watcherBookmarkTimeBuckets methods to indicate that proper synchronisation must be used

Kubernetes-commit: eab66a687b282266f0520b79166f7f55828ffd28
2023-04-19 15:13:11 +02:00