#9260·velero

Add CRD version compatibility validation during server startup

Author: shubham-pampattiwarCreated Sep 12, 2025Updated Sep 22, 2026
LabelsEnhancement/UserfeatureNeeds DesignReviewed Q3 2025

Status (as of 2026-09-21)

Design: #10010 (design doc: design/crd-schema-validation_design.md) — approved Implementation: #9910

Covered by #9910 (base feature)

  • Schema property validation: reflects on Go API types (velerov1api.CustomResources() / velerov2alpha1api.CustomResources()) to derive expected spec/status JSON field names, compares against installed CRDs' openAPIV3Schema.properties.
  • --crd-schema-check server flag (warn default / strict / skip), backed by a validated enum flag (invalid values rejected at parse time).
  • Missing-field detection only (CRD having extra fields vs. the server is intentionally not flagged — see follow-up below).
  • warn mode runs asynchronously (background goroutine) and strict mode synchronously, both bound by context.WithTimeout(s.ctx, s.config.ResourceTimeout) — cancels on server shutdown, self-terminates against an unresponsive API server, and warn mode never gates startup on the result.
  • Unit tests (pkg/cmd/server/crd_check_test.go) + kind e2e coverage (test/e2e/basic/crd-schema-check/) across warn/strict/skip modes.

Deferred — follow-up issues opened

The design doc goes further than #9910 implements in a few places, by design (kept the base PR reviewable/focused). Tracked separately:

  • #10544 — Self-resolution for strict mode: /readyz endpoint + non-crashing block, instead of today's crash-loop (os.Exit(1) on mismatch).
  • #10546 — Design follow-up: detect/handle the CRD-ahead-of-server (extra field) case, explicitly out of scope for the base feature.
  • #10547 — Unify veleroResourcesExist()'s missing-CRD crash path into this same validation framework.
  • vmware-tanzu/helm-charts#750 — cross-repo: the Helm chart's existing readinessProbe (aimed at /metrics) needs retargeting to /readyz once #10544 lands, or it'll mask the not-ready state.

#10545 — non-blocking warn mode + shared timeout — closed, completed. Initially closed not-planned (no other server.go startup check has a per-call timeout either), but design PR review (sseago, shubham-pampattiwar) independently raised the same concern for this specific check, so it was implemented directly in #9910: the warn-mode goroutine is now bound by context.WithTimeout(s.ctx, s.config.ResourceTimeout), same as strict mode's synchronous pass, without gating startup on it.

Open questions (not yet actionable issues — design doc's own Open Issues section)

  • Should strict become the default in a future major version, once the check has proven reliable?
  • Should the aggregated warning also be surfaced as a Kubernetes Event on the Velero deployment/pod, in addition to server logs?

Describe the problem/challenge you have

Add validation to ensure Velero server only starts with compatible CRD versions.

Describe the solution you'd like

Currently, Velero servers can start with CRDs from different versions, which may lead to:

  • Incompatible schema expectations
  • Runtime errors during backup/restore operations
  • Difficult-to-debug compatibility issues
  • Silent failures when CRD features don't match server expectations

CRD Version Identification Methods

Several approaches could work:

  1. Controller-gen annotation: Use existing controller-gen.kubebuilder.io/version annotation — ⚠️ insufficient per comment, CRD changes can happen without upgrading controller-gen
  2. Velero version label: Add app.kubernetes.io/version label to CRDs during generation
  3. Schema hash validation: Compare expected schema signatures with installed CRDs
  4. Resource version tracking: Maintain compatibility matrix in server code

Current Behavior:

  • Server startup validation in veleroResourcesExist() only checks if CRDs exist and have correct API group versions
  • Server will start successfully with CRDs from any Velero version (e.g., v1.15.x CRDs with v1.16.x server)
  • No warning or error when CRD schema versions don't match server expectations

Desired Behavior:

  • Server should validate that installed CRDs match the server version during startup
  • Server should fail to start with clear error message if CRD versions are incompatible
  • Users should be prompted to update CRDs to match server version (via velero install --crds-only, see #9132)

Proposed Implementation Options

Option 1: Server-side validation

  • Enhance veleroResourcesExist() to validate CRD versions
  • Add version compatibility check during server startup

Option 2: Pod spec-based validation

  • Init container: Validate CRDs before main container starts
  • Readiness probe: Continuously validate CRD compatibility
  • Startup probe: Ensure CRD validation passes before server becomes ready

Option 3: Admission control

  • ValidatingAdmissionWebhook that prevents incompatible deployments

Implementation Considerations

  • Should validation be strict (fail) or permissive (warn) by default?
  • How to handle patch version differences (v1.16.1 vs v1.16.2)?
  • Should validation be configurable via flag/environment variable?
  • Backward compatibility with existing deployments

Implementation Plan

Chosen approach: Schema property validation (Option 1 + method 3)

Based on discussion in comments, schema-based validation is preferred over version labels because:

  • CRD changes can happen without controller-gen upgrades (comment)
  • Avoids unnecessary CRD updates for patch releases with no schema changes (comment)
  • Already prototyped: go-playground PoC
  • No additional RBAC needed — Velero already has CRD Get permissions (comment)

Step 1: Define expected schema properties per CRD

In a new file pkg/cmd/server/crd_check.go:

  • For each Velero CRD kind (Backup, Restore, Schedule, etc.), define the set of top-level spec and status properties the server expects
  • Derive these from the Go API types at compile time (reflect or code generation), or maintain a static map that make verify validates against API types
  • Static map is simpler and sufficient — the set only changes when API types change, and make verify catches drift

Step 2: Fetch installed CRDs and validate schema

Add a validateCRDSchemas() method on server struct:

  1. Use the API server client to Get each Velero CRD object (e.g., backups.velero.io)
  2. Extract the OpenAPI v3 schema from spec.versions[].schema.openAPIV3Schema.properties.spec.properties
  3. Compare installed property keys against expected property set
  4. Report missing properties (server expects field that CRD doesn't have = outdated CRD)
  5. Extra properties in CRD are OK (forward-compatible, e.g. CRD is newer than server)

Step 3: Integrate into server startup

In pkg/cmd/server/server.go, call validateCRDSchemas() right after veleroResourcesExist() succeeds (~line 359):

  • Default behavior: warn — log error-level message with specific missing fields and suggest velero install --crds-only (from merged PR #9132)
  • Configurable via server flag — add --crd-schema-check to pkg/cmd/server/config/ with values: warn (default), strict (fatal), skip
  • On strict: return error, preventing server startup
  • On skip: no check performed

Step 4: Tests

In pkg/cmd/server/crd_check_test.go:

  • Test with matching schema → no error
  • Test with missing spec properties → appropriate warning/error
  • Test with extra properties (newer CRD) → no error
  • Test with empty/missing CRD schema → error
  • Test each config mode (warn/strict/skip)

Step 5: Documentation

  • Update site/content/docs/main/upgrading.md with CRD validation behavior
  • Add troubleshooting entry for the new error message

Files to change

File Change
pkg/cmd/server/crd_check.go New — expected schema map + validateCRDSchemas()
pkg/cmd/server/crd_check_test.go New — tests
pkg/cmd/server/server.go Call validateCRDSchemas() after veleroResourcesExist()
pkg/cmd/server/config/config.go Add --crd-schema-check flag

Estimated complexity

~200-300 lines of Go (implementation + tests). Medium-low difficulty. Main risk is keeping the expected schema map in sync with API types — make verify check mitigates this.

Anything else you would like to add:

Environment:

  • Velero version (use velero version):
  • Kubernetes version (use kubectl version):
  • Kubernetes installer & version:
  • Cloud provider or hardware configuration:
  • OS (e.g. from /etc/os-release):

Vote on this issue!

This is an invitation to the Velero community to vote on issues, you can see the project's top voted issues listed here. Use the "reaction smiley face" up to the right of this comment to vote.

  • :+1: for "The project would be better with this feature added"
  • :-1: for "This feature will not enhance the project in a meaningful way"

[!Note] Responses generated with Claude