mirror of https://github.com/k3s-io/k3s
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 objpull/8/head
commit
9e72003b9d
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue