(un *unstructured.Unstructured, opts ...Option)
| 887 | } |
| 888 | |
| 889 | func 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. |
no test coverage detected