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 4 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
26 changes: 22 additions & 4 deletions pkg/auth/asynccache.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ import (
"k8s.io/klog"
)

const (
initializationRetryInterval = 30 * time.Second
Copy link
Member

Choose a reason for hiding this comment

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

5s

Copy link
Member Author

Choose a reason for hiding this comment

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

What about 10s to match the historical behavior:

backoff = time.Second * 10

initializationTimeout = 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.

@deads2k is this ok?

Copy link
Member Author

Choose a reason for hiding this comment

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

@stlaz @deads2k The startupProbe for console pod lasts 5m, which also matches the duration console would retry auth config historically (4.14 and before).

initializeImmediately = true
)

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

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

item, err := cachingFunc(ctx)
err := wait.PollUntilContextTimeout(
ctx,
initializationRetryInterval,
initializationTimeout,
initializeImmediately,
func(ctx context.Context) (bool, error) {
item, err := cachingFunc(ctx)
if err != nil {
klog.V(4).Infof("failed to setup an async cache - retrying in %s", initializationRetryInterval)
TheRealJon marked this conversation as resolved.
Show resolved Hide resolved
return false, err
TheRealJon marked this conversation as resolved.
Show resolved Hide resolved
}
c.cachedItem = item
return true, nil
},
)

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