-
Notifications
You must be signed in to change notification settings - Fork 630
Replacing port-forwarding with k8s events in recordevents #4171
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
knative-prow-robot
merged 23 commits into
knative:master
from
slinkydeveloper:observer_and_record_events
Oct 6, 2020
Merged
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
7f2175e
WIP Replacing port-forwarding with k8s events in recordevents
slinkydeveloper 6b62c94
WIP Events are sent properly from recordevents to k8s events
slinkydeveloper a06f467
Sending the beast in battle
slinkydeveloper 46cd1bb
Update
slinkydeveloper 73d18db
Moved resources of recordevents in proper module
slinkydeveloper e6eb27d
gofmt
slinkydeveloper bcbd28b
Another one
slinkydeveloper 4a589d3
Other stuff
slinkydeveloper 65ac13b
Copyrights
slinkydeveloper 559bd6b
Other copyrights
slinkydeveloper b5107eb
boilerplate check
slinkydeveloper 9699197
boilerplate check
slinkydeveloper 6aed65b
Other lints checks
slinkydeveloper 9f80ef2
Warn
slinkydeveloper 7451b75
Now the linter
slinkydeveloper ab503eb
Missing decorator in recordevents
slinkydeveloper 4fc111a
Simplified the sink definition, just sending events to myself
slinkydeveloper 9a2cb27
Happy linter, happy me
slinkydeveloper 1196010
Correct HTTP server shutdown
slinkydeveloper 624ccaa
Try fix correlator config
slinkydeveloper 1a54bb2
Just close the server
slinkydeveloper 82e138b
Still messing up with the Event correlator options
slinkydeveloper 58a8542
lint check
slinkydeveloper File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| /* | ||
| Copyright 2020 The Knative Authors | ||
|
|
||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| */ | ||
|
|
||
| package lib | ||
|
|
||
| import ( | ||
| "context" | ||
| "sync" | ||
|
|
||
| corev1 "k8s.io/api/core/v1" | ||
| "k8s.io/client-go/informers" | ||
| "k8s.io/client-go/kubernetes" | ||
| "k8s.io/client-go/tools/cache" | ||
| ) | ||
|
|
||
| // EventHandler is the callback type for the EventListener | ||
| type EventHandler func(event *corev1.Event) | ||
|
|
||
| // EventListener is a type that broadcasts new k8s events | ||
| type EventListener struct { | ||
| cancel context.CancelFunc | ||
|
|
||
| lock sync.Mutex | ||
| handlers []EventHandler | ||
| } | ||
|
|
||
| // NewEventListener creates a new event listener | ||
| func NewEventListener(client kubernetes.Interface, namespace string, logf func(string, ...interface{})) *EventListener { | ||
| ctx, cancelCtx := context.WithCancel(context.Background()) | ||
| informerFactory := informers.NewSharedInformerFactoryWithOptions( | ||
| client, | ||
| 0, | ||
| informers.WithNamespace(namespace), | ||
| ) | ||
| eventsInformer := informerFactory.Core().V1().Events().Informer() | ||
|
|
||
| el := EventListener{ | ||
| cancel: cancelCtx, | ||
| } | ||
|
|
||
| eventsInformer.AddEventHandler(cache.ResourceEventHandlerFuncs{ | ||
| AddFunc: func(obj interface{}) { | ||
| el.handle(obj.(*corev1.Event)) | ||
| }, | ||
| }) | ||
|
|
||
| go func() { | ||
| eventsInformer.Run(ctx.Done()) | ||
| logf("EventListener stopped") | ||
| }() | ||
|
|
||
| return &el | ||
| } | ||
|
|
||
| func (el *EventListener) handle(event *corev1.Event) { | ||
| el.lock.Lock() | ||
| defer el.lock.Unlock() | ||
| for _, handler := range el.handlers { | ||
| handler(event) | ||
| } | ||
| } | ||
|
|
||
| func (el *EventListener) AddHandler(handler EventHandler) { | ||
| el.lock.Lock() | ||
| defer el.lock.Unlock() | ||
| el.handlers = append(el.handlers, handler) | ||
| } | ||
|
|
||
| func (el *EventListener) Stop() { | ||
| el.cancel() | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In reconciler-test the event informer is injected into the context (something to keep in mind when moving this code over).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool so we can avoid creating it manually!
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We'll still need this
EventListener, right? Note that this is shared between differentEventInfoStoreThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup I think so.