MCPcopy
hub / github.com/apecloud/kubeblocks / normalize

Function normalize

controllers/trace/util.go:804–822  ·  view source on GitHub ↗

normalize normalizes the default value of fields to a uniform format, for example, a list with a length of 0 is normalized to nil. The purpose is making the object easily to be compared by reflect.DeepEqual.

(obj client.Object)

Source from the content-addressed store, hash-verified

802// normalize normalizes the default value of fields to a uniform format, for example, a list with a length of 0 is normalized to nil.
803// The purpose is making the object easily to be compared by reflect.DeepEqual.
804func normalize(obj client.Object) (client.Object, error) {
805 if obj == nil {
806 return nil, nil
807 }
808 data, err := json.Marshal(obj)
809 if err != nil {
810 return nil, err
811 }
812 t := reflect.TypeOf(obj)
813 if t.Kind() == reflect.Ptr {
814 t = t.Elem()
815 }
816 newObj := reflect.New(t).Interface().(client.Object)
817 err = json.Unmarshal(data, newObj)
818 if err != nil {
819 return nil, err
820 }
821 return newObj, nil
822}

Callers 7

copyAndMergeComponentFunction · 0.85
increaseGenerationFunction · 0.85
InsertMethod · 0.85
UpdateMethod · 0.85
actionsToResolveImageFunction · 0.85

Calls 3

MarshalMethod · 0.65
KindMethod · 0.65
UnmarshalMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…