Decorator for Create should be called on out, not obj

obj is not what we return
parent 7d57060d
......@@ -373,7 +373,7 @@ func (e *Store) Create(ctx context.Context, obj runtime.Object, createValidation
}
}
if e.Decorator != nil {
if err := e.Decorator(obj); err != nil {
if err := e.Decorator(out); err != nil {
return nil, err
}
}
......
......@@ -311,6 +311,11 @@ func TestStoreCreate(t *testing.T) {
// re-define delete strategy to have graceful delete capability
defaultDeleteStrategy := testRESTStrategy{scheme, names.SimpleNameGenerator, true, false, true}
registry.DeleteStrategy = testGracefulStrategy{defaultDeleteStrategy}
registry.Decorator = func(obj runtime.Object) error {
pod := obj.(*example.Pod)
pod.Status.Phase = example.PodPhase("Testing")
return nil
}
// create the object with denying admission
objA, err := registry.Create(testContext, podA, denyCreateValidation, false)
......@@ -324,6 +329,11 @@ func TestStoreCreate(t *testing.T) {
t.Errorf("Unexpected error: %v", err)
}
// verify the decorator was called
if objA.(*example.Pod).Status.Phase != example.PodPhase("Testing") {
t.Errorf("Decorator was not called: %#v", objA)
}
// get the object
checkobj, err := registry.Get(testContext, podA.Name, &metav1.GetOptions{})
if err != nil {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment