mirror of https://github.com/k3s-io/k3s
remove useless codec param from strategicPatchObject
parent
0e097af8d8
commit
43baa697aa
|
@ -301,7 +301,7 @@ func (p *smpPatcher) applyPatchToCurrentObject(currentObject runtime.Object) (ru
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if err := strategicPatchObject(p.codec, p.defaulter, currentVersionedObject, p.patchJS, versionedObjToUpdate, p.schemaReferenceObj); err != nil {
|
if err := strategicPatchObject(p.defaulter, currentVersionedObject, p.patchJS, versionedObjToUpdate, p.schemaReferenceObj); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
// Convert the object back to unversioned (aka internal version).
|
// Convert the object back to unversioned (aka internal version).
|
||||||
|
@ -319,7 +319,6 @@ func (p *smpPatcher) applyPatchToCurrentObject(currentObject runtime.Object) (ru
|
||||||
// <originalObject> and <patchJS>.
|
// <originalObject> and <patchJS>.
|
||||||
// NOTE: Both <originalObject> and <objToUpdate> are supposed to be versioned.
|
// NOTE: Both <originalObject> and <objToUpdate> are supposed to be versioned.
|
||||||
func strategicPatchObject(
|
func strategicPatchObject(
|
||||||
codec runtime.Codec,
|
|
||||||
defaulter runtime.ObjectDefaulter,
|
defaulter runtime.ObjectDefaulter,
|
||||||
originalObject runtime.Object,
|
originalObject runtime.Object,
|
||||||
patchJS []byte,
|
patchJS []byte,
|
||||||
|
@ -336,7 +335,7 @@ func strategicPatchObject(
|
||||||
return errors.NewBadRequest(err.Error())
|
return errors.NewBadRequest(err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := applyPatchToObject(codec, defaulter, originalObjMap, patchMap, objToUpdate, schemaReferenceObj); err != nil {
|
if err := applyPatchToObject(defaulter, originalObjMap, patchMap, objToUpdate, schemaReferenceObj); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
@ -396,7 +395,6 @@ func (p *patcher) patchResource(ctx context.Context) (runtime.Object, error) {
|
||||||
// <originalMap> and stores the result in <objToUpdate>.
|
// <originalMap> and stores the result in <objToUpdate>.
|
||||||
// NOTE: <objToUpdate> must be a versioned object.
|
// NOTE: <objToUpdate> must be a versioned object.
|
||||||
func applyPatchToObject(
|
func applyPatchToObject(
|
||||||
codec runtime.Codec,
|
|
||||||
defaulter runtime.ObjectDefaulter,
|
defaulter runtime.ObjectDefaulter,
|
||||||
originalMap map[string]interface{},
|
originalMap map[string]interface{},
|
||||||
patchMap map[string]interface{},
|
patchMap map[string]interface{},
|
||||||
|
|
|
@ -79,7 +79,6 @@ func (obj *testPatchType) DeepCopyObject() runtime.Object {
|
||||||
func TestPatchAnonymousField(t *testing.T) {
|
func TestPatchAnonymousField(t *testing.T) {
|
||||||
testGV := schema.GroupVersion{Group: "", Version: "v"}
|
testGV := schema.GroupVersion{Group: "", Version: "v"}
|
||||||
scheme.AddKnownTypes(testGV, &testPatchType{})
|
scheme.AddKnownTypes(testGV, &testPatchType{})
|
||||||
codec := codecs.LegacyCodec(testGV)
|
|
||||||
defaulter := runtime.ObjectDefaulter(scheme)
|
defaulter := runtime.ObjectDefaulter(scheme)
|
||||||
|
|
||||||
original := &testPatchType{
|
original := &testPatchType{
|
||||||
|
@ -93,7 +92,7 @@ func TestPatchAnonymousField(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
actual := &testPatchType{}
|
actual := &testPatchType{}
|
||||||
err := strategicPatchObject(codec, defaulter, original, []byte(patch), actual, &testPatchType{})
|
err := strategicPatchObject(defaulter, original, []byte(patch), actual, &testPatchType{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unexpected error: %v", err)
|
t.Fatalf("unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -105,7 +104,6 @@ func TestPatchAnonymousField(t *testing.T) {
|
||||||
func TestPatchInvalid(t *testing.T) {
|
func TestPatchInvalid(t *testing.T) {
|
||||||
testGV := schema.GroupVersion{Group: "", Version: "v"}
|
testGV := schema.GroupVersion{Group: "", Version: "v"}
|
||||||
scheme.AddKnownTypes(testGV, &testPatchType{})
|
scheme.AddKnownTypes(testGV, &testPatchType{})
|
||||||
codec := codecs.LegacyCodec(testGV)
|
|
||||||
defaulter := runtime.ObjectDefaulter(scheme)
|
defaulter := runtime.ObjectDefaulter(scheme)
|
||||||
|
|
||||||
original := &testPatchType{
|
original := &testPatchType{
|
||||||
|
@ -116,7 +114,7 @@ func TestPatchInvalid(t *testing.T) {
|
||||||
expectedError := "invalid character 'b' looking for beginning of value"
|
expectedError := "invalid character 'b' looking for beginning of value"
|
||||||
|
|
||||||
actual := &testPatchType{}
|
actual := &testPatchType{}
|
||||||
err := strategicPatchObject(codec, defaulter, original, []byte(patch), actual, &testPatchType{})
|
err := strategicPatchObject(defaulter, original, []byte(patch), actual, &testPatchType{})
|
||||||
if !apierrors.IsBadRequest(err) {
|
if !apierrors.IsBadRequest(err) {
|
||||||
t.Errorf("expected HTTP status: BadRequest, got: %#v", apierrors.ReasonForError(err))
|
t.Errorf("expected HTTP status: BadRequest, got: %#v", apierrors.ReasonForError(err))
|
||||||
}
|
}
|
||||||
|
@ -128,7 +126,6 @@ func TestPatchInvalid(t *testing.T) {
|
||||||
func TestPatchCustomResource(t *testing.T) {
|
func TestPatchCustomResource(t *testing.T) {
|
||||||
testGV := schema.GroupVersion{Group: "mygroup.example.com", Version: "v1beta1"}
|
testGV := schema.GroupVersion{Group: "mygroup.example.com", Version: "v1beta1"}
|
||||||
scheme.AddKnownTypes(testGV, &unstructured.Unstructured{})
|
scheme.AddKnownTypes(testGV, &unstructured.Unstructured{})
|
||||||
codec := codecs.LegacyCodec(testGV)
|
|
||||||
defaulter := runtime.ObjectDefaulter(scheme)
|
defaulter := runtime.ObjectDefaulter(scheme)
|
||||||
|
|
||||||
original := &unstructured.Unstructured{
|
original := &unstructured.Unstructured{
|
||||||
|
@ -148,7 +145,7 @@ func TestPatchCustomResource(t *testing.T) {
|
||||||
expectedError := "strategic merge patch format is not supported"
|
expectedError := "strategic merge patch format is not supported"
|
||||||
|
|
||||||
actual := &unstructured.Unstructured{}
|
actual := &unstructured.Unstructured{}
|
||||||
err := strategicPatchObject(codec, defaulter, original, []byte(patch), actual, &unstructured.Unstructured{})
|
err := strategicPatchObject(defaulter, original, []byte(patch), actual, &unstructured.Unstructured{})
|
||||||
if !apierrors.IsBadRequest(err) {
|
if !apierrors.IsBadRequest(err) {
|
||||||
t.Errorf("expected HTTP status: BadRequest, got: %#v", apierrors.ReasonForError(err))
|
t.Errorf("expected HTTP status: BadRequest, got: %#v", apierrors.ReasonForError(err))
|
||||||
}
|
}
|
||||||
|
@ -453,7 +450,6 @@ func (tc *patchTestCase) Run(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNumberConversion(t *testing.T) {
|
func TestNumberConversion(t *testing.T) {
|
||||||
codec := codecs.LegacyCodec(examplev1.SchemeGroupVersion)
|
|
||||||
defaulter := runtime.ObjectDefaulter(scheme)
|
defaulter := runtime.ObjectDefaulter(scheme)
|
||||||
|
|
||||||
terminationGracePeriodSeconds := int64(42)
|
terminationGracePeriodSeconds := int64(42)
|
||||||
|
@ -471,7 +467,7 @@ func TestNumberConversion(t *testing.T) {
|
||||||
|
|
||||||
patchJS := []byte(`{"spec":{"terminationGracePeriodSeconds":42,"activeDeadlineSeconds":120}}`)
|
patchJS := []byte(`{"spec":{"terminationGracePeriodSeconds":42,"activeDeadlineSeconds":120}}`)
|
||||||
|
|
||||||
err := strategicPatchObject(codec, defaulter, currentVersionedObject, patchJS, versionedObjToUpdate, schemaReferenceObj)
|
err := strategicPatchObject(defaulter, currentVersionedObject, patchJS, versionedObjToUpdate, schemaReferenceObj)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue