{"id":31740827,"url":"https://github.com/joshdk/krf","last_synced_at":"2026-05-07T16:02:25.990Z","repository":{"id":317219571,"uuid":"1029759446","full_name":"joshdk/krf","owner":"joshdk","description":"🔬 Command line utility for filtering collections of Kubernetes resources","archived":false,"fork":false,"pushed_at":"2025-09-29T15:53:33.000Z","size":129,"stargazers_count":1,"open_issues_count":1,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-09-29T17:00:45.398Z","etag":null,"topics":["go","golang","k8s","kubectl","kubernetes","kustomize"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/joshdk.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-07-31T14:26:24.000Z","updated_at":"2025-09-29T15:06:24.000Z","dependencies_parsed_at":"2025-09-29T17:00:54.561Z","dependency_job_id":"5df90c63-d48f-445c-bd2f-76dfdba7d72b","html_url":"https://github.com/joshdk/krf","commit_stats":null,"previous_names":["joshdk/krf"],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/joshdk/krf","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joshdk%2Fkrf","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joshdk%2Fkrf/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joshdk%2Fkrf/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joshdk%2Fkrf/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/joshdk","download_url":"https://codeload.github.com/joshdk/krf/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joshdk%2Fkrf/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279001296,"owners_count":26083040,"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-10-09T02:00:07.460Z","response_time":59,"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":["go","golang","k8s","kubectl","kubernetes","kustomize"],"created_at":"2025-10-09T10:29:06.428Z","updated_at":"2026-05-07T16:02:25.983Z","avatar_url":"https://github.com/joshdk.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![License][license-badge]][license-link]\n[![Actions][github-actions-badge]][github-actions-link]\n[![Releases][github-release-badge]][github-release-link]\n\n# Kubernetes Resource Filter\n\n🔬 Command line utility for filtering collections of Kubernetes resources\n\n## What is this?\n\nThis repository provides `krf`, a tool that can be used to easily sift through large collections of Kubernetes resources using a number of powerful filters.\n\nThe original impetus for this was the need to search through a stream of Kubernetes yaml documents for resources that contain some value. \nThe immediate next problem is that tools like e.g. `grep` are only filename/line number aware at best; so you end up with a list of matching lines, but you are no closer to knowing which specific resources contain those lines.\nTo address this, `krf` was build as a Kubernetes resource aware `grep`, but can be utilized with both more power and precision.\n\n## Installation\n\n### Release artifact\n\nBinaries for various architectures are published on the [releases][github-release-link] page.\n\nThe latest release can be installed by running:\n\n```shell\nOS=$(uname | tr '[:upper:]' '[:lower:]')\nARCH=$(uname -m | sed 's/x86_64/amd64/; s/aarch64/arm64/')\ncurl -Lso krf.tar.gz https://github.com/joshdk/krf/releases/latest/download/krf-${OS}-${ARCH}.tar.gz\ntar -xf krf.tar.gz\nsudo mkdir -p /usr/local/bin/\nsudo install krf /usr/local/bin/\n```\n\n### Brew\n\nRelease binaries are also available via [Brew](https://brew.sh).\n\nThe latest release can be installed by running:\n\n```shell\nbrew tap joshdk/tap\nbrew install joshdk/tap/krf\n```\n\n### Go install\n\nInstallation can also be done directly from this repository.\n\nThe latest commit can be installed by running:\n\n```shell\ngo install github.com/joshdk/krf@master\n```\n\n## Usage\n\n### Reading Resources\n\nTo begin, a corpus of input resources can be provided in a number of ways.\n\nA single file:\n```shell\nkrf resources.yaml\n```\n\nAll yaml files contained within a directory:\n```shell\nkrf ./manifests/\n```\n\nThe output of `kustomize` build:\n```shell\nkustomize build … | krf\n```\n\nThe output of `kubectl` in yaml or json format:\n```shell\nkubectl get … -o=yaml | krf\nkubectl get … -o=json | krf\n```\n\n### Filtering Resources\n\nThe input corpus can then be filtered using a set of individual _matchers_ that you can mix and match.\n\nInclude resources that have the name `backend`:\n```shell\n… | krf --name backend\n```\n\nInclude resources that have the name `backend` and the namespace `default`:\n```shell\n… | krf --name backend --namespace default\n```\n\nInclude resources that have the name `backend` and are of kind `Deployment` or `Service`:\n```shell\n… | krf --name backend --kind deploy,svc\n```\n\nInclude resources that have the name `backend` or `frontend` and are not of kind `Ingress`:\n```shell\n… | krf --name backend,frontend --not-kind ing\n```\n\nFinally, simply output the same set of resources that were provided as input:\n```shell\n… | krf\n```\n\n#### Filtering Logic\n\nWhen `krf` is invoked, each input resource is evaluated against various categories of positive and negative matchers in order to reject, or ultimately accept the resource.\n\nAt a high level, in order to be accepted, each resource:\n- **Must not** match **any** of the negative matcher values from each provided category.\n- **Must** match **any** of the positive matcher values from each provided category.\n\nAs a concrete example, consider an invocation like so:\n```shell\n… | krf --not-kind job,po --name backend,cache --not-label role=secondary --namespace client-a,client-b,client-c\n```\n\nThe following checks are then performed against each resource in the input stream:\n\n- If the resource is of kind of `Job`, then the resource is **rejected**.\n- If the resource is of kind of `Pod`, then the resource is **rejected**.\n- If the resource has the label `role=secondary`, then the resource is **rejected**.\n- If the resource does not have a name of `backend` or `cache`, then the resource is **rejected**.\n- If the resource does not have a namespace of `client-a`, `client-b`, or `client-c`, then the resource is **rejected**.\n- Otherwise, the resource is finally **accepted**!\n\nA resource such as this would be accepted by the above rules:\n```yaml\napiVersion: apps/v1\nkind: Deployment\n\nmetadata:\n  name: cache\n  namespace: client-b\n  labels:\n    role: primary\n```\n\n### Outputting Resources\n\nBy default, resources will be output in a table format:\n```shell\n… | krf\nNamespace    API Version  Kind        Name              \n─────────    ───────────  ────        ────              \ndefault      apps/v1      Deployment  backend\n```\n\nIf resources are sourced from a file (opposed to stdin) then the associated paths will also be included:\n```shell\nkrf ./manifests\nNamespace    API Version  Kind        Name     Path\n─────────    ───────────  ────        ────     ────\ndefault      apps/v1      Deployment  backend  ./manifests/deployment.yaml\n```\n\nIf output is being redirected (to a file or another command) then the resources will be output in a yaml format:\n```shell\n… | krf | cat\napiVersion: apps/v1\nkind: Deployment\nmetadata:\n  namespace: default\n  name: backend\n```\n\nYou can also explicitly choose to output resources in yaml format:\n```shell\n… | krf -o=yaml\napiVersion: apps/v1\nkind: Deployment\nmetadata:\n  namespace: default\n  name: backend\n```\n\nConversely, you must explicitly choose to output resources in table format if you want to redirect that output: \n```shell\n… | krf -o=table | tee summary.txt\nNamespace    API Version  Kind        Name              \n─────────    ───────────  ────        ────              \ndefault      apps/v1      Deployment  backend\n```\n\nYou can also output only the names of filtered resources (similar to `kubectl -o=name`):\n```shell\n… | krf -o=name\nDeployment/backend\n```\n\nOr output only the names of resources that are referenced by filtered resources:\n\n```shell\n… | krf -o=references\nConfigMap/configuration\nPersistentVolumeClaim/database\nSecret/api-credentials\n```\n\n### Tips \u0026 Tricks\n\nHere is a collection of some useful ways to utilize `krf`.\n\nGet a quick overview of all resources:\n```shell\nkrf ./kustomize\n```\n\nShow resource patches (files ending in `.patch.yaml`) in the production overlay:\n```shell\nkrf ./kustomize/environments/production --patch\n```\n\nIdentify deployments that would roll if the credentials ConfigMap (which may have a generated name like `credentials-8mbdf7882g`) were updated: \n```shell\nkubectl get deploy -o=yaml | krf --references cm/credentials- \n````\n\nIdentify pods that do not have a security context configured:\n```shell\nkubectl get pod -o=yaml | krf --not-jsonpath '..securityContext'\n```\n\nIteratively verify the impact of refactors on resources:\n```shell\n# Render out the current resources:\nkustomize build ./kustomize/environments/production \u003e original.yaml\n\n# Perform your refactors on the various resources or manifests:\nvim ./kustomize/applications/kustomization.yaml\n\n# Render out the (now refactored) resources:\nkustomize build ./kustomize/environments/production \u003e modified.yaml\n\n# Display a list of any of the modified resources which differences from their \n# original counterparts. Verify that your changes had the desired impact, or \n# even to verify that no resources were ultimately impacted.\nkrf --diff original.yaml modified.yaml\n```\n\nSelectively apply certain resources:\n```shell\nkustomize build … | krf --kind svc,ing | kubectl apply -f -\n```\n\nPerform some additional processing on resources:\n```shell\nkrf … -o=json | while IFS= read -r line; do\n  echo $line | jq -r '. | \"processing \\(.kind)/\\(.metadata.name)...\"'\ndone\n```\n\n## License\n\nThis code is distributed under the [MIT License][license-link], see [LICENSE.txt][license-file] for more information.\n\n---\n\n\u003cp align=\"center\"\u003e\n  Created by \u003ca href=\"https://github.com/joshdk\"\u003eJosh Komoroske\u003c/a\u003e ☕\n\u003c/p\u003e\n\n[github-actions-badge]:  https://github.com/joshdk/krf/actions/workflows/build.yaml/badge.svg\n[github-actions-link]:   https://github.com/joshdk/krf/actions/workflows/build.yaml\n[github-release-badge]:  https://img.shields.io/github/release/joshdk/krf/all.svg\n[github-release-link]:   https://github.com/joshdk/krf/releases\n[license-badge]:         https://img.shields.io/badge/license-MIT-green.svg\n[license-file]:          https://github.com/joshdk/krf/blob/master/LICENSE.txt\n[license-link]:          https://opensource.org/licenses/MIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjoshdk%2Fkrf","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjoshdk%2Fkrf","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjoshdk%2Fkrf/lists"}