Skip to content

feat: add schema caching and local schema directory#13

Draft
nwaller-nesto wants to merge 2 commits into
silphid:masterfrom
nwaller-nesto:feat/schema-caching
Draft

feat: add schema caching and local schema directory#13
nwaller-nesto wants to merge 2 commits into
silphid:masterfrom
nwaller-nesto:feat/schema-caching

Conversation

@nwaller-nesto

Copy link
Copy Markdown

What

Two new optional flags for controlling how kubeconform downloads and resolves Kubernetes JSON schemas:

  • --cache-dir — caches schemas on disk between runs. Defaults to $XDG_CACHE_HOME/testchart (or ~/.cache/testchart). Set to an empty string to disable.
  • --schema-dir — points at a local checkout of yannh/kubernetes-json-schema, eliminating all HTTP traffic for standard Kubernetes schema resolution.

When --schema-dir is set, --cache-dir has no effect (local file reads don't require a cache).

Why

By default, testchart downloads schemas from raw.githubusercontent.com on every run. This works well in most cases, but creates an unnecessary network round-trip on each invocation, and makes runs sensitive to network availability and rate limits.

--cache-dir addresses the common case by persisting downloaded schemas locally. After a warm cache, schema validation adds only a few milliseconds.

--schema-dir addresses environments where HTTP access to GitHub is unavailable or undesirable, or where a fully offline/deterministic run is required.

How

  • buildSchemaLocations() constructs a file:// URL template for kubeconform when --schema-dir is provided, using the same {{ .NormalizedKubernetesVersion }}-standalone{{ .StrictSuffix }}/{{ .ResourceKind }}{{ .KindSuffix }}.json path convention that kubeconform already expects from yannh/kubernetes-json-schema.
  • --cache-dir is passed through to validator.Opts.Cache (kubeconform's built-in on-disk cache), with the cache directory created automatically on first use.
  • Passing nil to validator.New when --schema-dir is unset preserves the existing default behaviour exactly.

nwaller-nesto and others added 2 commits July 8, 2026 17:24
- Add --cache-dir flag (defaults to XDG_CACHE_HOME/testchart or
  ~/.cache/testchart) to cache downloaded schemas on disk across runs.
  This avoids re-downloading the same schemas on every invocation.

- Add --schema-dir flag to point at a local checkout of
  yannh/kubernetes-json-schema, eliminating all HTTP traffic for
  standard Kubernetes schemas.  When set, --cache-dir has no effect
  (local file reads need no cache).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant