From 8db44d6f1848fe496074cc65033fb20ee666f971 Mon Sep 17 00:00:00 2001 From: Oleksii Kliukin Date: Thu, 6 Apr 2017 15:39:32 +0200 Subject: [PATCH] Avoid unnecessary marshaling. --- pkg/cluster/util.go | 8 ++++---- pkg/util/util.go | 10 ++-------- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/pkg/cluster/util.go b/pkg/cluster/util.go index f994eca05..3bd21c792 100644 --- a/pkg/cluster/util.go +++ b/pkg/cluster/util.go @@ -89,7 +89,7 @@ func (c *Cluster) logStatefulSetChanges(old, new *v1beta1.StatefulSet, isUpdate util.NameFromMeta(old.ObjectMeta), ) } - c.logger.Debugf("diff %s\n", util.PrettyDiff(old.Spec, new.Spec)) + c.logger.Debugf("diff\n%s\n", util.PrettyDiff(old.Spec, new.Spec)) if reason != "" { c.logger.Infof("Reason: %s", reason) @@ -106,7 +106,7 @@ func (c *Cluster) logServiceChanges(old, new *v1.Service, isUpdate bool, reason util.NameFromMeta(old.ObjectMeta), ) } - c.logger.Debugf("diff %s\n", util.PrettyDiff(old.Spec, new.Spec)) + c.logger.Debugf("diff\n%s\n", util.PrettyDiff(old.Spec, new.Spec)) if reason != "" { c.logger.Infof("Reason: %s", reason) @@ -115,7 +115,7 @@ func (c *Cluster) logServiceChanges(old, new *v1.Service, isUpdate bool, reason func (c *Cluster) logVolumeChanges(old, new spec.Volume, reason string) { c.logger.Infof("Volume specification has been changed") - c.logger.Debugf("diff %s\n", util.PrettyDiff(old, new)) + c.logger.Debugf("diff\n%s\n", util.PrettyDiff(old, new)) if reason != "" { c.logger.Infof("Reason: %s", reason) } @@ -129,7 +129,7 @@ func (c *Cluster) logPodChanges(pod *v1.Pod, statefulset *v1beta1.StatefulSet, r if len(pod.Spec.Containers) == 1 { podContainer := pod.Spec.Containers[0] templateContainer := statefulset.Spec.Template.Spec.Containers[0] - c.logger.Debugf("diff %s", util.PrettyDiff(podContainer, templateContainer)) + c.logger.Debugf("diff\n%s", util.PrettyDiff(podContainer, templateContainer)) } if reason != "" { c.logger.Infof("Reason: %s", reason) diff --git a/pkg/util/util.go b/pkg/util/util.go index a016e0b52..9b8c5d74f 100644 --- a/pkg/util/util.go +++ b/pkg/util/util.go @@ -3,7 +3,6 @@ package util import ( "crypto/md5" "encoding/hex" - "encoding/json" "fmt" "math/rand" "time" @@ -13,6 +12,7 @@ import ( "github.bus.zalan.do/acid/postgres-operator/pkg/spec" "k8s.io/client-go/pkg/api/v1" "k8s.io/client-go/pkg/types" + "strings" ) var passwordChars = []byte("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789") @@ -70,11 +70,5 @@ func Pretty(x interface{}) (f fmt.Formatter) { func PrettyDiff(a, b interface{}) (result string) { diff := pretty.Diff(a, b) - json, err := json.MarshalIndent(diff, "", " ") - if err != nil { - result = fmt.Sprintf("%v", diff) - } else { - result = string(json) - } - return + return strings.Join(diff, "\n") }