Merge pull request #63880 from sttts/sttts-move-scheme-ref-obj-to-smp

Automatic merge from submit-queue. 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>.

apimachinery: move schema reference object into smp patcher

The schema reference object is only used in the strategic merge patch code path. This PR moves the creation there.

This PR is a preparation to make the patcher compatible with the UnstructuredObjectConverter without internal types. It will allow us to return an error on missing kinds at https://github.com/kubernetes/kubernetes/pull/63830#discussion_r188171025.
This commit is contained in:
Kubernetes Submit Queue 2018-05-15 18:50:48 -07:00 committed by GitHub
commit 0e42990eee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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,