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

OCPBUGS-29479: Add retries to async cache initialization #13610

Merged
merged 5 commits into from
Feb 28, 2024
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 16 additions & 4 deletions pkg/auth/asynccache.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ import (
"k8s.io/klog"
)

const (
initializationRetryDelay = 30 * time.Second
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you wan to be under the 150 liveness probe delay, which I think means you want this delay to 11 seconds.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See openshift/console-operator#869 which changes the probes for the console container.

)

type cachingFuncType[T any] func(ctx context.Context) (T, error)

type AsyncCache[T any] struct {
Expand All @@ -27,13 +31,21 @@ func NewAsyncCache[T any](ctx context.Context, reloadPeriod time.Duration, cachi
cachingFunc: cachingFunc,
}

item, err := cachingFunc(ctx)
var err error
ctx, cancel := context.WithTimeout(ctx, 5*time.Minute)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would expect something in terms of seconds, not minutes 👀
Remember that this blocks proper startup.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is intentionally long in order to give the API server time to become available. This context gets canceled on the first successful cachingFunc call, so we only wait the full 5 minutes when there is something wrong.

wait.UntilWithContext(ctx, func(ctx context.Context) {
TheRealJon marked this conversation as resolved.
Show resolved Hide resolved
item, err := cachingFunc(ctx)
if err != nil {
klog.V(4).Infof("failed to setup an async cache - retrying in %s", initializationRetryDelay)
return
}
c.cachedItem = item
cancel()
}, initializationRetryDelay)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the delay const is used in place of a check interval here


if err != nil {
return nil, fmt.Errorf("failed to setup an async cache - caching func returned error: %w", err)
}

c.cachedItem = item

return c, nil
}

Expand Down