{"id":18291138,"url":"https://github.com/rhecosystemappeng/patch-utils","last_synced_at":"2025-08-20T18:08:14.714Z","repository":{"id":256234160,"uuid":"854744138","full_name":"RHEcosystemAppEng/patch-utils","owner":"RHEcosystemAppEng","description":"Go module hosting utilities for patching Kubernetes resources.","archived":false,"fork":false,"pushed_at":"2025-01-14T00:45:17.000Z","size":53,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-08-09T21:46:52.521Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/RHEcosystemAppEng.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-09-09T17:48:35.000Z","updated_at":"2025-01-14T00:45:14.000Z","dependencies_parsed_at":"2024-09-09T19:28:31.271Z","dependency_job_id":"7ee7c903-1142-400f-a148-771a8020a66a","html_url":"https://github.com/RHEcosystemAppEng/patch-utils","commit_stats":null,"previous_names":["rhecosystemappeng/patch-utils"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/RHEcosystemAppEng/patch-utils","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RHEcosystemAppEng%2Fpatch-utils","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RHEcosystemAppEng%2Fpatch-utils/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RHEcosystemAppEng%2Fpatch-utils/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RHEcosystemAppEng%2Fpatch-utils/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/RHEcosystemAppEng","download_url":"https://codeload.github.com/RHEcosystemAppEng/patch-utils/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RHEcosystemAppEng%2Fpatch-utils/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271362054,"owners_count":24746495,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-20T02:00:09.606Z","response_time":69,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-05T14:13:20.921Z","updated_at":"2025-08-20T18:08:14.647Z","avatar_url":"https://github.com/RHEcosystemAppEng.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Kubernetes Operator Patch Utils\n\nWhen developing Kubernetes Operators for production use, patching is often the most robust approach for updating\nexisting objects. This module hosts utilities for creating standard patching functions.\n\n## Usage\n\n### JSON Patching\n\n```go\npackage yourpkg\n\nimport (\n    \"context\"\n    patchutils \"github.com/rhecosystemappeng/patch-utils/pkg\"\n    \"sigs.k8s.io/controller-runtime/pkg/client\"\n)\n\nfunc yourFunc() {\n    // assign with your own\n    var ctx context.Context\n    var clt client.Client\n    var obj client.Object\n\n    // #####################################################################\n    // ##### Patch Labels, Annotations, or any other map[string]string #####\n    // #####################################################################\n    // patches is a list of patchutils.JsonPatch that will get executed once you execute the\n    // patchFunc, patchutils.PatchFunc. err is an error from the patch generation process;\n    // executing patchFunc might return an error arising from the API calls.\n    // use the wrapper function patchutils.JsonPatchMapP if you don't need the generation error.\n    // use the wrapper function patchutils.JsonPatchMapQ if you only need the patchFunc.\n    patches, patchFunc, err := patchutils.JsonPatchMap(\n        ctx, clt, obj, \"/metadata/labels\", obj.GetLabels(), map[string]string{\n            patchutils.SanitizeKeyForJsonPatch(\"your.label/first.key\"): \"label-value\",\n            patchutils.SanitizeKeyForJsonPatch(\"your.label/second.key\"): \"another-label-value\",\n    })\n    patchErr := patchFunc() // this statement executes the patches against the api\n\n    // #################################\n    // ##### Patch any Spec object #####\n    // #################################\n    // assign with your own spec\n    var spec *interface{}\n    // patch is the patchutils.JsonPatch that will get executed once you execute the patchFunc,\n    // patchutils.PatchFunc. err is an error from the patch generation process; executing patchFunc\n    // might return an error arising from the API calls.\n    // use the wrapper function patchutils.JsonPatchSpecP if you don't need the generation error.\n    // use the wrapper function patchutils.JsonPatchSpecQ if you only need the patchFunc.\n    patch, patchFunc, err := patchutils.JsonPatchSpec(ctx, clt, obj, spec)\n    patchErr := patchFunc() // this statement executes the patches against the api\n\n    // ############################################\n    // ##### Patch a finalizer into an object #####\n    // ############################################\n    // patch is the patchutils.JsonPatch that will get executed once you execute the patchFunc,\n    // patchutils.PatchFunc. err is an error from the patch generation process; executing patchFunc\n    // might return an error arising from the API calls.\n    // use the wrapper function patchutils.JsonPatchFinalizerInP if you don't need the generation error.\n    // use the wrapper function patchutils.JsonPatchFinalizerInQ if you only need the patchFunc.\n    patch, patchFunc, err := patchutils.JsonPatchFinalizerIn(ctx, clt, obj, \"my.custom/cleanup-finalizer\")\n    patchErr := patchFunc() // this statement executes the patches against the api\n\n    // ##############################################\n    // ##### Patch a finalizer out of an object #####\n    // ##############################################\n    // patch is the patchutils.JsonPatch that will get executed once you execute the patchFunc,\n    // patchutils.PatchFunc. err is an error from the patch generation process; executing patchFunc\n    // might return an error arising from the API calls.\n    // use the wrapper function patchutils.JsonPatchFinalizerOutP if you don't need the generation error.\n    // use the wrapper function patchutils.JsonPatchFinalizerOutQ if you only need the patchFunc.\n    patch, patchFunc, err := patchutils.JsonPatchFinalizerOut(ctx, clt, obj, \"my.custom/cleanup-finalizer\")\n    patchErr := patchFunc() // this statement executes the patches against the api\n}\n\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frhecosystemappeng%2Fpatch-utils","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frhecosystemappeng%2Fpatch-utils","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frhecosystemappeng%2Fpatch-utils/lists"}