mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-11 13:02:14 +00:00
Merge pull request #126305 from richabanker/optimize-tests
Init common apiserver for all testcases in CEL tests
This commit is contained in:
commit
beb696c2c9
@ -41,6 +41,13 @@ import (
|
|||||||
"k8s.io/klog/v2"
|
"k8s.io/klog/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Interval for refreshing policies.
|
||||||
|
// 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
|
||||||
policyInformer generic.Informer[P]
|
policyInformer generic.Informer[P]
|
||||||
@ -122,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")
|
||||||
@ -178,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, 1*time.Second, ctx.Done())
|
wait.Until(s.refreshPolicies, policyRefreshInterval, ctx.Done())
|
||||||
}()
|
}()
|
||||||
|
|
||||||
<-ctx.Done()
|
<-ctx.Done()
|
||||||
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user