kubernetes-crd-storage-version-audit
Audit Kubernetes CustomResourceDefinition storage version changes read-only against saved status.storedVersions, served flags, conversion webhooks, and safe migration steps.
Try your first task
A source-grounded starter task has not been verified for this skill yet.
SKILL.md
name: kubernetes-crd-storage-version-auditdescription: "Audit Kubernetes CustomResourceDefinition storage version changes read-only against saved status.storedVersions, served flags, conversion webhooks, and safe migration steps."category: devopsrisk: safesource: selfsource_type: selfdate_added: "2026-12-01"author: Koushik-Katkamtags: [kubernetes, crd, storage-version, migration, validation, audit]Kubernetes CRD Storage Version Audit
Overview
Perform a strictly read-only pre-flight audit comparing a saved current Kubernetes CustomResourceDefinition (apiextensions.k8s.io/v1) YAML manifest against a proposed replacement CRD manifest before changing served/storage versions or removing an old API version.
Distinction from existing Kubernetes skills:
kubernetes-ops: covers live cluster workload deployments, scaling, Services, andkubectloperations rather than offline CRDstorage/storedVersionsschema transitions.kubernetes-deployment: orchestrates application rollout workflows (container build, Helm, mesh) without validating CRD version removal preconditions.helm-chart-scaffolding: packages Helm charts and templates rather than auditing saved CRD status against replacementspec.versions.gitops-workflow: manages ArgoCD/Flux continuous reconciliation rather than checking CRD conversion strategy andstatus.storedVersionsmigration blockers.
When to Use
- Before removing a deprecated version (such as
v1beta1) from a Kubernetes CRD'sspec.versions. - Before switching
storage: truefrom one CRD API version to another. - When reviewing whether a proposed CRD change requires a
Webhookconversion strategy andconversionReviewVersions. - Do not use this skill to patch live cluster CRDs, rewrite etcd objects, edit
status.storedVersionsdirectly, or delete CRDs in a cluster.
Prerequisites
- Python
3.10+with pinned test/YAML dependencies (tested with Python3.12.10,PyYAML==6.0.3,pytest==9.1.1). - A saved current CRD YAML export (including
status.storedVersions) and the proposed replacement CRD YAML manifest. - No live Kubernetes cluster access, kubeconfig, or cluster write permissions required.
How It Works
1. Validate inputs and CRD API version bounds
- Parse both YAML files strictly with
yaml.safe_loadand reject multi-document streams or non-mapping documents asINVALID_INPUT. - Require
kind: CustomResourceDefinition, validatemetadata,spec,spec.names, andstatus(when present) as mappings before accessing fields, and reject legacyapiextensions.k8s.io/v1beta1CRDs asUNSUPPORTEDrather than applyingv1field assumptions. - Require identical
(metadata.name, spec.group, spec.names.plural, spec.scope)CRD identity between current and proposed manifests.
2. Audit version flags, storedVersions, and conversion strategy
Run the local verification suite in CRD storage version audit harness:
- Single storage version rule: Verify both current and proposed CRDs have exact count = 1 entry with
storage: trueand valid booleanserved/storagefields across allspec.versions. - Stored versions vs. proposed & current specs: Check all entries in current
status.storedVersionsagainst bothcurrent.spec.versionsandproposed.spec.versions(not merely the removed-version set), and verify currentstorage: trueappears instatus.storedVersions. Any stored version absent fromproposed.spec.versions(REMOVED_STORED_VERSIONorORPHANED_STORED_VERSION), absent fromcurrent.spec.versions(STORED_VERSION_NOT_IN_CURRENT_SPEC), or missing the current storage version (INCONSISTENT_CURRENT_STORAGE_EVIDENCE) must FAIL. - Missing or stale status handling:
- Missing, non-list, or empty
status.storedVersionsin the current CRD producesMISSING_STATUS_EVIDENCE(FAILunder strict audit), never an assumption that zero stored versions exist. - Even when
status.storedVersionslists only the new storage version, explicitly record a stale-status caveat: a saved static status snapshot cannot prove every custom resource object across namespaces was rewritten at the new version without cluster-side object/StorageVersion verification.
- Missing, non-list, or empty
- Served vs. storage semantics & conversion prerequisites:
- Setting an old version to
served: false, storage: falsewhile retaining it inspec.versionsis allowed as an intermediate deprecation stage while storage migration completes. - Whenever
conversion.strategy: Webhookis configured (regardless ofspec.versionscount), require aconversion.webhookmapping with a validclientConfigmatchingWebhookClientConfig(exactly one ofserviceorurl, never both or neither:servicerequires non-emptynameandnamespace, optional integerportin1..65535, and optionalpathstarting with/;urlrequires a well-formedhttps://URL with host and no whitespace/control characters, rejectinghttp://, malformed URLs, user information, query parameters, and fragments) — emitting an additionalUNNECESSARY_WEBHOOKwarning if only one version remains. - Distinguish Kubernetes API-server requirements (where
apiextensions.k8s.io/v1permitsconversionReviewVersionswith"v1"or"v1beta1") from this harness's stricter modernv1ConversionReviewpolicy, first validating thatconversion.webhook.conversionReviewVersionsis a non-empty list where every element is a non-empty string before requiring"v1". Flagstrategy: Noneacross multi-version schema changes as an explicit warning/review gate.
- Setting an old version to
3. Emit safe migration sequencing
Report the ordered Kubernetes CRD storage migration sequence whenever an old version remains in status.storedVersions:
- Add the new version (
served: true, storage: false) and deploy conversion webhook if schemas differ. - Promote the new version to
storage: true(demoting old version tostorage: false, optionallyserved: false). - Re-read and re-write all existing custom resources at the new storage version (e.g., Storage Version Migrator or authorized controller).
- Verify live cluster objects are migrated and reconcile
status.storedVersionsbefore removing the old version fromspec.versions.
Examples
Run the self-contained verification suite in CRD storage version audit harness:
User request: "Can we safely drop v1beta1 from our Widget CRD manifest in this release PR?"
Inputs: Saved current Widget CRD YAML (with status.storedVersions) and proposed v1-only Widget CRD YAML.
Expected result: PASS with stale-status caveat when status.storedVersions == ["v1"] and proposed v1 has storage: true;
FAIL with REMOVED_STORED_VERSION when v1beta1 remains in status.storedVersions; FAIL on 0 or >1 storage versions
or incomplete Webhook conversion config.
Limitations
- Read-only manifest analysis checks a saved YAML export only;
status.storedVersionsin a snapshot can be stale relative to live etcd objects or pending StorageVersion migrations. - Passing this check does not validate OpenAPI v3 structural schema field compatibility across versions or test live webhook TLS connectivity/runtime behavior.
- Does not inspect live
StorageVersion(internal.apiserver.k8s.io/v1alpha1) resources or cluster admission webhooks.
Safety and Side Effects
- Strictly offline and read-only (
yaml.safe_loadonly — neveryaml.load/ arbitrary Python tag execution). - Never executes
kubectl apply,kubectl patch,kubectl delete crd, or status subresource writes.