Skip to content

feat: validate only gitops instances affected by the changed files - #88

Draft
leo-dur wants to merge 6 commits into
mainfrom
feat/gitops-values-validation-changed-files
Draft

leo-dur wants to merge 6 commits into
mainfrom
feat/gitops-values-validation-changed-files

Conversation

@leo-dur

@leo-dur leo-dur commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Context

gitops-values-validation validated every instance of the gitops repository on each commit (226 instances in cargo-gitops, even for a README-only commit).

The goal is to make pre-commit faster on gitops repositories with many services, by only validating what a commit actually touches.

Changes

  • Changed files only: the hook passes the changed files (--changed-files) and only validates the instances depending on them (Chart.yaml, Chart-<env>.yaml, values.yaml, values-<env>.yaml, values-<env>-<instance>.yaml). Repository-level checks (unique service names) still always run, and --all-files (CI) still validates everything.
  • Deleted and renamed files: pre-commit never passes deleted files to hooks, and its maintainer declined to add it (Detect deleted files pre-commit/pre-commit#749, #3048, #3502, #3713). prek has include_deleted, but pre-commit warns about the unknown key. So the script lists the staged deletions itself (git diff --staged --no-renames --diff-filter=D), and always_run is kept for deletion-only commits.
  • Dependencies: pyproject.toml is the single source, since pre-commit installs the repository itself; additional_dependencies is removed. requests and urllib3 are bumped (known CVEs), ruamel-yaml (unused) is dropped, and jsonschema stays pinned to 4.19.0 because the ignored-error keys depend on its json_path format. The hook is now a gitops-values-validation console script (PEP 621 metadata).
  • Dev environment and CI: nixpkgs 26.05 with Python 3.14 (aligned with Kpler/cookiecutter-python#50), and a new python-tests CI job on Python 3.10 and 3.14 (pytest never ran in CI). The real schemas are only downloadable through the Twingate VPN, so the tests use a minimal schema holding only the additionalChecks parts; pytest --real-schema runs them against the real schemas locally.
  • Docs: README section for the hook and the dev setup.

Tests

  • 34 unit tests, including deletion, rename and main() wiring.

  • pre-commit try-repo (4.6.2) and prek try-repo (0.5.4) on cargo-gitops (the rename case with pre-commit only):

    Commit Instances validated
    README only 0
    one instance file changed 1
    values-dev.yaml deleted 1
    values-dev.yaml moved out of its service 1
    --all-files 226
  • Validating all of cargo-gitops gives identical output with the old and new dependencies.

Performance

pre-commit run gitops-values-validation on cargo-gitops (60 services, 226 instances), main vs this branch, installed hook environments and warm schema cache, median of 5 runs:

Staged change Before After
values.yaml of a 2-instance service (typical) 8.7 s (226 instances) 1.3 s (2 instances)
values.yaml of the largest service, staticdata-sync 8.3 s (226 instances) 2.0 s (18 instances)
README only 9.2 s (226 instances) 1.2 s (0 instance)

The remaining ~1.1 s is mostly the pre-commit startup and the repository-level checks.

Notes

  • The hook now requires Python 3.10+ (required by the bumped dependencies).

gitops-values-validation used to validate every instance of the repository
on each commit (always_run + pass_filenames: false). The hook now passes the
changed files with --changed-files and only the instances depending on them
(Chart.yaml, Chart-<env>.yaml, values.yaml, values-<env>.yaml,
values-<env>-<instance>.yaml) are validated.

pre-commit never passes deleted files to hooks, and its maintainer has
repeatedly declined to add an option for it (pre-commit/pre-commit#749,
#3048, #3502, #3713). prek has one (include_deleted, since 0.5.4), but
pre-commit warns about this unknown key on every run, so it is not used.
Instead, the script adds the staged deleted files itself, and always_run is
kept so that commits only deleting files are still checked.

Repository-level constraints are always checked and --all-files still
validates every instance.
- requests 2.31.0 -> 2.34.2 and urllib3 1.26.15 -> 2.8.0 (known CVEs fixed),
  urllib3 2 has no `secure` extra anymore
- pyyaml 6.0.3, termcolor 3.3.0, semver 3.1.0
- drop ruamel-yaml, which is not used
- keep jsonschema pinned to 4.19.0, as IGNORED_VALIDATION_ERRORS keys depend
  on its json_path format (cf 6da8ace)

pyproject.toml is aligned on the same pinned versions (the lock had drifted
to jsonschema 4.23.0) and the lock is regenerated, which notably bumps
rpds-py to a version installable on recent Python versions.

Validation of the whole cargo-gitops repository gives the same result with
the old and new dependencies.
@leo-dur leo-dur self-assigned this Oct 1, 2026
@leo-dur
leo-dur force-pushed the feat/gitops-values-validation-changed-files branch from 197ab13 to 3caa2f4 Compare October 1, 2026 17:20
pytest never ran in CI.

The JSON schemas of the platform-managed-chart are only downloadable
through the Twingate VPN, which a public repository cannot use in CI
(Kpler/github-actions is internal). The tests now use a minimal schema,
holding only the parts of the real schema that carry the additionalChecks
(service name, service keys, topic names and maxLocalTopicBytes), instead
of downloading the real ones. The --real-schema pytest option downloads
the real schemas instead, to check the rules against them locally.

Tests run on Python 3.10, the oldest supported version, and 3.14, the
version of the nix shell.
pre-commit installs the hooks repository itself (pip install .), so the
dependencies declared in pyproject.toml are already installed in the hook
environment: additional_dependencies was a second list to keep aligned
(and was not, e.g. urllib3[secure]<2 vs urllib3==1.26.15). It is removed,
pyproject.toml is the single source of the dependencies.

The hook now calls a gitops-values-validation console script instead of
python -m. The package metadata moves to the PEP 621 [project] table, as
console scripts in [tool.poetry.scripts] are deprecated with Poetry 2.
@leo-dur
leo-dur force-pushed the feat/gitops-values-validation-changed-files branch from 8c5d9db to 434a236 Compare October 1, 2026 17:26
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