ref(kube): simplify encoding for creating patches

pull/1657/head
Adam Reese 8 years ago
parent fb9ef50bc8
commit 525df8f0d1

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

Loading…
Cancel
Save