init a common apiserver for TestAuthorizationDecisionCaching testcases
Kubernetes-commit: 4acedb5132b2c3a7d61bd9e088c964af3fcfee3d
This commit is contained in:
parent
1d26753b4b
commit
f434fbf0c7
|
@ -41,9 +41,12 @@ import (
|
||||||
"k8s.io/klog/v2"
|
"k8s.io/klog/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
// Interval for refreshing policies.
|
||||||
PolicyRefreshInterval = 1 * time.Second
|
// TODO: Consider reducing this to a shorter duration or replacing this entirely
|
||||||
)
|
// with checks that detect when a policy change took effect.
|
||||||
|
const policyRefreshIntervalDefault = 1 * time.Second
|
||||||
|
|
||||||
|
var policyRefreshInterval = policyRefreshIntervalDefault
|
||||||
|
|
||||||
type policySource[P runtime.Object, B runtime.Object, E Evaluator] struct {
|
type policySource[P runtime.Object, B runtime.Object, E Evaluator] struct {
|
||||||
ctx context.Context
|
ctx context.Context
|
||||||
|
@ -126,6 +129,15 @@ func NewPolicySource[P runtime.Object, B runtime.Object, E Evaluator](
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetPolicyRefreshIntervalForTests allows the refresh interval to be overridden during tests.
|
||||||
|
// This should only be called from tests.
|
||||||
|
func SetPolicyRefreshIntervalForTests(interval time.Duration) func() {
|
||||||
|
policyRefreshInterval = interval
|
||||||
|
return func() {
|
||||||
|
policyRefreshInterval = policyRefreshIntervalDefault
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (s *policySource[P, B, E]) Run(ctx context.Context) error {
|
func (s *policySource[P, B, E]) Run(ctx context.Context) error {
|
||||||
if s.ctx != nil {
|
if s.ctx != nil {
|
||||||
return fmt.Errorf("policy source already running")
|
return fmt.Errorf("policy source already running")
|
||||||
|
@ -182,7 +194,7 @@ func (s *policySource[P, B, E]) Run(ctx context.Context) error {
|
||||||
// and needs to be recompiled
|
// and needs to be recompiled
|
||||||
go func() {
|
go func() {
|
||||||
// Loop every 1 second until context is cancelled, refreshing policies
|
// Loop every 1 second until context is cancelled, refreshing policies
|
||||||
wait.Until(s.refreshPolicies, PolicyRefreshInterval, ctx.Done())
|
wait.Until(s.refreshPolicies, policyRefreshInterval, ctx.Done())
|
||||||
}()
|
}()
|
||||||
|
|
||||||
<-ctx.Done()
|
<-ctx.Done()
|
||||||
|
|
Loading…
Reference in New Issue