Merge pull request #63349 from smarterclayton/decorator

Automatic merge from submit-queue (batch tested with PRs 63349, 63294). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

Decorator for Create should be called on out, not obj
pull/8/head
Kubernetes Submit Queue 2018-05-02 11:43:07 -07:00 committed by GitHub
commit 9e72003b9d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 1 deletions

View File

@ -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
}
}

View File

@ -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 {