apiextensions: only create patch reference object for smp path

This commit is contained in:
Dr. Stefan Schimanski 2018-05-15 19:35:05 +02:00
parent 41a531317a
commit 9745d6c119
2 changed files with 8 additions and 14 deletions

View File

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

View File

@ -394,8 +394,6 @@ func (tc *patchTestCase) Run(t *testing.T) {
timeout: 1 * time.Second,
schemaReferenceObj: schemaReferenceObj,
restPatcher: testPatcher,
name: name,
patchType: patchType,