kglob
pip install kglob==0.1.0
Kustomize's resources: field takes an explicit list of files. There is no glob support in it, on purpose: kustomize build never touches the file system beyond what the file declares. kglob keeps that explicit list up to date for you, at edit time, from a pattern you write once in a comment.
resources:
# kglob: apps/*.yaml
- apps/api.yaml
- apps/web.yaml
patches:
- path: patch.yaml
$ kglob .
kustomization.yaml: 1 added, 0 removed
Run it again with nothing changed on disk, and it says so and touches nothing:
$ kglob .
kglob: nothing to do
Use it
kglob [PATH]scansPATH(a kustomization file, or a directory, default.) forkustomization.yaml/kustomization.ymlfiles that carry a# kglob: <pattern>marker, and rewrites the list under each marker to match the pattern against the file system: files that appeared are added, files that disappeared are removed, everything else in the file is left exactly as it was.kglob --check [PATH]reports drift and exits with status 1 without writing anything, for CI or a pre-commit hook.- A
kustomization.yamlwith no marker is left alone. This is not an error when scanning a directory: most kustomizations do not usekglob.
As a pre-commit hook:
- repo: local
hooks:
- id: kglob-check
name: kglob --check
entry: kglob --check
language: system
pass_filenames: false
What the marker means, and what it does not
The pattern is resolved relative to the directory the kustomization.yaml lives in, with the usual glob rules (*, **, ?). Only .yaml and .yml files are considered, hidden files and directories are skipped, and the kustomization.yaml file itself is never added to its own list.
kglob only writes explicit file names into resources:. It never runs kustomize build, never loads a plugin, never talks to a cluster, and never expands anything at build time: that is the one thing Kustomize's own maintainers have said, in writing, they will not add, and kglob does not try to be the exception. What it does is exactly what kustomize edit add resource 'dir/*.yaml' already does for additions, extended to also drop files that disappeared, which is the part no existing Kustomize command does today.
How it edits the file
kglob does not parse the file as YAML. It only recognises the exact block it owns: a resources: key, a # kglob: <pattern> comment directly under it, and the plain - path lines that follow. It reads and rewrites only those lines and copies every other byte of the file through unchanged, so anchors, aliases, multiple documents, comments and formatting anywhere else in the file cannot be broken by this tool.
If an existing line under the marker is not a plain path (for example a mapping, an anchor or a flow sequence), kglob refuses to touch that file and prints why, rather than guess.
Status
Version 0.1.0, covered by unit tests. Not yet used against a real production kustomization tree by anyone other than me. If you try it, an issue saying what happened is the most useful thing you can send, working or not.
Requirements
Python 3.9 or newer, no third party dependencies.
Where this comes from
kubernetes-sigs/kustomize #3205 and #119 ask for glob support in resources:. Not affiliated with the Kustomize project; "Kustomize" and "kustomization.yaml" are used here only to say what file this tool edits.
Licence
MIT. Written by Younes Z., built with AI assistance, reviewed and tested by me.
Release files for kglob 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| kglob-0.1.0.tar.gz | 8.4 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| kglob-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 16.0 kB
Release files / kglob-0.1.0.tar.gz
| Download URL | kglob-0.1.0.tar.gz |
|---|---|
| Size | 8.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6f0319c4794c556e84395537e567c8b4642f00e9a6a95f88c0365e4476f877c0
|
|
BLAKE2b-256 checksum How to use checksums |
8a765357721710c86f2884761af9e56a94917ed37f646de76eb5147af72ce441
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.12.10 {"installer":{"name":"uv","version":"0.12.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / kglob-0.1.0-py3-none-any.whl
| Download URL | kglob-0.1.0-py3-none-any.whl |
|---|---|
| Size | 7.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b6867f6980e75db7f8c319d9e0ff0c313ea3f1ef230775eed70973c029c7cd2d
|
|
BLAKE2b-256 checksum How to use checksums |
c14831ef4ad07b267a7446fc5aff75b9533be5917aa05ef7cff50a7dc376c2b8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.12.10 {"installer":{"name":"uv","version":"0.12.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|