Skip to content

fix(ci): validate the k8s manifests against a schema in CI #5084

Open

Description

@dan-petty

Update 2026-11-26 (infra move): the environment manifests, such as k8s/llm/gateway-db.yaml, are in dan-petty/homelab, which validates them with kubeconform through the shared k8s-validate.yml of dan-petty/infra. Here the scope is the product manifests of k8s/devops/ only. A skip list for environment kinds is not needed. Consider the infra workflow before new code.


Problem Description

No CI job validates a Kubernetes manifest against a schema. A schema error in a manifest, such as a wrong field of a PodMonitor or a CloudNativePG Cluster, can merge. The evidence of pull request #5048 said that CI runs kubeconform for the new PodMonitor, and the evidence of #5030 said that kubeconform did not run. Their reviews ran kubeconform by hand.

  • The Security Scan step of .github/workflows/ci.yml runs devops scan report. CI does not install kubeconform, so the scan skips it with a warning and does not fail.
  • No file of .github/workflows/ names kubeconform (git grep -n -i kubeconform -- .github/ finds only .github/labels.yml).
  • The k8s row of devops ci (tests/gate/k8s.py, tests/gate/k8s_checks/) renders the kustomizations and checks named fields. It validates no schema.

Reproduction Steps

  1. Open the log of a Static Analysis job on main, for example job 131206020361 of run 43225066588 (2026-11-12).
  2. Search the log for kubeconform.
  3. Run kubeconform -strict -summary k8s/llm/gateway-db.yaml with kubeconform 0.8.0.

Expected vs Actual Behavior

Expected: CI validates each rendered manifest, custom resources included, and a schema error fails a required check.

Actual:

  • Log line 876 of the job: ! Scanner 'kubeconform' was not run (Binary 'kubeconform' not found on PATH). The job passes.
  • Without a schema location for custom resources, kubeconform 0.8.0 gives could not find schema for PodMonitor and could not find schema for Cluster (Errors: 2). The adapter src/devops_cli/security/kubeconform.py passes -strict and no -schema-location. Thus only an install would make the scan fail on each custom resource.
  • With -schema-location default -schema-location 'https://raw.githubusercontent.com/datreeio/CRDs-catalog/main/{{.Group}}/{{.ResourceKind}}_{{.ResourceAPIVersion}}.json', the same file gives Valid: 3, Errors: 0.

Proposed Fix

  • Validate the kustomize renders of the committed applications with kubeconform in a required CI job, with the default schemas and a pinned CRD schema catalog.
  • Install kubeconform in CI with a pinned, checksummed step or a digest-pinned image, as the Run actionlint step does. chore(tools): remove devops install-tools and tools.lock #4363 removes devops install-tools, so do not add a new user of it.
  • Decide for each custom resource with no schema in the catalog: add the schema, or skip the kind with a reason.

Environment Diagnostics

.github/workflows/ci.yml on main, 2026-11-12. kubeconform 0.8.0 (the pin of .devcontainer/Dockerfile).

Acceptance Criteria

  • A required CI check fails on a manifest with a schema error, and a test or a fixture shows it.
  • The CI log shows kubeconform validating the custom resources of k8s/, with no "was not run" line.

Source: #5048

Alternatives check of 2026-11-22: in-use.
The repository already uses this tool.
Tool: yannh/kubeconform (https://github.com/yannh/kubeconform), Apache-2.0, last activity 2026-06-13, maintained.
Reason: Searches found kubeconform, a maintained validator that checks manifests against Kubernetes OpenAPI JSON schemas in strict mode and takes extra schema locations for custom resources; the project already runs it, so the need is CI wiring and pinning.

Covers:

  • Strict schema validation of Kubernetes manifests
  • Configurable remote and local schema locations for CRDs
  • Custom resource validation through a pinned catalog URL
  • JSON, JUnit and TAP output for CI logs

Lacks:

  • No install step in CI; the scan skips a missing binary
  • Does not render kustomizations itself
  • No guideline lint checks; kube-linter holds those
  • No schema for kinds absent from the catalog, such as SeaweedFS CRs

Proposed design

Problem statement

CI does not validate the product Kubernetes manifests in k8s/devops/ against a schema. A wrong field in a product manifest can merge. The Security Scan skips kubeconform when the binary is absent. The k8s row renders the manifests but checks no schema.

Acceptance criteria

Requirement: Kubeconform validates each product render

The k8s row of devops ci SHALL validate each rendered product manifest with kubeconform in strict mode.

Scenario: A schema error fails the k8s row

  • WHEN A rendered fixture manifest has a field that the kubeconform test double rejects as a schema error.
  • THEN The k8s row exits non-zero and prints the kubeconform error for the fixture manifest.

Requirement: The k8s row validates the render, not the source

The k8s row SHALL pass the kustomize render output to kubeconform and SHALL NOT pass a kustomization.yaml file.

Scenario: The source kustomization is not a resource

  • WHEN The k8s row validates a product kustomization that has a kustomization.yaml file.
  • THEN The kubeconform command receives the render output and no kustomization.yaml path.

Requirement: The runner accepts schema locations

The kubeconform runner in src/devops_cli/security/kubeconform.py SHALL accept extra -schema-location values and pass them to kubeconform.

Scenario: The runner passes the default and the pinned catalog

  • WHEN The k8s row calls the runner with -schema-location default and a commit-pinned catalog URL.
  • THEN The kubeconform command contains -strict, -schema-location default and the pinned catalog URL.

Requirement: The CRD catalog is pinned

The k8s row SHALL pin the datreeio CRDs-catalog schema location to a commit SHA.

Scenario: The catalog URL is pinned

  • WHEN A test calls the kubeconform command builder of the k8s row.
  • THEN The catalog URL contains a 40-character commit SHA and does not use the main branch.

Requirement: An unknown custom resource fails

The k8s row MUST fail on a custom resource whose schema is absent, unless k8s/kubeconform-skip.yaml names its kind and reason.

Scenario: An unlisted kind fails

  • WHEN A rendered fixture has a custom resource kind that the catalog and skip file do not name.
  • THEN The k8s row exits non-zero and prints the missing schema for that kind.

Requirement: A listed kind passes with its reason

The k8s row SHALL skip a missing schema only for a kind that k8s/kubeconform-skip.yaml names with a non-empty reason.

Scenario: A listed kind passes

  • WHEN A rendered fixture has a custom resource kind that the skip file names with a reason.
  • THEN The k8s row passes and prints the recorded reason for the skipped kind.

Requirement: The static job installs kubeconform

The Static Analysis job MUST put kubeconform 0.8.0 on PATH from the pinned devtools image and MUST NOT call devops install-tools.

Scenario: The static job installs kubeconform

  • WHEN The Static Analysis job runs on a pull request.
  • THEN The job log shows the devtools-commands step copied kubeconform and the k8s row finds it on PATH.

Requirement: The static job runs the k8s validation

The kubeconform validation SHALL run inside the Static Analysis job that the repository ruleset requires.

Scenario: The static job runs the k8s row

  • WHEN The Static Analysis job runs uv run devops ci --check --no-cache --skip test,outdated,actionlint.
  • THEN The k8s row runs kubeconform and the job fails on a schema error.

Requirement: The Security Scan skips kubeconform

The Security Scan step of the Static Analysis job SHALL skip the kubeconform scanner because the k8s row validates the rendered manifests.

Scenario: The Security Scan skips kubeconform

  • WHEN The Static Analysis job runs uv run devops scan report --sarif .data/scan.sarif --skip bandit,trivy,kubelinter,kubeconform.
  • THEN The scan passes and its log has no Scanner 'kubeconform' line.

Requirement: A missing kubeconform fails the k8s row

The k8s row MUST fail when kubeconform is not on PATH.

Scenario: Missing binary

  • WHEN The k8s row runs with no kubeconform on PATH.
  • THEN The row exits non-zero and prints that kubeconform is required.

Existing Tool Considered

The alternatives block in the issue body records the verdict in-use for yannh/kubeconform. The block lists what the tool covers and lacks. This change adds the missing CI install. It feeds the kustomize render to the tool with a commit-pinned datreeio/CRDs-catalog schema location. It adds a reasoned skip only for a product custom resource that the catalog lacks. The Security Scan skips kubeconform because the k8s row owns schema validation.

Key questions

  • Which manifests does this issue validate?: The product manifests of k8s/devops/ only. The environment tree, such as k8s/llm/gateway-db.yaml, lives in dan-petty/homelab and is out of scope. [sources: CONTEXT.md, .github/workflows/ci.yml]
  • Which inputs does the schema validation check?: The kustomize renders of the product base k8s/devops/. The k8s row writes the renders once and passes them to kubeconform. It does not pass the source directory. (best practice) [sources: tests/gate/k8s.py, .github/workflows/ci.yml]
    • Rejected: Raw YAML files under k8s/devops/. It misses generated manifests and duplicates the render logic.
    • Chosen: Kustomize renders. It reuses the existing render and catches generated manifests.
    • Rejected: kubectl apply --dry-run=server. It needs a live cluster and cannot run in the static job.
  • Which required CI check carries the schema validation?: The existing Static Analysis job, through the k8s row of devops ci. (best practice) [sources: .github/workflows/ci.yml, docs/adr/0004-ci-is-the-authoritative-gate.md, tests/gate/k8s.py]
    • Rejected: A new required job. It needs a ruleset change and a second render.
    • Chosen: The Static Analysis job. The ruleset already requires it and it runs the k8s row.
  • How does CI install kubeconform?: Add kubeconform to the commands list of the existing devtools-commands step in the static job. The devtools image pins kubeconform 0.8.0. Do not add a devops install-tools user. (best practice) [sources: .github/workflows/ci.yml, src/devops_cli/security/kubeconform.py]
    • Chosen: Copy from the devtools image. It uses the existing pinned image and PATH step.
    • Rejected: Download the release with a checksum. It adds a new supply-chain step and a checksum to keep.
    • Rejected: Run a digest-pinned docker:// action. It cannot put the binary on PATH for the k8s row.
    • Rejected: devops install-tools. chore(tools): remove devops install-tools and tools.lock #4363 removes it and the body forbids a new user.
  • Which schema locations does kubeconform use?: -schema-location default plus a commit-pinned datreeio/CRDs-catalog URL for custom resources. (best practice) [sources: src/devops_cli/security/kubeconform.py]
    • Rejected: Default schemas only. Custom resources have no default schema.
    • Chosen: Default plus the pinned CRD catalog. It validates custom resources with a fixed schema source.
    • Rejected: Vendor every CRD schema. It adds a maintenance burden that the catalog avoids.
  • What does the k8s row do for a custom resource with no schema?: It fails unless k8s/kubeconform-skip.yaml names the kind and a non-empty reason. Add an entry only for a product custom resource that the pinned catalog lacks. The environment kinds are out of scope. (best practice) [sources: src/devops_cli/security/kubeconform.py, tests/gate/k8s.py, CONTEXT.md]
    • Chosen: Fail with a reasoned skip file. It keeps the check strict and records each exception.
    • Rejected: Skip the kind silently. It hides a schema error.
    • Rejected: Write a local schema for every kind. It adds a large maintenance cost for kinds that the catalog does not cover.
    • Rejected: Pass -ignore-missing-schemas. It skips every unknown kind with no reason.
  • What does the Security Scan do with kubeconform?: The Security Scan skips the kubeconform scanner. The k8s row validates the rendered manifests. The scan adapter has no schema location and would fail on custom resources. (best practice) [sources: .github/workflows/ci.yml, src/devops_cli/security/kubeconform.py, src/devops_cli/security/registry.py]
    • Chosen: Skip kubeconform in the Security Scan. The k8s row owns schema validation and the scan adapter has no schema location.
    • Rejected: Give the scan the pinned catalog. It scans raw files and duplicates the render.
    • Rejected: Leave the scan as it is. The binary on PATH makes the scan fail on custom resources.
  • Does the k8s row reuse the kubeconform runner?: Yes. Extend src/devops_cli/security/kubeconform.py to accept extra schema locations. The k8s row uses the runner and applies the skip file to missing-schema errors. (best practice) [sources: src/devops_cli/security/kubeconform.py, tests/security/test_security_kubeconform.py, tests/gate/k8s.py]
    • Chosen: Extend the existing runner. It keeps one strict-mode invocation path and its tests.
    • Rejected: Add a new runner. It duplicates the existing adapter.
  • Does this issue include the kube-linter checks?: No. The kube-linter row of ci(k8s): Run kube-linter on the rendered manifests in CI #6068 takes the guideline checks. This issue keeps kubeconform only. (best practice) [sources: src/devops_cli/security/kubelinter.py, tests/gate/k8s.py, .github/workflows/ci.yml]

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Activity

  1. added
    source/agent
    type/bug
    scope/ci
    status/new
    value/medium
    effort/medium
    on Nov 12, 2026
  2. dan-petty commented on Nov 12, 2026

    @dan-petty
    OwnerAuthor
  3. added
    priority/p2-medium
    on Nov 12, 2026
  4. dan-petty commented on Nov 13, 2026

    @dan-petty
    OwnerAuthor

    Scope from the spec split (2026-11-13)

    Also run kube-linter in the same CI job, on the same full render as kubeconform. Give it a committed .kube-linter.yaml that turns on the checks that docs/guidelines/kubernetes.md names (the amendment of PR #5492), such as unset-memory-requirements, unset-cpu-requirements, no-liveness-probe and no-readiness-probe.

    Reason: the owner directions of 2026-11-13 remove the hand counts from the specs. Two drafts counted the containers with no memory limit as 13 of 52 and as 25 of 115, with different scopes. One kube-linter run on the full render gives one count at each CI run, and the guideline names the check id in place of a number. src/devops_cli/security/kubelinter.py already runs kube-linter for the review, so reuse its runner and its report model.

  5. devops-cli-service commented on Nov 15, 2026

    @devops-cli-service
    Contributor

    Alternatives check: in-use

    Reason: kubeconform is the maintained, open tool that validates rendered Kubernetes YAML against JSON schemas, and the issue's own evidence shows that with -schema-location default plus the datreeio CRDs-catalog it validates the PodMonitor and CloudNativePG Cluster of k8s/llm/gateway-db.yaml with 0 errors, so it covers the schema-validation need in full; it only has to be installed in CI. The project already ships a kubeconform scanner (src/devops_cli/security/kubeconform.py, pinned in .devcontainer/Dockerfile), so the tool is already in use and only the CI wiring is missing.

    The repository already uses this tool.

    Tool: yannh/kubeconform (https://github.com/yannh/kubeconform)

    • License: Apache-2.0
    • Last activity: 2026-06-13
    • Maintained: yes

    Covers:

    • Validates rendered Kubernetes manifests against the upstream JSON schemas with -strict and returns a non-zero exit code on a schema error
    • Accepts extra -schema-location entries, so a pinned CRD catalog (datreeio CRDs-catalog) validates custom resources such as PodMonitor and CloudNativePG Cluster
    • Runs on the output of the kustomize renders of the committed applications, so one invocation covers every manifest the issue names
    • Reports a summary (Valid/Invalid/Errors) that a required CI check can fail on and log

    Lacks:

    • Does not install itself in CI: the job needs a pinned, checksummed install step or a digest-pinned image
    • Does not render the kustomizations; the render step of devops ci k8s must feed it the manifests
    • Does not cover the kube-linter checks the reply asks for (unset-memory-requirements, unset-cpu-requirements, no-liveness-probe, no-readiness-probe)
    • Custom resource kinds with no schema in the catalog still need a schema added or a reasoned skip

    Tools considered:

    Searches run:

    • kube-linter lint Kubernetes YAML checks unset-memory-requirements, results: 5
    • kubeconform validate Kubernetes manifests against schema CRD catalog, results: 5
    • stackrox/kube-linter GitHub, results: 5
    • yannh/kubeconform GitHub, results: 5
    • datreeio CRDs-catalog schema location kubeconform PodMonitor, results: 5

    Sources:

    Checked on 2026-11-15. A person decides what this means for the item. The check changes no label and closes no issue.

  6. added
    status/ready
    and removed
    status/new
    on Nov 17, 2026
  7. devops-cli-service commented on Nov 17, 2026

    @devops-cli-service
    Contributor

    Status set to Ready at 19bfec3 (see proposed design in issue body).

  8. dan-petty commented on Nov 17, 2026

    @dan-petty
    OwnerAuthor

    Pull request #6112 (for #6068) takes the kube-linter part of the scope comment of 2026-11-13. The kube-linter row of devops ci lints the build of each path source of the Argo CD Applications with .kube-linter.yaml. This item keeps kubeconform. write_path_renders of src/devops_cli/k8s/app_render.py writes the builds to one folder, so kubeconform can read the same builds. The Helm chart sources are #6106.

  9. dan-petty commented on Nov 19, 2026

    @dan-petty
    OwnerAuthor

    Evidence from #6439 (2026-11-19). uv run devops k8s validate k8s/llm/gateway gives two HIGH findings, on origin/main (fda0478) and on the #6439 branch alike:

    • kustomization.yaml: Kubeconform statusError, "Kustomization '' could not be validated". The command validates the files of the directory, not the kustomize render, so it reads kustomization.yaml as a resource.
    • servicemonitor.yaml: Kubeconform statusError, "ServiceMonitor 'llm-gateway' could not be validated". No schema location gives the monitoring.coreos.com CRD.

    The design of this issue (validate the kustomize render, with a pinned CRD catalog) removes both. #6439 does not change them.

  10. dan-petty commented on Nov 22, 2026

    @dan-petty
    OwnerAuthor

    More evidence from #4756 (PR #6724): uv run devops k8s validate k8s/object-store reports Kubeconform statusError ... could not be validated for each SeaweedFS operator CR (Seaweed on main, and the 18 new Bucket, BucketLifecyclePolicy, S3Identity, S3Policy, S3PolicyBinding, S3Credentials and ResourceReferenceGrant CRs), because kubeconform has no schema for their kinds. On 2026-11-22 the 18 CRs passed kubectl apply --dry-run=server against the live CRDs of chart 0.1.48, but no CI job checks them.

  11. devops-cli-service commented on Nov 26, 2026

    @devops-cli-service
    Contributor

    Next step: the stage job writes the plan of the item. See the section Proposed design of the body.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    effort/mediumpriority/p2-mediumscope/cisource/agentstatus/readytype/bugvalue/medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions