importrefromtypingimportListfromhikaruimportDiffDetail,HikaruBase# TODO: filter out all the managed fields crapdefis_matching_diff(diff_detail:DiffDetail,fields_to_monitor:List[str])->bool:returnany(substringindiff_detail.formatted_pathforsubstringinfields_to_monitor)
[docs]defduplicate_without_fields(obj:HikaruBase,omitted_fields:List[str]):""" Duplicate a hikaru object, omitting the specified fields This is useful when you want to compare two versions of an object and first "cleanup" fields that shouldn't be compared. :param HikaruBase obj: A kubernetes object :param List[str] omitted_fields: List of fields to be omitted. Field name format should be '.' separated For example: ["status", "metadata.generation"] """ifobjisNone:returnNoneifnotomitted_fields:returnobjduplication=obj.dup()forfield_nameinomitted_fields:field_parts=field_name.split(".")try:iflen(field_parts)>1:parent_obj=duplication.object_at_path(field_parts[:-1])else:parent_obj=duplicationsetattr(parent_obj,field_parts[-1],None)exceptException:pass# in case the field doesn't exist on this objectreturnduplication