Skip to content

Commit beb696c

Browse files
authored
Merge pull request kubernetes#126305 from richabanker/optimize-tests
Init common apiserver for all testcases in CEL tests
2 parents f6c88ab + 4acedb5 commit beb696c

File tree

2 files changed

+613
-547
lines changed

2 files changed

+613
-547
lines changed

staging/src/k8s.io/apiserver/pkg/admission/plugin/policy/generic/policy_source.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,13 @@ import (
4141
"k8s.io/klog/v2"
4242
)
4343

44+
// Interval for refreshing policies.
45+
// TODO: Consider reducing this to a shorter duration or replacing this entirely
46+
// with checks that detect when a policy change took effect.
47+
const policyRefreshIntervalDefault = 1 * time.Second
48+
49+
var policyRefreshInterval = policyRefreshIntervalDefault
50+
4451
type policySource[P runtime.Object, B runtime.Object, E Evaluator] struct {
4552
ctx context.Context
4653
policyInformer generic.Informer[P]
@@ -122,6 +129,15 @@ func NewPolicySource[P runtime.Object, B runtime.Object, E Evaluator](
122129
return res
123130
}
124131

132+
// SetPolicyRefreshIntervalForTests allows the refresh interval to be overridden during tests.
133+
// This should only be called from tests.
134+
func SetPolicyRefreshIntervalForTests(interval time.Duration) func() {
135+
policyRefreshInterval = interval
136+
return func() {
137+
policyRefreshInterval = policyRefreshIntervalDefault
138+
}
139+
}
140+
125141
func (s *policySource[P, B, E]) Run(ctx context.Context) error {
126142
if s.ctx != nil {
127143
return fmt.Errorf("policy source already running")
@@ -178,7 +194,7 @@ func (s *policySource[P, B, E]) Run(ctx context.Context) error {
178194
// and needs to be recompiled
179195
go func() {
180196
// Loop every 1 second until context is cancelled, refreshing policies
181-
wait.Until(s.refreshPolicies, 1*time.Second, ctx.Done())
197+
wait.Until(s.refreshPolicies, policyRefreshInterval, ctx.Done())
182198
}()
183199

184200
<-ctx.Done()

0 commit comments

Comments
 (0)