Rename dispatcher Run to Start to match naming conventions

This commit is contained in:
Joe Betz 2024-10-25 18:44:10 -04:00
parent 0cb90973b0
commit 0dfbc85cd9
6 changed files with 10 additions and 9 deletions

View File

@ -49,8 +49,8 @@ type Source[H Hook] interface {
// Dispatcher dispatches evaluates an admission request against the currently // Dispatcher dispatches evaluates an admission request against the currently
// active hooks returned by the source. // active hooks returned by the source.
type Dispatcher[H Hook] interface { type Dispatcher[H Hook] interface {
// Run the dispatcher. This method should be called only once at startup. // Start the dispatcher. This method should be called only once at startup.
Run(ctx context.Context) error Start(ctx context.Context) error
// Dispatch a request to the policies. Dispatcher may choose not to // Dispatch a request to the policies. Dispatcher may choose not to
// call a hook, either because the rules of the hook does not match, or // call a hook, either because the rules of the hook does not match, or

View File

@ -186,7 +186,7 @@ func (c *Plugin[H]) ValidateInitialization() error {
} }
}() }()
err := c.dispatcher.Run(pluginContext) err := c.dispatcher.Start(pluginContext)
if err != nil && !errors.Is(err, context.Canceled) { if err != nil && !errors.Is(err, context.Canceled) {
utilruntime.HandleError(fmt.Errorf("policy dispatcher context unexpectedly closed: %w", err)) utilruntime.HandleError(fmt.Errorf("policy dispatcher context unexpectedly closed: %w", err))
} }

View File

@ -95,12 +95,12 @@ func NewPolicyDispatcher[P runtime.Object, B runtime.Object, E Evaluator](
} }
} }
// Dispatch implements generic.Dispatcher. It loops through all active hooks // Start implements generic.Dispatcher Start. It loops through all active hooks
// (policy x binding pairs) and selects those which are active for the current // (policy x binding pairs) and selects those which are active for the current
// request. It then resolves all params and creates an Invocation for each // request. It then resolves all params and creates an Invocation for each
// matching policy-binding-param tuple. The delegate is then called with the // matching policy-binding-param tuple. The delegate is then called with the
// list of tuples. // list of tuples.
func (d *policyDispatcher[P, B, E]) Run(ctx context.Context) error { func (d *policyDispatcher[P, B, E]) Start(ctx context.Context) error {
return nil return nil
} }

View File

@ -21,6 +21,7 @@ import (
"testing" "testing"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"k8s.io/api/admissionregistration/v1" "k8s.io/api/admissionregistration/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime"
@ -38,7 +39,7 @@ type fakeDispatcher struct{}
func (fd *fakeDispatcher) Dispatch(context.Context, admission.Attributes, admission.ObjectInterfaces, []generic.PolicyHook[*FakePolicy, *FakeBinding, generic.Evaluator]) error { func (fd *fakeDispatcher) Dispatch(context.Context, admission.Attributes, admission.ObjectInterfaces, []generic.PolicyHook[*FakePolicy, *FakeBinding, generic.Evaluator]) error {
return nil return nil
} }
func (fd *fakeDispatcher) Run(context.Context) error { func (fd *fakeDispatcher) Start(context.Context) error {
return nil return nil
} }

View File

@ -63,9 +63,9 @@ type dispatcher struct {
generic.Dispatcher[PolicyHook] generic.Dispatcher[PolicyHook]
} }
func (d *dispatcher) Run(ctx context.Context) error { func (d *dispatcher) Start(ctx context.Context) error {
go d.typeConverterManager.Run(ctx) go d.typeConverterManager.Run(ctx)
return d.Dispatcher.Run(ctx) return d.Dispatcher.Start(ctx)
} }
func (d *dispatcher) dispatchInvocations( func (d *dispatcher) dispatchInvocations(

View File

@ -64,7 +64,7 @@ type policyDecisionWithMetadata struct {
Binding *admissionregistrationv1.ValidatingAdmissionPolicyBinding Binding *admissionregistrationv1.ValidatingAdmissionPolicyBinding
} }
func (c *dispatcher) Run(ctx context.Context) error { func (c *dispatcher) Start(ctx context.Context) error {
return nil return nil
} }