mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-19 00:31:00 +00:00
Make REST After* funcs not return error
This commit is contained in:
parent
67c9761623
commit
64491be328
@ -160,7 +160,7 @@ type Store struct {
|
||||
BeginCreate func(ctx context.Context, obj runtime.Object, options *metav1.CreateOptions) (FinishFunc, error)
|
||||
// AfterCreate implements a further operation to run after a resource is
|
||||
// created and before it is decorated, optional.
|
||||
AfterCreate ObjectFunc
|
||||
AfterCreate func(runtime.Object)
|
||||
|
||||
// UpdateStrategy implements resource-specific behavior during updates.
|
||||
UpdateStrategy rest.RESTUpdateStrategy
|
||||
@ -172,13 +172,13 @@ type Store struct {
|
||||
BeginUpdate func(ctx context.Context, obj, old runtime.Object, options *metav1.UpdateOptions) (FinishFunc, error)
|
||||
// AfterUpdate implements a further operation to run after a resource is
|
||||
// updated and before it is decorated, optional.
|
||||
AfterUpdate ObjectFunc
|
||||
AfterUpdate func(runtime.Object)
|
||||
|
||||
// DeleteStrategy implements resource-specific behavior during deletion.
|
||||
DeleteStrategy rest.RESTDeleteStrategy
|
||||
// AfterDelete implements a further operation to run after a resource is
|
||||
// deleted and before it is decorated, optional.
|
||||
AfterDelete ObjectFunc
|
||||
AfterDelete func(runtime.Object)
|
||||
// ReturnDeletedObject determines whether the Store returns the object
|
||||
// that was deleted. Otherwise, return a generic success status response.
|
||||
ReturnDeletedObject bool
|
||||
@ -422,9 +422,7 @@ func (e *Store) Create(ctx context.Context, obj runtime.Object, createValidation
|
||||
fn(ctx, true)
|
||||
|
||||
if e.AfterCreate != nil {
|
||||
if err := e.AfterCreate(out); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
e.AfterCreate(out)
|
||||
}
|
||||
if e.Decorator != nil {
|
||||
if err := e.Decorator(out); err != nil {
|
||||
@ -666,15 +664,11 @@ func (e *Store) Update(ctx context.Context, name string, objInfo rest.UpdatedObj
|
||||
|
||||
if creating {
|
||||
if e.AfterCreate != nil {
|
||||
if err := e.AfterCreate(out); err != nil {
|
||||
return nil, false, err
|
||||
}
|
||||
e.AfterCreate(out)
|
||||
}
|
||||
} else {
|
||||
if e.AfterUpdate != nil {
|
||||
if err := e.AfterUpdate(out); err != nil {
|
||||
return nil, false, err
|
||||
}
|
||||
e.AfterUpdate(out)
|
||||
}
|
||||
}
|
||||
if e.Decorator != nil {
|
||||
@ -1165,9 +1159,7 @@ func (e *Store) DeleteCollection(ctx context.Context, deleteValidation rest.Vali
|
||||
// returns the decorated deleted object if appropriate.
|
||||
func (e *Store) finalizeDelete(ctx context.Context, obj runtime.Object, runHooks bool) (runtime.Object, error) {
|
||||
if runHooks && e.AfterDelete != nil {
|
||||
if err := e.AfterDelete(obj); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
e.AfterDelete(obj)
|
||||
}
|
||||
if e.ReturnDeletedObject {
|
||||
if e.Decorator != nil {
|
||||
|
@ -440,7 +440,7 @@ func TestStoreCreateHooks(t *testing.T) {
|
||||
name string
|
||||
decorator ObjectFunc
|
||||
beginCreate func(context.Context, runtime.Object, *metav1.CreateOptions) (FinishFunc, error)
|
||||
afterCreate ObjectFunc
|
||||
afterCreate func(runtime.Object)
|
||||
// the TTLFunc is an easy hook to force a failure
|
||||
ttl func(obj runtime.Object, existing uint64, update bool) (uint64, error)
|
||||
expectError bool
|
||||
@ -457,9 +457,8 @@ func TestStoreCreateHooks(t *testing.T) {
|
||||
expectAnnotation: "DecoratorWasCalled",
|
||||
}, {
|
||||
name: "AfterCreate mutation",
|
||||
afterCreate: func(obj runtime.Object) error {
|
||||
afterCreate: func(obj runtime.Object) {
|
||||
setAnn(obj, "AfterCreateWasCalled")
|
||||
return nil
|
||||
},
|
||||
expectAnnotation: "AfterCreateWasCalled",
|
||||
}, {
|
||||
@ -475,9 +474,8 @@ func TestStoreCreateHooks(t *testing.T) {
|
||||
mile("Decorator")
|
||||
return nil
|
||||
},
|
||||
afterCreate: func(obj runtime.Object) error {
|
||||
afterCreate: func(obj runtime.Object) {
|
||||
mile("AfterCreate")
|
||||
return nil
|
||||
},
|
||||
beginCreate: func(_ context.Context, obj runtime.Object, _ *metav1.CreateOptions) (FinishFunc, error) {
|
||||
mile("BeginCreate")
|
||||
@ -492,9 +490,8 @@ func TestStoreCreateHooks(t *testing.T) {
|
||||
mile("Decorator")
|
||||
return nil
|
||||
},
|
||||
afterCreate: func(obj runtime.Object) error {
|
||||
afterCreate: func(obj runtime.Object) {
|
||||
mile("AfterCreate")
|
||||
return nil
|
||||
},
|
||||
beginCreate: func(_ context.Context, obj runtime.Object, _ *metav1.CreateOptions) (FinishFunc, error) {
|
||||
mile("BeginCreate")
|
||||
@ -515,9 +512,8 @@ func TestStoreCreateHooks(t *testing.T) {
|
||||
mile("Decorator")
|
||||
return fmt.Errorf("decorator")
|
||||
},
|
||||
afterCreate: func(obj runtime.Object) error {
|
||||
afterCreate: func(obj runtime.Object) {
|
||||
mile("AfterCreate")
|
||||
return nil
|
||||
},
|
||||
beginCreate: func(_ context.Context, obj runtime.Object, _ *metav1.CreateOptions) (FinishFunc, error) {
|
||||
mile("BeginCreate")
|
||||
@ -526,24 +522,6 @@ func TestStoreCreateHooks(t *testing.T) {
|
||||
}, nil
|
||||
},
|
||||
expectMilestones: []string{"BeginCreate", "FinishCreate(true)", "AfterCreate", "Decorator"},
|
||||
}, {
|
||||
name: "fail AfterCreate ordering",
|
||||
expectError: true,
|
||||
decorator: func(obj runtime.Object) error {
|
||||
mile("Decorator")
|
||||
return nil
|
||||
},
|
||||
afterCreate: func(obj runtime.Object) error {
|
||||
mile("AfterCreate")
|
||||
return fmt.Errorf("after")
|
||||
},
|
||||
beginCreate: func(_ context.Context, obj runtime.Object, _ *metav1.CreateOptions) (FinishFunc, error) {
|
||||
mile("BeginCreate")
|
||||
return func(_ context.Context, success bool) {
|
||||
mile(fmt.Sprintf("FinishCreate(%v)", success))
|
||||
}, nil
|
||||
},
|
||||
expectMilestones: []string{"BeginCreate", "FinishCreate(true)", "AfterCreate"},
|
||||
}, {
|
||||
name: "fail BeginCreate ordering",
|
||||
expectError: true,
|
||||
@ -551,9 +529,8 @@ func TestStoreCreateHooks(t *testing.T) {
|
||||
mile("Decorator")
|
||||
return nil
|
||||
},
|
||||
afterCreate: func(obj runtime.Object) error {
|
||||
afterCreate: func(obj runtime.Object) {
|
||||
mile("AfterCreate")
|
||||
return nil
|
||||
},
|
||||
beginCreate: func(_ context.Context, obj runtime.Object, _ *metav1.CreateOptions) (FinishFunc, error) {
|
||||
mile("BeginCreate")
|
||||
@ -783,9 +760,9 @@ func TestStoreUpdateHooks(t *testing.T) {
|
||||
decorator ObjectFunc
|
||||
// create-on-update is tested elsewhere, but this proves non-use here
|
||||
beginCreate func(context.Context, runtime.Object, *metav1.CreateOptions) (FinishFunc, error)
|
||||
afterCreate ObjectFunc
|
||||
afterCreate func(runtime.Object)
|
||||
beginUpdate func(context.Context, runtime.Object, runtime.Object, *metav1.UpdateOptions) (FinishFunc, error)
|
||||
afterUpdate ObjectFunc
|
||||
afterUpdate func(runtime.Object)
|
||||
expectError bool
|
||||
expectAnnotation string // to test object mutations
|
||||
expectMilestones []string // to test sequence
|
||||
@ -800,9 +777,8 @@ func TestStoreUpdateHooks(t *testing.T) {
|
||||
expectAnnotation: "DecoratorWasCalled",
|
||||
}, {
|
||||
name: "AfterUpdate mutation",
|
||||
afterUpdate: func(obj runtime.Object) error {
|
||||
afterUpdate: func(obj runtime.Object) {
|
||||
setAnn(obj, "AfterUpdateWasCalled")
|
||||
return nil
|
||||
},
|
||||
expectAnnotation: "AfterUpdateWasCalled",
|
||||
}, {
|
||||
@ -818,9 +794,8 @@ func TestStoreUpdateHooks(t *testing.T) {
|
||||
mile("Decorator")
|
||||
return nil
|
||||
},
|
||||
afterCreate: func(obj runtime.Object) error {
|
||||
afterCreate: func(obj runtime.Object) {
|
||||
mile("AfterCreate")
|
||||
return nil
|
||||
},
|
||||
beginCreate: func(_ context.Context, obj runtime.Object, _ *metav1.CreateOptions) (FinishFunc, error) {
|
||||
mile("BeginCreate")
|
||||
@ -828,9 +803,8 @@ func TestStoreUpdateHooks(t *testing.T) {
|
||||
mile(fmt.Sprintf("FinishCreate(%v)", success))
|
||||
}, nil
|
||||
},
|
||||
afterUpdate: func(obj runtime.Object) error {
|
||||
afterUpdate: func(obj runtime.Object) {
|
||||
mile("AfterUpdate")
|
||||
return nil
|
||||
},
|
||||
beginUpdate: func(_ context.Context, obj, _ runtime.Object, _ *metav1.UpdateOptions) (FinishFunc, error) {
|
||||
mile("BeginUpdate")
|
||||
@ -846,9 +820,8 @@ func TestStoreUpdateHooks(t *testing.T) {
|
||||
mile("Decorator")
|
||||
return fmt.Errorf("decorator")
|
||||
},
|
||||
afterUpdate: func(obj runtime.Object) error {
|
||||
afterUpdate: func(obj runtime.Object) {
|
||||
mile("AfterUpdate")
|
||||
return nil
|
||||
},
|
||||
beginUpdate: func(_ context.Context, obj, _ runtime.Object, _ *metav1.UpdateOptions) (FinishFunc, error) {
|
||||
mile("BeginUpdate")
|
||||
@ -857,24 +830,6 @@ func TestStoreUpdateHooks(t *testing.T) {
|
||||
}, nil
|
||||
},
|
||||
expectMilestones: []string{"BeginUpdate", "FinishUpdate(true)", "AfterUpdate", "Decorator"},
|
||||
}, {
|
||||
name: "fail AfterUpdate ordering",
|
||||
expectError: true,
|
||||
decorator: func(obj runtime.Object) error {
|
||||
mile("Decorator")
|
||||
return nil
|
||||
},
|
||||
afterUpdate: func(obj runtime.Object) error {
|
||||
mile("AfterUpdate")
|
||||
return fmt.Errorf("after")
|
||||
},
|
||||
beginUpdate: func(_ context.Context, obj, _ runtime.Object, _ *metav1.UpdateOptions) (FinishFunc, error) {
|
||||
mile("BeginUpdate")
|
||||
return func(_ context.Context, success bool) {
|
||||
mile(fmt.Sprintf("FinishUpdate(%v)", success))
|
||||
}, nil
|
||||
},
|
||||
expectMilestones: []string{"BeginUpdate", "FinishUpdate(true)", "AfterUpdate"},
|
||||
}, {
|
||||
name: "fail BeginUpdate ordering",
|
||||
expectError: true,
|
||||
@ -882,9 +837,8 @@ func TestStoreUpdateHooks(t *testing.T) {
|
||||
mile("Decorator")
|
||||
return nil
|
||||
},
|
||||
afterUpdate: func(obj runtime.Object) error {
|
||||
afterUpdate: func(obj runtime.Object) {
|
||||
mile("AfterUpdate")
|
||||
return nil
|
||||
},
|
||||
beginUpdate: func(_ context.Context, obj, _ runtime.Object, _ *metav1.UpdateOptions) (FinishFunc, error) {
|
||||
mile("BeginUpdate")
|
||||
@ -955,9 +909,9 @@ func TestStoreCreateOnUpdateHooks(t *testing.T) {
|
||||
name string
|
||||
decorator ObjectFunc
|
||||
beginCreate func(context.Context, runtime.Object, *metav1.CreateOptions) (FinishFunc, error)
|
||||
afterCreate ObjectFunc
|
||||
afterCreate func(runtime.Object)
|
||||
beginUpdate func(context.Context, runtime.Object, runtime.Object, *metav1.UpdateOptions) (FinishFunc, error)
|
||||
afterUpdate ObjectFunc
|
||||
afterUpdate func(runtime.Object)
|
||||
// the TTLFunc is an easy hook to force a failure
|
||||
ttl func(obj runtime.Object, existing uint64, update bool) (uint64, error)
|
||||
expectError bool
|
||||
@ -970,9 +924,8 @@ func TestStoreCreateOnUpdateHooks(t *testing.T) {
|
||||
mile("Decorator")
|
||||
return nil
|
||||
},
|
||||
afterCreate: func(obj runtime.Object) error {
|
||||
afterCreate: func(obj runtime.Object) {
|
||||
mile("AfterCreate")
|
||||
return nil
|
||||
},
|
||||
beginCreate: func(_ context.Context, obj runtime.Object, _ *metav1.CreateOptions) (FinishFunc, error) {
|
||||
mile("BeginCreate")
|
||||
@ -980,9 +933,8 @@ func TestStoreCreateOnUpdateHooks(t *testing.T) {
|
||||
mile(fmt.Sprintf("FinishCreate(%v)", success))
|
||||
}, nil
|
||||
},
|
||||
afterUpdate: func(obj runtime.Object) error {
|
||||
afterUpdate: func(obj runtime.Object) {
|
||||
mile("AfterUpdate")
|
||||
return nil
|
||||
},
|
||||
beginUpdate: func(_ context.Context, obj, _ runtime.Object, _ *metav1.UpdateOptions) (FinishFunc, error) {
|
||||
mile("BeginUpdate")
|
||||
@ -997,9 +949,8 @@ func TestStoreCreateOnUpdateHooks(t *testing.T) {
|
||||
mile("Decorator")
|
||||
return nil
|
||||
},
|
||||
afterCreate: func(obj runtime.Object) error {
|
||||
afterCreate: func(obj runtime.Object) {
|
||||
mile("AfterCreate")
|
||||
return nil
|
||||
},
|
||||
beginCreate: func(_ context.Context, obj runtime.Object, _ *metav1.CreateOptions) (FinishFunc, error) {
|
||||
mile("BeginCreate")
|
||||
@ -1007,9 +958,8 @@ func TestStoreCreateOnUpdateHooks(t *testing.T) {
|
||||
mile(fmt.Sprintf("FinishCreate(%v)", success))
|
||||
}, nil
|
||||
},
|
||||
afterUpdate: func(obj runtime.Object) error {
|
||||
afterUpdate: func(obj runtime.Object) {
|
||||
mile("AfterUpdate")
|
||||
return nil
|
||||
},
|
||||
beginUpdate: func(_ context.Context, obj, _ runtime.Object, _ *metav1.UpdateOptions) (FinishFunc, error) {
|
||||
mile("BeginUpdate")
|
||||
@ -1030,9 +980,8 @@ func TestStoreCreateOnUpdateHooks(t *testing.T) {
|
||||
mile("Decorator")
|
||||
return fmt.Errorf("decorator")
|
||||
},
|
||||
afterCreate: func(obj runtime.Object) error {
|
||||
afterCreate: func(obj runtime.Object) {
|
||||
mile("AfterCreate")
|
||||
return nil
|
||||
},
|
||||
beginCreate: func(_ context.Context, obj runtime.Object, _ *metav1.CreateOptions) (FinishFunc, error) {
|
||||
mile("BeginCreate")
|
||||
@ -1040,9 +989,8 @@ func TestStoreCreateOnUpdateHooks(t *testing.T) {
|
||||
mile(fmt.Sprintf("FinishCreate(%v)", success))
|
||||
}, nil
|
||||
},
|
||||
afterUpdate: func(obj runtime.Object) error {
|
||||
afterUpdate: func(obj runtime.Object) {
|
||||
mile("AfterUpdate")
|
||||
return nil
|
||||
},
|
||||
beginUpdate: func(_ context.Context, obj, _ runtime.Object, _ *metav1.UpdateOptions) (FinishFunc, error) {
|
||||
mile("BeginUpdate")
|
||||
@ -1051,34 +999,6 @@ func TestStoreCreateOnUpdateHooks(t *testing.T) {
|
||||
}, nil
|
||||
},
|
||||
expectMilestones: []string{"BeginCreate", "FinishCreate(true)", "AfterCreate", "Decorator"},
|
||||
}, {
|
||||
name: "fail AfterCreate ordering",
|
||||
expectError: true,
|
||||
decorator: func(obj runtime.Object) error {
|
||||
mile("Decorator")
|
||||
return nil
|
||||
},
|
||||
afterCreate: func(obj runtime.Object) error {
|
||||
mile("AfterCreate")
|
||||
return fmt.Errorf("after")
|
||||
},
|
||||
beginCreate: func(_ context.Context, obj runtime.Object, _ *metav1.CreateOptions) (FinishFunc, error) {
|
||||
mile("BeginCreate")
|
||||
return func(_ context.Context, success bool) {
|
||||
mile(fmt.Sprintf("FinishCreate(%v)", success))
|
||||
}, nil
|
||||
},
|
||||
afterUpdate: func(obj runtime.Object) error {
|
||||
mile("AfterUpdate")
|
||||
return nil
|
||||
},
|
||||
beginUpdate: func(_ context.Context, obj, _ runtime.Object, _ *metav1.UpdateOptions) (FinishFunc, error) {
|
||||
mile("BeginUpdate")
|
||||
return func(_ context.Context, success bool) {
|
||||
mile(fmt.Sprintf("FinishUpdate(%v)", success))
|
||||
}, nil
|
||||
},
|
||||
expectMilestones: []string{"BeginCreate", "FinishCreate(true)", "AfterCreate"},
|
||||
}, {
|
||||
name: "fail BeginCreate ordering",
|
||||
expectError: true,
|
||||
@ -1086,9 +1006,8 @@ func TestStoreCreateOnUpdateHooks(t *testing.T) {
|
||||
mile("Decorator")
|
||||
return nil
|
||||
},
|
||||
afterCreate: func(obj runtime.Object) error {
|
||||
afterCreate: func(obj runtime.Object) {
|
||||
mile("AfterCreate")
|
||||
return nil
|
||||
},
|
||||
beginCreate: func(_ context.Context, obj runtime.Object, _ *metav1.CreateOptions) (FinishFunc, error) {
|
||||
mile("BeginCreate")
|
||||
@ -1096,9 +1015,8 @@ func TestStoreCreateOnUpdateHooks(t *testing.T) {
|
||||
mile(fmt.Sprintf("FinishCreate(%v)", success))
|
||||
}, fmt.Errorf("begin")
|
||||
},
|
||||
afterUpdate: func(obj runtime.Object) error {
|
||||
afterUpdate: func(obj runtime.Object) {
|
||||
mile("AfterUpdate")
|
||||
return nil
|
||||
},
|
||||
beginUpdate: func(_ context.Context, obj, _ runtime.Object, _ *metav1.UpdateOptions) (FinishFunc, error) {
|
||||
mile("BeginUpdate")
|
||||
@ -1174,7 +1092,7 @@ func TestStoreUpdateHooksInnerRetry(t *testing.T) {
|
||||
name string
|
||||
decorator func(runtime.Object) error
|
||||
beginUpdate func(context.Context, runtime.Object, runtime.Object, *metav1.UpdateOptions) (FinishFunc, error)
|
||||
afterUpdate func(runtime.Object) error
|
||||
afterUpdate func(runtime.Object)
|
||||
// the TTLFunc is an easy hook to force an inner-loop retry
|
||||
ttl func(obj runtime.Object, existing uint64, update bool) (uint64, error)
|
||||
expectError bool
|
||||
@ -1185,9 +1103,8 @@ func TestStoreUpdateHooksInnerRetry(t *testing.T) {
|
||||
mile("Decorator")
|
||||
return nil
|
||||
},
|
||||
afterUpdate: func(obj runtime.Object) error {
|
||||
afterUpdate: func(obj runtime.Object) {
|
||||
mile("AfterUpdate")
|
||||
return nil
|
||||
},
|
||||
beginUpdate: func(_ context.Context, obj, _ runtime.Object, _ *metav1.UpdateOptions) (FinishFunc, error) {
|
||||
mile("BeginUpdate")
|
||||
@ -1203,9 +1120,8 @@ func TestStoreUpdateHooksInnerRetry(t *testing.T) {
|
||||
mile("Decorator")
|
||||
return nil
|
||||
},
|
||||
afterUpdate: func(obj runtime.Object) error {
|
||||
afterUpdate: func(obj runtime.Object) {
|
||||
mile("AfterUpdate")
|
||||
return nil
|
||||
},
|
||||
beginUpdate: func(_ context.Context, obj, _ runtime.Object, _ *metav1.UpdateOptions) (FinishFunc, error) {
|
||||
mile("BeginUpdate")
|
||||
|
Loading…
Reference in New Issue
Block a user