feat: add schema caching and local schema directory#13
Draft
nwaller-nesto wants to merge 2 commits into
Draft
Conversation
- 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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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-diris set,--cache-dirhas no effect (local file reads don't require a cache).Why
By default, testchart downloads schemas from
raw.githubusercontent.comon 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-diraddresses the common case by persisting downloaded schemas locally. After a warm cache, schema validation adds only a few milliseconds.--schema-diraddresses environments where HTTP access to GitHub is unavailable or undesirable, or where a fully offline/deterministic run is required.How
buildSchemaLocations()constructs afile://URL template for kubeconform when--schema-diris provided, using the same{{ .NormalizedKubernetesVersion }}-standalone{{ .StrictSuffix }}/{{ .ResourceKind }}{{ .KindSuffix }}.jsonpath convention that kubeconform already expects from yannh/kubernetes-json-schema.--cache-diris passed through tovalidator.Opts.Cache(kubeconform's built-in on-disk cache), with the cache directory created automatically on first use.niltovalidator.Newwhen--schema-diris unset preserves the existing default behaviour exactly.