Avoid unnecessary marshaling.

This commit is contained in:
Oleksii Kliukin 2017-04-06 15:39:32 +02:00 committed by Murat Kabilov
parent b69b6b26e5
commit 8db44d6f18
2 changed files with 6 additions and 12 deletions

View File

@ -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)

View File

@ -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")
}