mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 11:50:44 +00:00
apiextensions: only create patch reference object for smp path
This commit is contained in:
parent
41a531317a
commit
9745d6c119
@ -82,12 +82,6 @@ func PatchResource(r rest.Patcher, scope RequestScope, admit admission.Interface
|
|||||||
ctx := req.Context()
|
ctx := req.Context()
|
||||||
ctx = request.WithNamespace(ctx, namespace)
|
ctx = request.WithNamespace(ctx, namespace)
|
||||||
|
|
||||||
schemaReferenceObj, err := scope.UnsafeConvertor.ConvertToVersion(r.New(), scope.Kind.GroupVersion())
|
|
||||||
if err != nil {
|
|
||||||
scope.err(err, w, req)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
patchJS, err := readBody(req)
|
patchJS, err := readBody(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
scope.err(err, w, req)
|
scope.err(err, w, req)
|
||||||
@ -134,8 +128,6 @@ func PatchResource(r rest.Patcher, scope RequestScope, admit admission.Interface
|
|||||||
|
|
||||||
timeout: timeout,
|
timeout: timeout,
|
||||||
|
|
||||||
schemaReferenceObj: schemaReferenceObj,
|
|
||||||
|
|
||||||
restPatcher: r,
|
restPatcher: r,
|
||||||
name: name,
|
name: name,
|
||||||
patchType: patchType,
|
patchType: patchType,
|
||||||
@ -191,9 +183,6 @@ type patcher struct {
|
|||||||
|
|
||||||
timeout time.Duration
|
timeout time.Duration
|
||||||
|
|
||||||
// Schema
|
|
||||||
schemaReferenceObj runtime.Object
|
|
||||||
|
|
||||||
// Operation information
|
// Operation information
|
||||||
restPatcher rest.Patcher
|
restPatcher rest.Patcher
|
||||||
name string
|
name string
|
||||||
@ -263,6 +252,9 @@ func (p *jsonPatcher) applyJSPatch(versionedJS []byte) (patchedJS []byte, retErr
|
|||||||
|
|
||||||
type smpPatcher struct {
|
type smpPatcher struct {
|
||||||
*patcher
|
*patcher
|
||||||
|
|
||||||
|
// Schema
|
||||||
|
schemaReferenceObj runtime.Object
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *smpPatcher) applyPatchToCurrentObject(currentObject runtime.Object) (runtime.Object, error) {
|
func (p *smpPatcher) applyPatchToCurrentObject(currentObject runtime.Object) (runtime.Object, error) {
|
||||||
@ -352,7 +344,11 @@ func (p *patcher) patchResource(ctx context.Context) (runtime.Object, error) {
|
|||||||
case types.JSONPatchType, types.MergePatchType:
|
case types.JSONPatchType, types.MergePatchType:
|
||||||
p.mechanism = &jsonPatcher{patcher: p}
|
p.mechanism = &jsonPatcher{patcher: p}
|
||||||
case types.StrategicMergePatchType:
|
case types.StrategicMergePatchType:
|
||||||
p.mechanism = &smpPatcher{patcher: p}
|
schemaReferenceObj, err := p.unsafeConvertor.ConvertToVersion(p.restPatcher.New(), p.kind.GroupVersion())
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
p.mechanism = &smpPatcher{patcher: p, schemaReferenceObj: schemaReferenceObj}
|
||||||
default:
|
default:
|
||||||
return nil, fmt.Errorf("%v: unimplemented patch type", p.patchType)
|
return nil, fmt.Errorf("%v: unimplemented patch type", p.patchType)
|
||||||
}
|
}
|
||||||
|
@ -394,8 +394,6 @@ func (tc *patchTestCase) Run(t *testing.T) {
|
|||||||
|
|
||||||
timeout: 1 * time.Second,
|
timeout: 1 * time.Second,
|
||||||
|
|
||||||
schemaReferenceObj: schemaReferenceObj,
|
|
||||||
|
|
||||||
restPatcher: testPatcher,
|
restPatcher: testPatcher,
|
||||||
name: name,
|
name: name,
|
||||||
patchType: patchType,
|
patchType: patchType,
|
||||||
|
Loading…
Reference in New Issue
Block a user