Avoid unnecessary marshaling.
This commit is contained in:
		
							parent
							
								
									b69b6b26e5
								
							
						
					
					
						commit
						8db44d6f18
					
				|  | @ -89,7 +89,7 @@ func (c *Cluster) logStatefulSetChanges(old, new *v1beta1.StatefulSet, isUpdate | ||||||
| 			util.NameFromMeta(old.ObjectMeta), | 			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 != "" { | 	if reason != "" { | ||||||
| 		c.logger.Infof("Reason: %s", 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), | 			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 != "" { | 	if reason != "" { | ||||||
| 		c.logger.Infof("Reason: %s", 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) { | func (c *Cluster) logVolumeChanges(old, new spec.Volume, reason string) { | ||||||
| 	c.logger.Infof("Volume specification has been changed") | 	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 != "" { | 	if reason != "" { | ||||||
| 		c.logger.Infof("Reason: %s", 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 { | 	if len(pod.Spec.Containers) == 1 { | ||||||
| 		podContainer := pod.Spec.Containers[0] | 		podContainer := pod.Spec.Containers[0] | ||||||
| 		templateContainer := statefulset.Spec.Template.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 != "" { | 	if reason != "" { | ||||||
| 		c.logger.Infof("Reason: %s", reason) | 		c.logger.Infof("Reason: %s", reason) | ||||||
|  |  | ||||||
|  | @ -3,7 +3,6 @@ package util | ||||||
| import ( | import ( | ||||||
| 	"crypto/md5" | 	"crypto/md5" | ||||||
| 	"encoding/hex" | 	"encoding/hex" | ||||||
| 	"encoding/json" |  | ||||||
| 	"fmt" | 	"fmt" | ||||||
| 	"math/rand" | 	"math/rand" | ||||||
| 	"time" | 	"time" | ||||||
|  | @ -13,6 +12,7 @@ import ( | ||||||
| 	"github.bus.zalan.do/acid/postgres-operator/pkg/spec" | 	"github.bus.zalan.do/acid/postgres-operator/pkg/spec" | ||||||
| 	"k8s.io/client-go/pkg/api/v1" | 	"k8s.io/client-go/pkg/api/v1" | ||||||
| 	"k8s.io/client-go/pkg/types" | 	"k8s.io/client-go/pkg/types" | ||||||
|  | 	"strings" | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| var passwordChars = []byte("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789") | var passwordChars = []byte("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789") | ||||||
|  | @ -70,11 +70,5 @@ func Pretty(x interface{}) (f fmt.Formatter) { | ||||||
| 
 | 
 | ||||||
| func PrettyDiff(a, b interface{}) (result string) { | func PrettyDiff(a, b interface{}) (result string) { | ||||||
| 	diff := pretty.Diff(a, b) | 	diff := pretty.Diff(a, b) | ||||||
| 	json, err := json.MarshalIndent(diff, "", " ") | 	return strings.Join(diff, "\n") | ||||||
| 	if err != nil { |  | ||||||
| 		result = fmt.Sprintf("%v", diff) |  | ||||||
| 	} else { |  | ||||||
| 		result = string(json) |  | ||||||
| 	} |  | ||||||
| 	return |  | ||||||
| } | } | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue