792 Commits

Author SHA1 Message Date
Lucy Sweet
c633a8222b Include annotations all the time
Kubernetes-commit: 8373afef0e0886fcd05a4cbf8b0bedeaa82a4d05
2023-02-21 16:42:37 +01:00
Lucy Sweet
f7f367ebae Respond to review
Kubernetes-commit: 7a48c6e2171d23fea76b7a15ab4971989f125b96
2023-02-21 16:29:38 +01:00
Lucy Sweet
a43f324cb9 Allow inclusion of annotations in channel events when using FakeRecorder
Kubernetes-commit: 9839ce96f557413f522230fa3e374e26356ae3d9
2023-02-17 16:38:10 +01:00
Odin Ugedal
b2a4f028d6 client-go/cache: update Replace comment to be more clear
Since the behavior is now changed, and the old behavior leaked objects,
this adds a new comment about how Replace works.

Signed-off-by: Odin Ugedal <ougedal@palantir.com>
Signed-off-by: Odin Ugedal <odin@uged.al>

Kubernetes-commit: 27f4bcae5c52a3bb88141f940ec23d907a15cde5
2023-02-13 11:23:50 +00:00
Odin Ugedal
a01b5a2a96 client-go/cache: rewrite Replace to check queue first
This is useful to both reduce the code complexity, and to ensure clients
get the "newest" version of an object known when its deleted. This is
all best-effort, but for clients it makes more sense giving them the
newest object they observed rather than an old one.

This is especially useful when an object is recreated. eg.

Object A with key K is in the KnownObjects store;
- DELETE delta for A is queued with key K
- CREATE delta for B is queued with key K
- Replace without any object with key K in it.

In this situation its better to create a DELETE delta with
DeletedFinalStateUnknown with B (with this patch), than it is to give
the client an DeletedFinalStateUnknown with A (without this patch).

Signed-off-by: Odin Ugedal <ougedal@palantir.com>
Signed-off-by: Odin Ugedal <odin@uged.al>

Kubernetes-commit: 7bcc3e00fc28b2548886d04639a2e352ab37fb55
2023-02-13 11:12:37 +00:00
Odin Ugedal
b250bf51ae client-go/cache: merge ReplaceMakesDeletionsForObjectsInQueue tests
Signed-off-by: Odin Ugedal <ougedal@palantir.com>
Signed-off-by: Odin Ugedal <odin@uged.al>

Kubernetes-commit: cd3e98b65c1339a8adc157175630de099a057d3f
2023-02-10 14:30:10 +00:00
Odin Ugedal
8279635aa4 client-go/cache: fix missing delete event on replace without knownObjects
This fixes an issue where a relist could result in a DELETED delta
with an object wrapped in a DeletedFinalStateUnknown object; and then on
the next relist, it would wrap that object inside another
DeletedFinalStateUnknown, leaving the user with a "double" layer
of DeletedFinalStateUnknown's.

Signed-off-by: Odin Ugedal <ougedal@palantir.com>
Signed-off-by: Odin Ugedal <odin@uged.al>

Kubernetes-commit: 0bf0546d9f75d92c801e81c9f7adf040bba64102
2023-02-10 14:16:26 +00:00
Odin Ugedal
2ded6b6eb8 client-go/cache: fix missing delete event on replace
This fixes a race condition when a "short lived" object
is created and the create event is still present on the queue
when a relist replaces the state. Previously that would lead in the
object being leaked.

The way this could happen is roughly;

1. new Object is added O, agent gets CREATED event for it
2. watch is terminated, and the agent runs a new list, L
3. CREATE event for O is still on the queue to be processed.
4. informer replaces the old data in store with L, and O is not in L
  - Since O is not in the store, and not in the list L, no DELETED event
    is queued
5. CREATE event for O is still on the queue to be processed.
6. CREATE event for O is processed
7. O is <leaked>; its present in the cache but not in k8s.

With this patch, on step 4. above it would create a DELETED event
ensuring that the object will be removed.

Signed-off-by: Odin Ugedal <ougedal@palantir.com>
Signed-off-by: Odin Ugedal <odin@uged.al>

Kubernetes-commit: 25d77218acdac2f793071add9ea878b08c7d328b
2023-02-08 14:57:23 +00:00
Patrick Ohly
f6a5a1f139 client-go: don't wait too long after EventBroadcaster.Shutdown
When Shutdown was called, delivery of each pending event would still be retried
12 times with a delay of ~10s between each retry. In apiserver integration
tests that caused the goroutine to linger long after the corresponding
apiserver of the test was shut down.

Kubernetes-commit: 15b01af9c18a0840d71e2bb7dff4d8c29b158aad
2023-02-03 14:52:20 +01:00
Abu Kashem
d2388d199c client-go: add metric to count retries
Kubernetes-commit: b6c369f5c90bbef8058b3d44949f4e815dd6607f
2022-02-28 12:22:09 -05:00
Mikhail Mazurskiy
ac40ba3297 Always emit the stopped leading event
Kubernetes-commit: 771ab7488d53f0d6c85238992a8e5f4bcb73e24e
2022-10-12 20:53:05 +11:00
xuzhenglun
7685b51912 Fix bug in reflector not detecting "Too large resource version" error before 1.17.0
Kubernetes-commit: 11e5e92dc65c1caaeb248a60d90ccc8e29eb9ff0
2023-01-16 11:36:28 +08:00
Clayton Coleman
08e22c4b64 cache: Reflector should have the same injected clock as its informer
While refactoring the backoff manager to simplify and unify the code
in wait a race condition was encountered in
TestSharedInformerWatchDisruption. The new implementation failed
because the fake clock was not propagated to the backoff managers
when the reflector was used in a controller. After ensuring the
mangaers, reflector, controller, and informer shared the same
clock the test needed was updated to avoid the race condition by
advancing the fake clock and adding real sleeps to wait for
asynchronous propagation of the various goroutines in the controller.

Due to the deep structure of informers it is difficult to inject
hooks to avoid having to perform sleeps. At a minimum the FakeClock
interface should allow a caller to determine the number of waiting
timers (to avoid the first sleep).

Kubernetes-commit: 91b3a81fbd916713afe215f7d701950e13a02869
2023-01-14 14:17:33 -05:00
Daniel Smith
cb28a0e57e Fix N^2 startup for webhook configurations
Add a "lazy" type to track when an update is needed. It uses a nested
locking technique to avoid extra evaluation calls.

Kubernetes-commit: 5a1091d88d95bd1dd5c27f2c72cee4ecb4219dda
2023-01-09 23:29:25 +00:00
Damien Grisonnet
1113415196 event_broadcaster: update isomorphic event def
Update the definition of an isomorphic event in the events/v1 client to
match the aggregation logic that was already present in the core/v1
implementation.

The note field was omitted even though the message was used in the core
API aggregation because we didn't reach consensus.

Signed-off-by: Damien Grisonnet <dgrisonn@redhat.com>

Kubernetes-commit: 21f2f746abc1a5a1b3193274401f5728e19cc26f
2022-09-09 19:16:40 +02:00
Brian Pursley
b0a6a6f777 portforward: Add unit test to cover stopChan usage
Kubernetes-commit: 6f08ab013c6ce54de239aab46b4086c09464f977
2022-12-23 10:11:21 -05:00
Brian Pursley
d0842249d3 portforward: return error on lost connection to pod
Currently, when the remote connection is unexpected closed, forward() prints an error message saying "lost connection to pod" via runtime.HandleError, but then it returns nil for the error.

This prevents the caller from being able to handle this error differently.

This commit changes forward() to return the "lost connection to pod" error so that it can be handled by the caller.

Making this change enables kubectl port-forward to exit with code 1, instead of 0, which is the expected behavior for a command that has failed.

Kubernetes-commit: a9f04103854893056237a09250ad3335867b0391
2022-12-13 13:32:42 -05:00
Damien Grisonnet
4b578e1242 tools/events: fix data race when emitting series
There was a data race in the recordToSink function that caused changes
to the events cache to be overriden if events were emitted
simultaneously via Eventf calls.

The race lies in the fact that when recording an Event, there might be
multiple calls updating the cache simultaneously. The lock period is
optimized so that after updating the cache with the new Event, the lock
is unlocked until the Event is recorded on the apiserver side and then
the cache is locked again to be updated with the new value returned by
the apiserver.

The are a few problem with the approach:

1. If two identical Events are emitted successively the changes of the
   second Event will override the first one. In code the following
   happen:
   1. Eventf(ev1)
   2. Eventf(ev2)
   3. Lock cache
   4. Set cache[getKey(ev1)] = &ev1
   5. Unlock cache
   6. Lock cache
   7. Update cache[getKey(ev2)] = &ev1 + Series{Count: 1}
   8. Unlock cache
   9. Start attempting to record the first event &ev1 on the apiserver side.

   This can be mitigated by recording a copy of the Event stored in
   cache instead of reusing the pointer from the cache.

2. When the Event has been recorded on the apiserver the cache is
   updated again with the value of the Event returned by the server.
   This update will override any changes made to the cache entry when
   attempting to record the new Event since the cache was unlocked at
   that time. This might lead to some inconsistencies when dealing with
   EventSeries since the count may be overriden or the client might even
   try to record the first isomorphic Event multiple time.

   This could be mitigated with a lock that has a larger scope, but we
   shouldn't want to reflect Event returned by the apiserver in the
   cache in the first place since mutation could mess with the
   aggregation by either allowing users to manipulate values to update
   a different cache entry or even having two cache entries for the same
   Events.

Signed-off-by: Damien Grisonnet <dgrisonn@redhat.com>

Kubernetes-commit: 55ec09d377274b4a6107fe0b7a061ad408fe05a7
2022-12-01 15:39:34 +01:00
Damien Grisonnet
e3ded99476 tools/events: retry on AlreadyExist for Series
When attempting to record a new Event and a new Serie on the apiserver
at the same time, the patch of the Serie might happen before the Event
is actually created. In that case, we handle the error and try to create
the Event. But the Event might be created during that period of time and
it is treated as an error today. So in order to handle that scenario, we
need to retry when a Create call for a Serie results in an AlreadyExist
error.

Signed-off-by: Damien Grisonnet <dgrisonn@redhat.com>

Kubernetes-commit: 2f83117bcfe30ad3ada7f1ca66f4b885a1d5df25
2022-12-01 15:40:01 +01: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
Daniel Smith
5d70a118df Enable propagration of HasSynced
* Add tracker types and tests
* Modify ResourceEventHandler interface's OnAdd member
* Add additional ResourceEventHandlerDetailedFuncs struct
* Fix SharedInformer to let users track HasSynced for their handlers
* Fix in-tree controllers which weren't computing HasSynced correctly
* Deprecate the cache.Pop function

Kubernetes-commit: 8100efc7b3122ad119ee8fa4bbbedef3b90f2e0d
2022-11-18 00:12:50 +00:00
Andy Goldstein
fbb7f087d1 reflector: refactor setting typeDescription & expectedGVK
Signed-off-by: Andy Goldstein <andy.goldstein@redhat.com>

Kubernetes-commit: 784ec157e67c86bc3383b326bbfe8ee70737aa4d
2022-12-02 12:39:58 -05:00
Andy Goldstein
37897aff8d Reflector: support logging Unstructured type
Add an annotation that can be added to the exampleType passed to
NewReflector to indicate the expected type for the Reflector. This is
useful for types such as unstuctured.Unstructured, which, when used with
a dynamic informer, do not have their TypeMeta filled in.

Signed-off-by: Andy Goldstein <andy.goldstein@redhat.com>

Kubernetes-commit: 474fc8c5234000bce666a6b02f7ffbb295ef135f
2022-08-17 15:49:26 -04:00
Marly Puckett
769443557e Update redacting functionality to redact all sensitive info in config when printing with view (#109189)
* Add RedactSecrets function

* Move RedactSecrets method to existing RawBytesData case

* Update TestRedactSecrets to use new pattern of os.CreateTemp()

Kubernetes-commit: e721272d10dd6c4d85ff613182ba0eaddcec9272
2022-11-08 17:30:10 +00:00
jlsong01
34679611a8 rewrite signature of function StartEventWatcher
Kubernetes-commit: c8291e393b32f8ce4e8fd1d4f18e848247be13f8
2022-07-29 23:43:05 +08:00
Wojciech Tyczyński
5e7ba1f8d7 Minor cleanup of thread safe store
Kubernetes-commit: 72194de96f0bb5c1c1e3247a129cf9e3f11972ef
2022-11-02 13:02:29 +01:00
Wojciech Tyczyński
b69a16cf38 Refactor store index into its structure
Kubernetes-commit: 7c94ce3076a96acab4c7e88489cd596f1aad40e0
2022-05-05 17:30:24 +02:00
arkbriar
0563decd0a Propagate the panic with a channel
Signed-off-by: arkbriar <arkbriar@gmail.com>

Kubernetes-commit: b7e6c23e9f73e4cc0209e94fe95c5e2809998bf6
2022-11-02 11:36:22 +08:00
arkbriar
2362c7b162 use subtests and defer in TestSPDYExecutorStream
Signed-off-by: arkbriar <arkbriar@gmail.com>

Kubernetes-commit: 86e5d069ecece8591ad693b50bcea49000f6df26
2022-10-10 11:24:40 +08:00
arkbriar
5e0a53136c Support cancelable SPDY executor stream
Mark remotecommand.Executor as deprecated and related modifications.

Handle crash when streamer.stream panics

Add a test to verify if stream is closed after connection being closed

Remove blank line and update waiting time to 1s to avoid test flakes in CI.

Refine the tests of StreamExecutor according to comments.

Remove the comment of context controlling the negotiation progress and misc.

Signed-off-by: arkbriar <arkbriar@gmail.com>

Kubernetes-commit: 42808c8343671e6783ba4c901dcd619bed648c3d
2022-08-24 10:21:35 +08:00
zackzhangkai
0945beb5d7 fix typo
Signed-off-by: zackzhangkai <zhangkaiamm@gmail.com>

Kubernetes-commit: 5a1ca395b28efd6537f93f9615bc5c7ca401a9dd
2022-10-17 14:10:09 +08:00
astraw99
f549acf3ce Fix duplicate code block of ListAll function
Kubernetes-commit: d8db1e9ba3c110012def6faa5579ad3abb71a6a6
2022-03-24 14:47:20 +08:00
Nick Turner
5870c622c7 Remove log line from expiration cache
Kubernetes-commit: e7bfd5909f5540f884a8bb914a9230c9bf7c2803
2022-10-04 11:01:37 -07:00
Monis Khan
166580894e Use https links for k8s KEPs, issues, PRs, etc
Signed-off-by: Monis Khan <mok@microsoft.com>

Kubernetes-commit: b738be9b46a899571303c8c887e32bf4d5b71a0a
2022-09-23 16:13:22 -04:00
Lurong
59765b8784 fix typo error
Kubernetes-commit: 0b2ad4cc42e727ec93011411033cac1abfb637ea
2022-09-22 14:42:41 +08:00
Monis Khan
67030989c0 Check for context cancellation on each buffered chunk
TestListPager_EachListItem flakes without this change.

Signed-off-by: Monis Khan <mok@microsoft.com>

Kubernetes-commit: 7458ed01d6aa150b8a6046e0dbeba88d5d5ff1bb
2022-09-15 10:33:33 -04:00
LiHui
cc3cc93e6a kubectl: fix memory leaks in port forwarding client
Signed-off-by: LiHui <andrewli@kubesphere.io>

Kubernetes-commit: 1df24569a0bf62a528c49f73fdb236fd56eb05ee
2022-08-29 14:15:01 +08:00
Shyam Jeedigunta
49ac40b489 Autogen code
Kubernetes-commit: f9c46a0e3361e19de93c02562fedfff7de448dc2
2022-09-07 18:05:42 -07:00
Shyam Jeedigunta
b8a8d94944 Add DisableCompression option to KubeConfig
Kubernetes-commit: 641fd5b482c6117d459a22d99f76aae086c3524f
2022-09-07 18:04:17 -07:00
Alexander Zielenski
a300ae0dfe return when test is done
Kubernetes-commit: cc0b9ffbd5a4edfe7ce01293c2bf963d4335d8d6
2022-08-30 14:38:21 -07:00
Alexander Zielenski
93e5e0e8a0 hold listener lock while waiting for goroutines to finish
Kubernetes-commit: 7ce19b75a8dbca12837ed9f4c5c2828c38b82a03
2022-08-29 12:34:35 -07:00
Alexander Zielenski
e11a988e1c simplify control flow
Kubernetes-commit: ee24648300f8575f503156f45b44034054c2e49d
2022-08-29 11:52:35 -07:00
Alexander Zielenski
ac7f6579ff fix spelling
Kubernetes-commit: 7685b393c2ee8f8548d62f9dd8485df764a0c8c3
2022-08-22 17:34:02 -07:00
Alexander Zielenski
0f4a6cf319 reset listenersStarted
for correctness. technically shouldnt be an issue since restarting a stopped processor is not supported

Kubernetes-commit: 3a81341cfa6f7e2ca1b9bfc195c567dcdfaa4dea
2022-08-08 14:19:37 -07:00
Alexander Zielenski
449817f7b5 add multithreaded test to shared informer
Kubernetes-commit: 8af0a31a15079725e5910d538a6ace03df2e382a
2022-08-08 13:39:18 -07:00
Alexander Zielenski
de0b7671e3 remove duplicate test
became a duplicate while refactoring original PR

Kubernetes-commit: df9a7afa63164035f1e94c3278d470b347b697b9
2022-08-08 11:46:05 -07:00
Alexander Zielenski
0565962dd0 address review comments
asd

Kubernetes-commit: 5f372e1867305679d8f9d8a013c5500763e5c875
2022-08-08 11:44:37 -07:00
Alexander Zielenski
5a25eb0de8 switch listeners to use a map, adapt tests
Kubernetes-commit: 063ef090e7fb5823ca18a10a83e8847eedac9599
2022-06-16 10:54:03 -07:00
Uwe Krueger
90c6a46b32 active remove/add tests for event handlers
Kubernetes-commit: e9cd17170b1646672796e713dee6c4fb0e6693bb
2021-10-06 12:40:46 +02:00