{"id":20102922,"url":"https://github.com/stackrox/k8s-overlay-patch","last_synced_at":"2025-06-25T19:32:47.029Z","repository":{"id":178349514,"uuid":"661654929","full_name":"stackrox/k8s-overlay-patch","owner":"stackrox","description":"Kubernetes overlay patches","archived":false,"fork":false,"pushed_at":"2025-06-07T00:39:17.000Z","size":95,"stargazers_count":0,"open_issues_count":10,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-06-07T01:28:14.627Z","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/stackrox.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":"CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2023-07-03T10:57:59.000Z","updated_at":"2025-02-24T11:09:29.000Z","dependencies_parsed_at":"2023-12-21T12:04:42.500Z","dependency_job_id":"a9dcca15-f7a3-4555-8eaf-18ab6064acf2","html_url":"https://github.com/stackrox/k8s-overlay-patch","commit_stats":null,"previous_names":["stackrox/k8s-overlay-patch"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/stackrox/k8s-overlay-patch","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stackrox%2Fk8s-overlay-patch","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stackrox%2Fk8s-overlay-patch/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stackrox%2Fk8s-overlay-patch/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stackrox%2Fk8s-overlay-patch/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/stackrox","download_url":"https://codeload.github.com/stackrox/k8s-overlay-patch/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stackrox%2Fk8s-overlay-patch/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261940779,"owners_count":23233599,"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","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-13T17:33:29.950Z","updated_at":"2025-06-25T19:32:46.984Z","avatar_url":"https://github.com/stackrox.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# k8s-overlay-patch\nKubernetes overlay patches\n\n## Disclaimer\nThis codebase was mostly plucked from https://github.com/istio/istio\n\n## Purpose\nUsers often need to customize the resources generated from a kubernetes operator/Custom Resource. Though, for every new\nconfiguration option that needs to be added, new fields need to be added to the Custom Resource. \nThis is time-consuming and can lead to a bloated Custom Resource. \n\nThis library implements logic so that these overlays are a first-class citizen in a CRD. This allows\nusers to customize the output of a kubernetes operator by overlaying patches on top of the generated output, without\nhaving to modify the CRD.\n\n## Command-line usage\n\n```\nUsage:\n  k8s-overlay-patch [flags]\n\nFlags:\n  -h, --help                   help for k8s-overlay-patch\n  -m, --manifest-file string   File containing the rendered manifests to patch\n  -n, --namespace string       Namespace to use when patching the manifests\n  -o, --out string             File to write the patched manifests to\n  -p, --patch-file string      File containing the patch to apply\n```\n\n\n## Usage as helm post-renderer\n\nExample\n\n```\nhelm template test pkg/testdata/chart --debug --dry-run --post-renderer pkg/testdata/postrender.sh\n```\n\n```\n# build the binary and place it in your path\ngo build\n\n# Create a postrender.sh file. Helm doesn't allow passing\n# arguments to postrenderers.\n#!/bin/bash\nk8s-overlay-patch -n default -p patch.yaml\n\n# Make the file executable\nchmod +x postrender.sh\n\n# Call helm with the postrender.sh file\nhelm template [NAME] [CHART] --post-renderer postrender.sh\n\n```\n\n## Example usage with CRD\n\n#### Adding the overlay patch to the CRD\n```go\npackage v1alpha1\n\ntype MySpec struct {\n\t// Overlays is the list of overlay patches to apply to resource.\n\t//+operator-sdk:csv:customresourcedefinitions:type=spec,displayName=\"Patches\",order=4\n\tOverlays []K8sObjectOverlay `json:\"overlays,omitempty\"`\n}\n\n\ntype K8sObjectOverlay struct {\n\t// Resource API version.\n\t//+operator-sdk:csv:customresourcedefinitions:type=spec,displayName=\"API Version\",order=1\n\tApiVersion string `json:\"apiVersion,omitempty\"`\n\t// Resource kind.\n\t//+operator-sdk:csv:customresourcedefinitions:type=spec,displayName=\"Kind\",order=2\n\tKind string `json:\"kind,omitempty\"`\n\t// Name of resource.\n\t//+operator-sdk:csv:customresourcedefinitions:type=spec,displayName=\"Name\",order=3\n\tName string `json:\"name,omitempty\"`\n\t// List of patches to apply to resource.\n\t//+operator-sdk:csv:customresourcedefinitions:type=spec,displayName=\"Patches\",order=4\n\tPatches []*K8sObjectOverlayPatch `json:\"patches,omitempty\"`\n}\n\ntype K8sObjectOverlayPatch struct {\n\t// Path of the form a.[key1:value1].b.[:value2]\n\t// Where [key1:value1] is a selector for a key-value pair to identify a list element and [:value] is a value\n\t// selector to identify a list element in a leaf list.\n\t// All path intermediate nodes must exist.\n\t//+operator-sdk:csv:customresourcedefinitions:type=spec,displayName=\"Path\",order=1\n\tPath string `json:\"path,omitempty\"`\n\t// Value to add, delete or replace.\n\t// For add, the path should be a new leaf.\n\t// For delete, value should be unset.\n\t// For replace, path should reference an existing node.\n\t// All values are strings but are converted into appropriate type based on schema.\n\t//+operator-sdk:csv:customresourcedefinitions:type=spec,displayName=\"Value\",order=2\n\tValue string `json:\"value,omitempty\"`\n\t// Verbatim value to add, delete or replace.\n\t// Same as Value, however the content is not interpreted as YAML, but treated as literal string instead.\n\t// At least one of Value and Verbatim must be empty.\n\t//+operator-sdk:csv:customresourcedefinitions:type=spec,displayName=\"Verbatim\",order=3\n\tVerbatim string `json:\"verbatim,omitempty\"`\n}\n\n```\n\n\n#### Using the overlay patch in the reconciler\n```go\npackage reconciler\n\nimport (\n\t\"github.com/stackrox/k8s-overlay-patch/pkg/patch\"\n\t\"github.com/stackrox/k8s-overlay-patch/pkg/types\"\n)\n\nfunc (r reconciler) Reconcile(obj v1alpha1.MyObject){\n\tmanifests := renderManifests(obj)\n\tpatched := patch.YAMLManifestPatch(manifests, obj.Namespace, mapOverlays(obj.Spec.Overlays))\n\t// ...\n}\n\nfunc mapOverlays(overlays []*v1alpha1.K8sObjectOverlay) []*types.K8sObjectOverlay {\n\tout := make([]*types.K8sObjectOverlay, len(overlays))\n\tfor i, o := range overlays {\n\t\tout[i] = \u0026types.K8sObjectOverlay{\n\t\t\tApiVersion: o.ApiVersion,\n\t\t\tKind:       o.Kind,\n\t\t\tName:       o.Name,\n\t\t\tPatches:    mapOverlayPatches(o.Patches),\n\t\t}\n\t}\n\treturn out\n}\n\nfunc mapOverlayPatches(patches []*v1alpha1.K8sObjectOverlayPatch) []*types.K8sObjectOverlayPatch {\n\tout := make([]*types.K8sObjectOverlayPatch, len(patches))\n\tfor i, p := range patches {\n\t\tout[i] = \u0026types.K8sObjectOverlayPatch{\n\t\t\tPath:     p.Path,\n\t\t\tValue:    p.Value,\n\t\t\tVerbatim: p.Verbatim,\n\t\t}\n\t}\n\treturn out\n}\n\n\n```\n\n#### Example CRD\n```yaml\napiVersion: blah.com/v1alpha1\nkind: MyObject\nmetadata:\n  name: my-object\nspec:\n  resources:\n    requests:\n      cpu: 100m\n      memory: 128Mi\n    limits:\n      cpu: 200m\n      memory: 256Mi        \n  overlays:\n  - apiVersion: v1\n    kind: ConfigMap\n    name: my-config-map\n    patches:\n    - path: data.foo\n      value: bar\n    - path: data.baz\n      verbatim: |\n        qux\n        separate lines\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstackrox%2Fk8s-overlay-patch","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstackrox%2Fk8s-overlay-patch","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstackrox%2Fk8s-overlay-patch/lists"}