@@ -693,6 +693,7 @@ func CloneSelectorAndAddLabel(selector *metav1.LabelSelector, labelKey, labelVal
693693// DeepHashObject writes specified object to hash using the spew library
694694// which follows pointers and prints actual values of the nested objects
695695// ensuring the hash does not change when a pointer changes.
696+ // Deprecated: Please use controllers/mdutil SpewHashObject(hasher, objectToWrite).
696697func DeepHashObject (hasher hash.Hash , objectToWrite interface {}) {
697698 hasher .Reset ()
698699 printer := spew.ConfigState {
@@ -701,16 +702,46 @@ func DeepHashObject(hasher hash.Hash, objectToWrite interface{}) {
701702 DisableMethods : true ,
702703 SpewKeys : true ,
703704 }
704- printer .Fprintf (hasher , "%#v" , objectToWrite )
705+ // We ignore the returned error because there is no way to return the error without
706+ // breaking API compatibility. Please use SpewHashObject instead.
707+ _ , _ = printer .Fprintf (hasher , "%#v" , objectToWrite )
705708}
706709
707- // ComputeHash computes the has of a MachineTemplateSpec.
710+ // SpewHashObject writes specified object to hash using the spew library
711+ // which follows pointers and prints actual values of the nested objects
712+ // ensuring the hash does not change when a pointer changes.
713+ func SpewHashObject (hasher hash.Hash , objectToWrite interface {}) error {
714+ hasher .Reset ()
715+ printer := spew.ConfigState {
716+ Indent : " " ,
717+ SortKeys : true ,
718+ DisableMethods : true ,
719+ SpewKeys : true ,
720+ }
721+
722+ if _ , err := printer .Fprintf (hasher , "%#v" , objectToWrite ); err != nil {
723+ return fmt .Errorf ("failed to write object to hasher" )
724+ }
725+ return nil
726+ }
727+
728+ // ComputeHash computes the hash of a MachineTemplateSpec using the spew library.
729+ // Deprecated: Please use controllers/mdutil ComputeSpewHash(template).
708730func ComputeHash (template * clusterv1.MachineTemplateSpec ) uint32 {
709731 machineTemplateSpecHasher := fnv .New32a ()
710732 DeepHashObject (machineTemplateSpecHasher , * template )
711733 return machineTemplateSpecHasher .Sum32 ()
712734}
713735
736+ // ComputeSpewHash computes the hash of a MachineTemplateSpec using the spew library.
737+ func ComputeSpewHash (template * clusterv1.MachineTemplateSpec ) (uint32 , error ) {
738+ machineTemplateSpecHasher := fnv .New32a ()
739+ if err := SpewHashObject (machineTemplateSpecHasher , * template ); err != nil {
740+ return 0 , err
741+ }
742+ return machineTemplateSpecHasher .Sum32 (), nil
743+ }
744+
714745// GetDeletingMachineCount gets the number of machines that are in the process of being deleted
715746// in a machineList.
716747func GetDeletingMachineCount (machineList * clusterv1.MachineList ) int32 {
0 commit comments