3.9 KiB
TODO
Refactor: host-namespace paths everywhere in the file source
What
Move the file source so that the exporter reads, caches, and labels every
on-disk artefact by its host-namespace path (the path the operator
reads kubectl exec-ing into a node, e.g. /var/lib/kubelet/pki/...),
and applies PathMapping.From → To translation uniformly at every
filesystem operation — open, Stat, Lstat, ReadDir, Readlink.
Today (post-symlink-mapping change) the chart writes in-pod paths
into the configmap (/mnt/watch/file-<sha1>/var/lib/kubelet/pki/...),
and PathMapping is consulted only when an absolute symlink target is
read back — i.e. only inside pkg/fileglob.handleSymlink. The
proposal is to flip the polarity: have the chart write raw host paths,
and let the runtime translate transparently for every FS op.
Why we'd want to
-
Drop
trimPathComponents.chart/templates/configmap.yamlcurrently setsmetrics.trimPathComponents: 3for hostPath sources so that/mnt/watch/file-<sha1>/var/lib/kubelet/pki/foo.pemdisplays asvar/lib/kubelet/pki/foo.peminfilepathPrometheus labels. That's a workaround for a label-cosmetics problem that goes away if the runtime knows the host path natively. -
One translation point, not two. Right now
pkg/fileglob.handleSymlinkhas bespoke translation + containment logic. With a universal translator, the same logic covers every code path that touches the FS, so any new FS-using feature is covered for free. -
Operator UX. Labels match what humans type. No mental mapping from
/mnt/watch/file-9dff…/var/lib/kubelet/pki/...back to the real file.
Why this is not done as part of the symlink-mapping change
-
Blast radius. It touches every FS op in
fileglob, not just symlink resolution. The cache key inpkg/source/file/file.gobecomes the host path (today it's the walker'sPath= in-pod), affecting cache invariants and theSkipUnchangedmachinery. -
Public API ripple.
pkg/cert.SourceRef.Locationand the registry'sfilepathlabel semantics change in user-visible ways. Needs a deprecation cycle for downstream consumers reading those labels (Grafana dashboards, alert rules). -
Test churn. Every fileglob/source/file/cmd test that asserts on paths needs to be revisited. Today's symlink-mapping change is surgical; this would be a multi-package rewrite.
-
trimPathComponentsremoval is a chained breaking change. The values key would have to be deprecated separately.
When to revisit
- After the symlink-mapping change has had at least one release in the
wild and we have feedback from real DaemonSet operators about the
shape of
filepathlabels they'd prefer. - When we next plan a
pkg/certAPI revision (anything that already forces consumers to update their dashboards is a natural moment to bundle this in). - If a third concrete need for "exporter knows the host path" surfaces
(e.g. exposing the host path in error messages, in
/healthzdiagnostics, in a future audit trail). Two needs is a coincidence, three is a pattern that justifies the refactor.
Sketch of the change
pkg/fileglob/walkfs.go(new): a smallWalkFSdecorator that takes[]PathMappingand a baseWalkFS, applies the longest-prefixFrom → Torewrite to every method'snameargument, and forwards. The walker becomes oblivious to the translation — it sees host paths everywhere.pkg/source/file/file.go: drop the special-caseif e.LinkTo != "" { readPath = e.LinkTo }(no longer needed —Readerwould also be wrapped to apply the translation).chart/templates/configmap.yaml: write host paths inpaths:andpathMappings:; removemetrics.trimPathComponents:.chart/values.yaml: deprecatemetrics.trimPathComponents(keep for backwards compat for one release, then remove).- Tests: every test that hardcodes
/mnt/watch/file-<sha1>/...flips to host paths.