mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-27 05:27:21 +00:00
Merge pull request #78743 from smarterclayton/patch_object
Calling PatchAction on typed objects should work correctly
This commit is contained in:
commit
f09c828496
@ -18,9 +18,11 @@ package testing
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"reflect"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
jsonpatch "github.com/evanphx/json-patch"
|
jsonpatch "github.com/evanphx/json-patch"
|
||||||
|
|
||||||
"k8s.io/apimachinery/pkg/api/errors"
|
"k8s.io/apimachinery/pkg/api/errors"
|
||||||
"k8s.io/apimachinery/pkg/api/meta"
|
"k8s.io/apimachinery/pkg/api/meta"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
@ -139,6 +141,11 @@ func ObjectReaction(tracker ObjectTracker) ReactionFunc {
|
|||||||
return true, nil, err
|
return true, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// reset the object in preparation to unmarshal, since unmarshal does not guarantee that fields
|
||||||
|
// in obj that are removed by patch are cleared
|
||||||
|
value := reflect.ValueOf(obj)
|
||||||
|
value.Elem().Set(reflect.New(value.Type().Elem()).Elem())
|
||||||
|
|
||||||
switch action.GetPatchType() {
|
switch action.GetPatchType() {
|
||||||
case types.JSONPatchType:
|
case types.JSONPatchType:
|
||||||
patch, err := jsonpatch.DecodePatch(action.GetPatch())
|
patch, err := jsonpatch.DecodePatch(action.GetPatch())
|
||||||
@ -149,6 +156,7 @@ func ObjectReaction(tracker ObjectTracker) ReactionFunc {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return true, nil, err
|
return true, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = json.Unmarshal(modified, obj); err != nil {
|
if err = json.Unmarshal(modified, obj); err != nil {
|
||||||
return true, nil, err
|
return true, nil, err
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user