{"id":13644103,"url":"https://github.com/patrickdappollonio/kubectl-slice","last_synced_at":"2025-04-08T02:36:57.316Z","repository":{"id":37684955,"uuid":"419529156","full_name":"patrickdappollonio/kubectl-slice","owner":"patrickdappollonio","description":"Split multiple Kubernetes files into smaller files with ease. Split multi-YAML files into individual files.","archived":false,"fork":false,"pushed_at":"2025-03-31T03:08:43.000Z","size":259,"stargazers_count":335,"open_issues_count":5,"forks_count":25,"subscribers_count":5,"default_branch":"main","last_synced_at":"2025-04-01T01:38:08.704Z","etag":null,"topics":["hacktoberfest","kubectl","kubectl-plugin","kubectl-plugins","yaml","yaml-parser"],"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/patrickdappollonio.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}},"created_at":"2021-10-21T00:21:44.000Z","updated_at":"2025-03-30T11:28:09.000Z","dependencies_parsed_at":"2023-12-26T05:30:17.853Z","dependency_job_id":"2bab8546-f8c5-462a-a762-971bedf2324a","html_url":"https://github.com/patrickdappollonio/kubectl-slice","commit_stats":null,"previous_names":["patrickdappollonio/kubectl-split"],"tags_count":17,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/patrickdappollonio%2Fkubectl-slice","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/patrickdappollonio%2Fkubectl-slice/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/patrickdappollonio%2Fkubectl-slice/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/patrickdappollonio%2Fkubectl-slice/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/patrickdappollonio","download_url":"https://codeload.github.com/patrickdappollonio/kubectl-slice/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247765730,"owners_count":20992361,"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":["hacktoberfest","kubectl","kubectl-plugin","kubectl-plugins","yaml","yaml-parser"],"created_at":"2024-08-02T01:01:57.572Z","updated_at":"2025-04-08T02:36:57.291Z","avatar_url":"https://github.com/patrickdappollonio.png","language":"Go","funding_links":[],"categories":["yaml","Go"],"sub_categories":[],"readme":"# `kubectl-slice`: split Kubernetes YAMLs into files\n\n[![Downloads](https://img.shields.io/github/downloads/patrickdappollonio/kubectl-slice/total?color=blue\u0026logo=github\u0026style=flat-square)](https://github.com/patrickdappollonio/kubectl-slice/releases)\n\n- [`kubectl-slice`: split Kubernetes YAMLs into files](#kubectl-slice-split-kubernetes-yamls-into-files)\n  - [Installation](#installation)\n    - [Using `krew`](#using-krew)\n    - [Using Homebrew](#using-homebrew)\n    - [Download and install manually](#download-and-install-manually)\n  - [Usage](#usage)\n  - [Why `kubectl-slice`?](#why-kubectl-slice)\n  - [Passing configuration options to `kubectl-slice`](#passing-configuration-options-to-kubectl-slice)\n  - [Including and excluding manifests from the output](#including-and-excluding-manifests-from-the-output)\n  - [Examples](#examples)\n  - [Contributing \\\u0026 Roadmap](#contributing--roadmap)\n\n`kubectl-slice` is a tool that allows you to split a single multi-YAML Kubernetes manifest (with `--input-file` or `-f`), or a folder containing multiple manifests files (with `--input-folder` or `-d`, optionally with `--recursive`), into multiple subfiles using a naming convention you choose. This is done by parsing the YAML code and allowing you to access any key from the YAML object [using Go Templates](https://pkg.go.dev/text/template).\n\nBy default, `kubectl-slice` will split your files into multiple subfiles following this naming convention that you can configure to your liking:\n\n```handlebars\n{{.kind | lower}}-{{.metadata.name}}.yaml\n```\n\nThat is, the Kubernetes kind -- in this case, the value `Namespace` -- lowercased, followed by a dash, followed by the resource name -- in this case, the value `production`:\n\n```text\nnamespace-production.yaml\n```\n\nIf your YAML includes multiple files, for example:\n\n```yaml\napiVersion: v1\nkind: Pod\nmetadata:\n  name: nginx-ingress\n---\napiVersion: v1\nkind: Namespace\nmetadata:\n  name: production\n```\n\nThen the following files will be created:\n\n```text\n$ kubectl-slice --input-file=input.yaml --output-dir=.\nWrote pod-nginx-ingress.yaml -- 58 bytes.\nWrote namespace-production.yaml -- 61 bytes.\n2 files generated.\n```\n\nYou can customize the file name to your liking, by using the `--template` flag.\n\n## Installation\n\n`kubectl-slice` can be used as a standalone tool or through `kubectl`, as a plugin.\n\n### Using `krew`\n\n`kubectl-slice` is available as a [krew plugin](https://krew.sigs.k8s.io/docs/user-guide/installing-plugins/).\n\nTo install, use the following command:\n\n```bash\nkubectl krew install slice\n```\n\n### Using Homebrew\n\n`kubectl-slice` is available as a Homebrew tap for both macOS and Linux:\n\n```bash\nbrew install patrickdappollonio/tap/kubectl-slice\n```\n\n### Download and install manually\n\nDownload the latest release for your platform from the [Releases page](https://github.com/patrickdappollonio/kubectl-slice/releases), then extract and move the `kubectl-slice` binary to any place in your `$PATH`. If you have `kubectl` installed, you can use both `kubectl-slice` and `kubectl slice` (note in the later the absence of the `-`).\n\n## Usage\n\n```text\nkubectl-slice allows you to split a YAML into multiple subfiles using a pattern.\nFor documentation, available functions, and more, visit: https://github.com/patrickdappollonio/kubectl-slice.\n\nUsage:\n  kubectl-slice [flags]\n\nExamples:\n  kubectl-slice -f foo.yaml -o ./ --include-kind Pod,Namespace\n  kubectl-slice -f foo.yaml -o ./ --exclude-kind Pod\n  kubectl-slice -f foo.yaml -o ./ --exclude-name *-svc\n  kubectl-slice -f foo.yaml --exclude-name *-svc --stdout\n  kubectl-slice -f foo.yaml --include Pod/* --stdout\n  kubectl-slice -f foo.yaml --exclude deployment/kube* --stdout\n  kubectl-slice -d ./ --recurse -o ./ --include-kind Pod,Namespace\n  kubectl-slice -d ./ --recurse --stdout --include Pod/*\n  kubectl-slice --config config.yaml\n\nFlags:\n      --allow-empty-kinds      if enabled, resources with empty kinds don't produce an error when filtering\n      --allow-empty-names      if enabled, resources with empty names don't produce an error when filtering\n  -c, --config string          path to the config file\n      --dry-run                if true, no files are created, but the potentially generated files will be printed as the command output\n      --exclude strings        resource name to exclude in the output (format \u003ckind\u003e/\u003cname\u003e, case insensitive, glob supported)\n      --exclude-kind strings   resource kind to exclude in the output (singular, case insensitive, glob supported)\n      --exclude-name strings   resource name to exclude in the output (singular, case insensitive, glob supported)\n      --extensions strings     the extensions to look for in the input folder (default [.yaml,.yml])\n  -h, --help                   help for kubectl-slice\n      --include strings        resource name to include in the output (format \u003ckind\u003e/\u003cname\u003e, case insensitive, glob supported)\n      --include-kind strings   resource kind to include in the output (singular, case insensitive, glob supported)\n      --include-name strings   resource name to include in the output (singular, case insensitive, glob supported)\n      --include-triple-dash    if enabled, the typical \"---\" YAML separator is included at the beginning of resources sliced\n  -f, --input-file string      the input file used to read the initial macro YAML file; if empty or \"-\", stdin is used (exclusive with --input-folder)\n  -d, --input-folder string    the input folder used to read the initial macro YAML files (exclusive with --input-file)\n  -o, --output-dir string      the output directory used to output the splitted files\n      --prune                  if enabled, the output directory will be pruned before writing the files\n  -q, --quiet                  if true, no output is written to stdout/err\n  -r, --recurse                if true, the input folder will be read recursively (has no effect unless used with --input-folder)\n  -s, --skip-non-k8s           if enabled, any YAMLs that don't contain at least an \"apiVersion\", \"kind\" and \"metadata.name\" will be excluded from the split\n      --sort-by-kind           if enabled, resources are sorted by Kind, a la Helm, before saving them to disk\n      --stdout                 if enabled, no resource is written to disk and all resources are printed to stdout instead\n  -t, --template string        go template used to generate the file name when creating the resource files in the output directory (default \"{{.kind | lower}}-{{.metadata.name}}.yaml\")\n  -v, --version                version for kubectl-slice\n```\n\n## Why `kubectl-slice`?\n\nSee [why `kubectl-slice`?](docs/why.md) for more information.\n\n## Passing configuration options to `kubectl-slice`\n\nBesides command-line flags, you can also use environment variables and a YAML configuration file to pass options to `kubectl-slice`. See [the documentation for configuration options](docs/configuring-cli.md) for details about both, including precedence.\n\n## Including and excluding manifests from the output\n\nIncluding or excluding manifests from the output via `metadata.name` or `kind` is possible. Globs are supported in both cases. See [the documentation for including and excluding items](docs/including-excluding-items.md) for more information.\n\n## Examples\n\nSee [examples](docs/examples.md) for more information.\n\n## Contributing \u0026 Roadmap\n\nPull requests are welcomed! So far, looking for help with the following items, which are also part of the roadmap:\n\n* Adding unit tests\n* Improving the YAML file-by-file parser, right now it works by buffering line by line\n* Adding support to install through `brew`\n* [Adding new features marked as `enhancement`](//github.com/patrickdappollonio/kubectl-slice/issues?q=is%3Aissue+is%3Aopen+label%3Aenhancement)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpatrickdappollonio%2Fkubectl-slice","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpatrickdappollonio%2Fkubectl-slice","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpatrickdappollonio%2Fkubectl-slice/lists"}