Commit 525df8f0 authored by Adam Reese's avatar Adam Reese

ref(kube): simplify encoding for creating patches

parent fb9ef50b
......@@ -22,7 +22,6 @@ import (
"fmt"
"io"
"log"
"reflect"
"strings"
"time"
......@@ -36,7 +35,6 @@ import (
"k8s.io/kubernetes/pkg/kubectl/resource"
"k8s.io/kubernetes/pkg/runtime"
"k8s.io/kubernetes/pkg/util/strategicpatch"
"k8s.io/kubernetes/pkg/util/yaml"
"k8s.io/kubernetes/pkg/watch"
)
......@@ -298,33 +296,22 @@ func deleteResource(info *resource.Info) error {
}
func updateResource(target *resource.Info, currentObj runtime.Object) error {
encoder := api.Codecs.LegacyCodec(registered.EnabledVersions()...)
originalSerialization, err := runtime.Encode(encoder, currentObj)
if err != nil {
return err
}
editedSerialization, err := runtime.Encode(encoder, target.Object)
if err != nil {
return err
}
originalJS, err := yaml.ToJSON(originalSerialization)
original, err := runtime.Encode(encoder, currentObj)
if err != nil {
return err
}
editedJS, err := yaml.ToJSON(editedSerialization)
modified, err := runtime.Encode(encoder, target.Object)
if err != nil {
return err
}
if reflect.DeepEqual(originalJS, editedJS) {
if api.Semantic.DeepEqual(original, modified) {
return ErrAlreadyExists{target.Name}
}
patch, err := strategicpatch.CreateStrategicMergePatch(originalJS, editedJS, currentObj)
patch, err := strategicpatch.CreateTwoWayMergePatch(original, modified, currentObj)
if err != nil {
return err
}
......
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