Skip to content
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

fix OOM issue on real clusters #144

Merged
merged 2 commits into from
Mar 7, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 20 additions & 9 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,13 +160,15 @@ func Start(ctx context.Context, conf *Config, c kubernetes.Interface) <-chan str

var eventsCh = make(chan mapipwriter.Event, 64)

cm, err := c.CoreV1().ConfigMaps(conf.Namespace).Get(ctx, conf.FromConfigMap, v1.GetOptions{})
if err == nil {
for _, event := range translateFromConfigmap(watch.Event{
Type: watch.Added,
Object: cm,
}) {
eventsCh <- event
if conf.FromConfigMap != "" {
cm, err := c.CoreV1().ConfigMaps(conf.Namespace).Get(ctx, conf.FromConfigMap, v1.GetOptions{})
if err == nil {
for _, event := range translateFromConfigmap(watch.Event{
Type: watch.Added,
Object: cm,
}) {
eventsCh <- event
}
}
}

Expand Down Expand Up @@ -205,17 +207,26 @@ func Start(ctx context.Context, conf *Config, c kubernetes.Interface) <-chan str
}

func monitorEvents(ctx context.Context, out chan<- mapipwriter.Event, getWatchFn func() watch.Interface, translateFn func(watch.Event) []mapipwriter.Event) {
for ctx.Err() == nil {
w := getWatchFn()
w := getWatchFn()
defer func() {
if w != nil {
w.Stop()
}
}()

for ctx.Err() == nil {
if w == nil {
log.FromContext(ctx).Errorf("cant supply watcher")
time.Sleep(time.Second / 2)
wazsone marked this conversation as resolved.
Show resolved Hide resolved
w = getWatchFn()
continue
}

select {
case e, ok := <-w.ResultChan():
if !ok {
w.Stop()
w = getWatchFn()
continue
}
events := translateFn(e)
Expand Down