Commit 9745d6c1 authored by Dr. Stefan Schimanski's avatar Dr. Stefan Schimanski

apiextensions: only create patch reference object for smp path

parent 41a53131
......@@ -82,12 +82,6 @@ func PatchResource(r rest.Patcher, scope RequestScope, admit admission.Interface
ctx := req.Context()
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)
if err != nil {
scope.err(err, w, req)
......@@ -134,8 +128,6 @@ func PatchResource(r rest.Patcher, scope RequestScope, admit admission.Interface
timeout: timeout,
schemaReferenceObj: schemaReferenceObj,
restPatcher: r,
name: name,
patchType: patchType,
......@@ -191,9 +183,6 @@ type patcher struct {
timeout time.Duration
// Schema
schemaReferenceObj runtime.Object
// Operation information
restPatcher rest.Patcher
name string
......@@ -263,6 +252,9 @@ func (p *jsonPatcher) applyJSPatch(versionedJS []byte) (patchedJS []byte, retErr
type smpPatcher struct {
*patcher
// Schema
schemaReferenceObj runtime.Object
}
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:
p.mechanism = &jsonPatcher{patcher: p}
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:
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,
schemaReferenceObj: schemaReferenceObj,
restPatcher: testPatcher,
name: name,
patchType: patchType,
......
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