Use typedefs for Begin* functions

David asked for this for readability, even if not all other hooks do it.
This commit is contained in:
Tim Hockin 2020-12-15 21:49:16 -08:00
parent 25da6a0660
commit 37b34f5b53
2 changed files with 13 additions and 7 deletions

View File

@ -56,9 +56,15 @@ type FinishFunc func(ctx context.Context, success bool)
// AfterDeleteFunc is the type used for the Store.AfterDelete hook.
type AfterDeleteFunc func(obj runtime.Object, options *metav1.DeleteOptions)
// BeginCreateFunc is the type used for the Store.BeginCreate hook.
type BeginCreateFunc func(ctx context.Context, obj runtime.Object, options *metav1.CreateOptions) (FinishFunc, error)
// AfterCreateFunc is the type used for the Store.AfterCreate hook.
type AfterCreateFunc func(obj runtime.Object, options *metav1.CreateOptions)
// BeginUpdateFunc is the type used for the Store.BeginUpdate hook.
type BeginUpdateFunc func(ctx context.Context, obj, old runtime.Object, options *metav1.UpdateOptions) (FinishFunc, error)
// AfterUpdateFunc is the type used for the Store.AfterUpdate hook.
type AfterUpdateFunc func(obj runtime.Object, options *metav1.UpdateOptions)
@ -162,7 +168,7 @@ type Store struct {
// but before AfterCreate and Decorator, indicating via the argument
// whether the operation succeeded. If this returns an error, the function
// is not called. Almost nobody should use this hook.
BeginCreate func(ctx context.Context, obj runtime.Object, options *metav1.CreateOptions) (FinishFunc, error)
BeginCreate BeginCreateFunc
// AfterCreate implements a further operation to run after a resource is
// created and before it is decorated, optional.
AfterCreate AfterCreateFunc
@ -174,7 +180,7 @@ type Store struct {
// but before AfterUpdate and Decorator, indicating via the argument
// whether the operation succeeded. If this returns an error, the function
// is not called. Almost nobody should use this hook.
BeginUpdate func(ctx context.Context, obj, old runtime.Object, options *metav1.UpdateOptions) (FinishFunc, error)
BeginUpdate BeginUpdateFunc
// AfterUpdate implements a further operation to run after a resource is
// updated and before it is decorated, optional.
AfterUpdate AfterUpdateFunc

View File

@ -499,7 +499,7 @@ func TestStoreCreateHooks(t *testing.T) {
testCases := []struct {
name string
decorator func(runtime.Object)
beginCreate func(context.Context, runtime.Object, *metav1.CreateOptions) (FinishFunc, error)
beginCreate BeginCreateFunc
afterCreate AfterCreateFunc
// the TTLFunc is an easy hook to force a failure
ttl func(obj runtime.Object, existing uint64, update bool) (uint64, error)
@ -798,9 +798,9 @@ func TestStoreUpdateHooks(t *testing.T) {
name string
decorator func(runtime.Object)
// create-on-update is tested elsewhere, but this proves non-use here
beginCreate func(context.Context, runtime.Object, *metav1.CreateOptions) (FinishFunc, error)
beginCreate BeginCreateFunc
afterCreate AfterCreateFunc
beginUpdate func(context.Context, runtime.Object, runtime.Object, *metav1.UpdateOptions) (FinishFunc, error)
beginUpdate BeginUpdateFunc
afterUpdate AfterUpdateFunc
expectError bool
expectAnnotation string // to test object mutations
@ -927,9 +927,9 @@ func TestStoreCreateOnUpdateHooks(t *testing.T) {
testCases := []struct {
name string
decorator func(runtime.Object)
beginCreate func(context.Context, runtime.Object, *metav1.CreateOptions) (FinishFunc, error)
beginCreate BeginCreateFunc
afterCreate AfterCreateFunc
beginUpdate func(context.Context, runtime.Object, runtime.Object, *metav1.UpdateOptions) (FinishFunc, error)
beginUpdate BeginUpdateFunc
afterUpdate AfterUpdateFunc
// the TTLFunc is an easy hook to force a failure
ttl func(obj runtime.Object, existing uint64, update bool) (uint64, error)