mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-21 19:01:49 +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 = 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,
|
||||
|
Loading…
Reference in New Issue
Block a user