MCPcopy
hub / github.com/argoproj/argo-cd / Normalize

Function Normalize

gitops-engine/pkg/diff/diff.go:889–918  ·  view source on GitHub ↗
(un *unstructured.Unstructured, opts ...Option)

Source from the content-addressed store, hash-verified

887}
888
889func Normalize(un *unstructured.Unstructured, opts ...Option) {
890 if un == nil {
891 return
892 }
893 o := applyOptions(opts)
894
895 // creationTimestamp is sometimes set to null in the config when exported (e.g. SealedSecrets)
896 // Removing the field allows a cleaner diff.
897 unstructured.RemoveNestedField(un.Object, "metadata", "creationTimestamp")
898
899 gvk := un.GroupVersionKind()
900 switch {
901 case gvk.Group == "" && gvk.Kind == "Secret":
902 NormalizeSecret(un, opts...)
903 case gvk.Group == "rbac.authorization.k8s.io" && (gvk.Kind == "ClusterRole" || gvk.Kind == "Role"):
904 normalizeRole(un, o)
905 case gvk.Group == "" && gvk.Kind == "Endpoints":
906 normalizeEndpoint(un, o)
907 }
908
909 // Skip the full normalization (ignoreDifferences + knownTypes) for server-side diff
910 // In the case an ignoreDifferences field is required, it needs to be present in the config
911 // before server-side diff is calculated and normalized before final comparison.
912 if !o.skipFullNormalize {
913 err := o.normalizer.Normalize(un)
914 if err != nil {
915 o.log.Error(err, fmt.Sprintf("Failed to normalize %s/%s/%s", un.GroupVersionKind(), un.GetNamespace(), un.GetName()))
916 }
917 }
918}
919
920// NormalizeSecret mutates the supplied object and encodes stringData to data, and converts nils to
921// empty strings. If the object is not a secret, or is an invalid secret, then returns the same object.

Callers 2

DiffFunction · 0.70
serverSideDiffFunction · 0.70

Calls 9

NormalizeSecretFunction · 0.85
normalizeRoleFunction · 0.85
normalizeEndpointFunction · 0.85
applyOptionsFunction · 0.70
NormalizeMethod · 0.65
GetNamespaceMethod · 0.65
GetNameMethod · 0.65
GroupVersionKindMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected