- Notifications
You must be signed in to change notification settings - Fork7
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,9 @@ | ||
| # url -- The URL of your Coder deployment. Must prefix with http or https | ||
| url:"" | ||
| # namespace --List of namespacestosearch for Pods within. | ||
| # If unspecified or empty it will watch all namespaces. | ||
| namespaces:[] | ||
Member 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. This is breaking so make sure you inform customers in the release notes. | ||
| # volumes -- A list of extra volumes to add to the coder-logstream pod. | ||
| volumes: | ||
| 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! | ||
| namespaces[]string | ||
| fieldSelector string | ||
| labelSelector string | ||
| } | ||
| @@ -78,7 +78,18 @@ func newPodEventLogger(ctx context.Context, opts podEventLoggerOptions) (*podEve | ||
| }, | ||
| } | ||
| // 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 | ||
| } | ||
| // 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 { | ||
Member 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(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(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", namespace), | ||
| slog.F("field_selector", p.fieldSelector), | ||
| slog.F("label_selector", p.labelSelector), | ||
| ) | ||
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.