Commit Graph

48 Commits

Author SHA1 Message Date
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
Patrick Ohly
b4e1cfcfab client-go record: avoid panic when watch creation failed
The previous attempt to fix this in
6aa779f4ed (diff-efa2cd1347df22ace5a516ea794152d00ef2a079db135c81787ed920ecb73658)
didn't address the root cause (or perhaps created it, not sure): the goroutine
must not be started if watch creation failed.

Instead, the error gets logged (as before) and an empty watch gets returned to
the caller (new). This is necessary because the function doesn't have an error
return value and changing that now would be disruptive. The empty watch is
valid and usable, so callers won't crash when they calls Stop.

This showed up recently in failed unit tests, probably because test
cancellation makes this error more likely:

   "Unable start event watcher (will not retry!)" err="broadcaster already
   stopped" logger="TestGarbageCollectorConstruction leaked goroutine"

The logger value and a preceding warning show that this occurs after test
completion.

Kubernetes-commit: 080432c46a7a49c3abf86d7fc5f2a5d7abc92239
2024-05-29 14:10:49 +02:00
Patrick Ohly
ebbf7d7dc3 client-go/tools/record: fix and test Broadcaster shutdown + logging
Constructing a Broadcaster already starts a watch which runs in the
background. Shutdown must be called to avoid leaking the goroutine.  Providing
a context was supposed to remove the need to call Shutdown, but that did not
actually work because the logic for "must check for cancellation" was
accidentally inverted.

While at it, structured log output also gets tested together with checking for
goroutine leaks.

Kubernetes-commit: ff779f1cb56cf896405e52f7923188b99b88bb00
2024-04-30 12:16:55 +02: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
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
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
HirazawaUi
0a0ddf8b6b generate ReportingInstance and ReportingController in Event
Kubernetes-commit: df0a25382053bb6c0f04fc4d807be6e059b552c1
2023-03-27 22:23:45 +08: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
bells17
21f4308ca2 Fix typo: type -> eventtype
Kubernetes-commit: 53083ea6aa9817f130b15efaf8ccc2d0c59c4be3
2019-10-21 17:15:44 +09:00
Andrew Stoycos
f19a514ff5 Fix Panic Condition
Currenlty an event recorder can send an event to a
broadcaster that is already stopped, resulting
in a panic.  This ensures the broadcaster holds
a lock while it is shutting down and then forces
any senders to drop queued events following
broadcaster shutdown.

It also updates the Action, ActionOrDrop,  Watch,
and WatchWithPrefix functions to return an error
in the case where data is sent on the closed bradcaster
channel rather than panicing.

Lastly it updates unit tests to ensure the fix works correctly

fixes: https://github.com/kubernetes/kubernetes/issues/108518

Signed-off-by: Andrew Stoycos <astoycos@redhat.com>

Kubernetes-commit: 6aa779f4ed3d3acdad2f2bf17fb27e11e23aabe4
2022-02-11 14:50:19 -05:00
Di Yi
5b56e4a504 resolve casing issue
Kubernetes-commit: 9996c154cba000346db940c90e234265d67dd8a9
2022-01-28 15:50:43 +08:00
Di Yi
93a63158d4 add fieldPath back to event logs
Kubernetes-commit: 94245af8f4a144e0aceb5a4be0d3ae4993e19be7
2022-01-27 14:28:26 +08:00
Madhav Jivrajani
721036c908 migrate k8s.io/apimachinery/util/clock -> k8s.io/utils/clock
Signed-off-by: Madhav Jivrajani <madhav.jiv@gmail.com>

Kubernetes-commit: fed2ec99c652550ed4a8c00b7cfc6c93abbc4ade
2021-09-21 15:53:43 +05:30
Madhav Jivrajani
b9fa896d5d Refactor client-go/util/flowcontrol/throttle.go RateLimiter
- Introduce PassiveRateLimiter which implements all methods of previous RateLimiter except Accept() and Wait()
- Change RateLimiter interface to extend PassiveRateLimiter by additionally implementing Accept() and Wait()
- Make client-go/tools/record use PassiveRateLimiter

Refactor EventSourceObjectSpamFilter, EventAggregator, EventCorrelator

- EventSourceObjectSpamFilter, EventAggregator, EventCorrelator use clock.PassiveClock now.
	- This won't be a breaking change because even if a clock.Clock is passed, it still implements the clock.PassiveClock interface.
- Extend clock.PassiveClock through Clock.
- Replace pacakge local implementation of realClock with clock.RealClock
- In flowcontrol/throttle.go split tokenBucketRateLimiters to use Clock and clock.PassiveClock.
- Migrate client-go/tools/record tests from using IntervalClock to using SimpleIntervalClock (honest implementation of clock.PassiveClock)

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

Kubernetes-commit: ac5c55f0bd853fcf883d9b8e1f5ef728a2fb5309
2021-08-25 21:56:26 +05:30
Aleksandra Gacek
23071d64f0 Allow customizing spam filtering in event client library
Kubernetes-commit: 00080d400fe27f11795b654ad1e124311831a0fc
2021-07-26 16:05:18 +02:00
Solly Ross
726d27fe7a Don't record events in goroutines
This changes the event recorder to use the equivalent of a select
statement instead of a goroutine to record events.

Previously, we used a goroutine to make event recording non-blocking.
Unfortunately, this writes to a channel, and during shutdown we then
race to write to a closed channel, panicing (caught by the error
handler, but still) and making the race detector unhappy.

Instead, we now use the select statement to make event emitting
non-blocking, and if we'd block, we just drop the event.  We already
drop events if a particular sink is overloaded, so this just moves the
incoming event queue to match that behavior (and makes the incoming
event queue much longer).

This means that, if the user uses `Eventf` and friends correctly (i.e.
ensure they've returned by the time we call `Shutdown`), it's
now safe to call Shutdown.  This matches the conventional go guidance on
channels: the writer should call close.

Kubernetes-commit: e90e67bd002e70a525d3ee9045b213a5d826074d
2020-10-16 15:05:00 -07:00
Bryan Boreham
5d2c89de53 Remove unused argument from generateEvent
Kubernetes-commit: beceee68156dff8b10123a37bb4645941b7df0c2
2020-11-17 16:51:10 +00:00
Derek Carr
475bc66604 Improve ability to debug Events e2e failure
Kubernetes-commit: 4502fa3cfcd6025ba434f8626102e56d09d95b7e
2020-09-03 15:01:33 -04:00
Kobayashi Daisuke
b5d4191149 Replace StartLogging(klog.Infof) with StartStructuredLogging(0)
Kubernetes-commit: 4ae11dac2e2cc8594c528a679db5861c0926b514
2020-06-09 12:01:45 +09:00
Kobayashi Daisuke
55768fa31f Add an function for Structured Logging function into EventBroatcaster
Kubernetes-commit: dcaa8d7126cb711b9b93ef10fa84364dac8a22d3
2020-06-09 10:10:41 +09:00
Kobayashi Daisuke
10e6fa29f1 Migrate log to klog.InfoS for staging/src/k8s.io/client-go
Kubernetes-commit: ed1b83c6de5ccc62494e7f0e580cd743ad9a5934
2020-06-03 11:13:54 +09: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
mattjmcnaughton
3ada5c0eb8 Remove recorder.PastEventf method
The `recorder.PastEventf` method wasn't actually working as advertised.
It was supposed to accept a timestamp, which would be used when
generating the event. However, as the
[source code](https://github.com/kubernetes/kubernetes/blob/master/staging/src/k8s.io/client-go/tools/record/event.go#L316)
shows, this `timestamp` was never actually used.

In other words, `PastEventf` is identical to `Eventf`.

We have two options: one would be to fix `PastEventf` so that it works
as advertised. The other would be to delete `PastEventf` and only
support `Eventf`.

Ultimately, I could only find one use of `PastEventf` in the code base,
so I propose we just delete `PastEventf` and convert all uses to
`Eventf`.

Kubernetes-commit: 92940fa80d67593c7a2333267da4424c8b45ac88
2019-12-30 11:55:47 -05:00
Luke Shumaker
f5d68cde58 client-go/tools: Docs: Clarify what's "old" core/v1 and what's "new" events/v1beta1
Kubernetes-commit: 2c4bb0fa4db88462a61995d9179fad801b00d69d
2019-11-12 08:30:24 -05:00
Yassine TIJANI
6cdcb13531 add a fallback for kube-scheduler when events.k8s.io is disabled
Signed-off-by: Yassine TIJANI <ytijani@vmware.com>

Kubernetes-commit: f970b3413779ef817d2a374847bc0a4cb733a9a0
2019-10-09 20:14:29 +02:00
Ted Yu
9be50f2e07 Use consistent short name for receivers
Kubernetes-commit: 21b11c2b6434f949299f85a12c535bfd169c2cf3
2019-10-08 09:08:52 -07:00
Ted Yu
c4ea3eed4f Expose Shutdown func for EventBroadcaster
Kubernetes-commit: 57d43e4946f352f075b219b0a2f35942b06cfeb9
2019-10-07 08:58:38 -07:00
Mikhail Mazurskiy
c90a87409a Cleanup math/rand package usage
Kubernetes-commit: 4ce1fb7d40beb9010e56d60792c4da25e8d86ed0
2018-11-17 16:45:36 +11:00
vivekbagade
060f7d3455 Added config to EventCorrelator in client-go
Added CorrelatorOptions that contains options to change the
defaults in EventSourceObjectSpamFilter and EventAggregator
in EventCorrelator. Added a eventCorrelator property to the
eventBroadcasterImpl to help with this.

Kubernetes-commit: 9d8e6fb1b9cf2d3fac8139a97334287e33ff911f
2019-03-07 10:39:49 +01:00
Yassine TIJANI
60920bb9e4 refactor util functions for event recording
Kubernetes-commit: 7296288928d347dfb1dcb990d779cdfce96ead1b
2019-01-18 15:28:37 +01: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
David Ashpole
55b7c99dca add metadata to kubelet eviction event annotations
Kubernetes-commit: fd1f19fc423880b2b292d6f9e6fca1e941e87994
2018-05-23 16:12:54 -07:00
Mikhail Mazurskiy
37d44da37d Use range in loops; misc fixes
Kubernetes-commit: c23a8a85cce80a1015797e9c76aae709d9910791
2018-03-29 22:55:25 +11:00
Dr. Stefan Schimanski
c5fd4b1202 Move pkg/api/v1/ref -> client-go/tools/reference
Kubernetes-commit: 5925a0a1df1cb8cfbf9d1b4c9aa62d772090ad75
2017-07-28 13:45:48 +00:00
Chao Xu
d82cfb70dd run hack/update-staging-client-go, somehow we copied listers/<authn,authz,imagepolicy>
Kubernetes-commit: ffe74d1fe749b5887711f70af24e1375856f2520
2017-06-28 00:06:44 +00:00
Chao Xu
1e9caa8e14 run root-rewrite-import-client-go-api-types
Kubernetes-commit: f2d3220a11111f86b2f481e70e3c1ca4f5896f44
2017-06-28 00:06:44 +00:00
Clayton Coleman
09165439d7 Refactor move of client-go/util/clock to apimachinery
Kubernetes-commit: 3e095d12b4f152a45b593927804e2e7b8816239a
2017-05-21 17:20:29 +00:00
Chao Xu
354468e551 move pkg/api/v1/ref.go and pkg/api/v1/resource.go to subpackages. move some functions in resource.go to pkg/api/v1/node and pkg/api/v1/pod
Kubernetes-commit: 4f9591b1de11bff617c920f89144004669b0f461
2017-04-18 20:28:21 +00:00
Kubernetes Publisher
7ac1236194 published by bot
(https://github.com/kubernetes/test-infra/tree/master/mungegithub)

copied from https://github.com/kubernetes/kubernetes.git, branch master,
last commit is ab794c612853e6c6dfda63594cb5d74914e7e151
2017-02-03 22:09:57 +00:00
Kubernetes Publisher
fcdf37233b published by bot
(https://github.com/kubernetes/contrib/tree/master/mungegithub)

copied from https://github.com/kubernetes/kubernetes.git, branch master,
last commit is baaaf26609565b4299008018486ec75fb30903eb
2017-01-25 15:19:43 +00:00
Kubernetes Publisher
687fd42903 published by bot
(https://github.com/kubernetes/contrib/tree/master/mungegithub)

copied from https://github.com/kubernetes/kubernetes.git, branch master,
last commit is 68f123dfa036bef57495f014a78144a9a1b517ca
2017-01-24 15:19:42 +00:00
Kubernetes Publisher
0eb5431cb7 published by bot
(https://github.com/kubernetes/contrib/tree/master/mungegithub)

copied from https://github.com/kubernetes/kubernetes.git, branch master,
last commit is 8d5227bb2e05e01031ace81fa6611a13f598278e
2017-01-21 15:19:42 +00:00
Kubernetes Publisher
8fa0506b26 published by bot
(https://github.com/kubernetes/contrib/tree/master/mungegithub)

copied from https://github.com/kubernetes/kubernetes.git, branch master,
last commit is d9467519245c3858ac58c5fa91ec9e5b16c1f507
2017-01-18 15:19:42 +00:00
Kubernetes Publisher
204f12b1f3 published by bot
(https://github.com/kubernetes/contrib/tree/master/mungegithub)

copied from https://github.com/kubernetes/kubernetes.git, branch master,
last commit is 616038db1b0d1e852b4a3d10c8c512a052f91fba
2017-01-14 15:19:47 +00:00
Kubernetes Publisher
124670e99d published by bot
(https://github.com/kubernetes/contrib/tree/master/mungegithub)

copied from https://github.com/kubernetes/kubernetes.git, branch master,
last commit is 81d788dd6e0748e5d53a62c16d933c5f7a0718af
2016-12-04 11:39:55 +00:00
Kubernetes Publisher
75399f68c8 published by bot
(https://github.com/kubernetes/contrib/tree/master/mungegithub)

copied from https://github.com/kubernetes/kubernetes.git, branch master,
last commit is e56cfc5322138aa23e6418ee30a6ab54c7c6fe8c
2016-10-21 04:44:19 +00:00
Chao Xu
a6d206121d remove the top-level folders for versions
remove scripts
2016-10-19 14:34:19 -07:00