-
Notifications
You must be signed in to change notification settings - Fork 6
feat: add multi-namespace support #124
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
+244
−27
Merged
Changes from all commits
Commits
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,7 +36,7 @@ type podEventLoggerOptions struct { | |
logDebounce time.Duration | ||
|
||
// The following fields are optional! | ||
namespace string | ||
namespaces []string | ||
fieldSelector string | ||
labelSelector string | ||
} | ||
|
@@ -78,7 +78,18 @@ func newPodEventLogger(ctx context.Context, opts podEventLoggerOptions) (*podEve | |
}, | ||
} | ||
|
||
return reporter, reporter.init() | ||
// If no namespaces are provided, we listen for events in all namespaces. | ||
if len(opts.namespaces) == 0 { | ||
reporter.initNamespace("") | ||
} else { | ||
for _, namespace := range opts.namespaces { | ||
if err := reporter.initNamespace(namespace); err != nil { | ||
return nil, err | ||
} | ||
} | ||
} | ||
|
||
return reporter, nil | ||
} | ||
|
||
type podEventLogger struct { | ||
|
@@ -95,22 +106,23 @@ type podEventLogger struct { | |
lq *logQueuer | ||
} | ||
|
||
// init starts the informer factory and registers event handlers. | ||
func (p *podEventLogger) init() error { | ||
// initNamespace starts the informer factory and registers event handlers for a given namespace. | ||
// If provided namespace is empty, it will start the informer factory and register event handlers for all namespaces. | ||
func (p *podEventLogger) initNamespace(namespace string) error { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should include a sentence in the method comment explaining the |
||
// We only track events that happen after the reporter starts. | ||
// This is to prevent us from sending duplicate events. | ||
startTime := time.Now() | ||
|
||
go p.lq.work(p.ctx) | ||
|
||
podFactory := informers.NewSharedInformerFactoryWithOptions(p.client, 0, informers.WithNamespace(p.namespace), informers.WithTweakListOptions(func(lo *v1.ListOptions) { | ||
podFactory := informers.NewSharedInformerFactoryWithOptions(p.client, 0, informers.WithNamespace(namespace), informers.WithTweakListOptions(func(lo *v1.ListOptions) { | ||
lo.FieldSelector = p.fieldSelector | ||
lo.LabelSelector = p.labelSelector | ||
})) | ||
eventFactory := podFactory | ||
if p.fieldSelector != "" || p.labelSelector != "" { | ||
// Events cannot filter on labels and fields! | ||
eventFactory = informers.NewSharedInformerFactoryWithOptions(p.client, 0, informers.WithNamespace(p.namespace)) | ||
eventFactory = informers.NewSharedInformerFactoryWithOptions(p.client, 0, informers.WithNamespace(namespace)) | ||
} | ||
|
||
// We listen for Pods and Events in the informer factory. | ||
|
@@ -277,7 +289,7 @@ func (p *podEventLogger) init() error { | |
|
||
p.logger.Info(p.ctx, "listening for pod events", | ||
slog.F("coder_url", p.coderURL.String()), | ||
slog.F("namespace", p.namespace), | ||
slog.F("namespace", namespace), | ||
slog.F("field_selector", p.fieldSelector), | ||
slog.F("label_selector", p.labelSelector), | ||
) | ||
|
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
Oops, something went wrong.
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.
This is breaking so make sure you inform customers in the release notes.