Skip to content

Strip deprecated CRD descriptions from the Helm chart - #7466

Open
jhrozek wants to merge 2 commits into
stacklok:mainfrom
jhrozek:crd-strip-deprecated-descriptions
Open

jhrozek wants to merge 2 commits into
stacklok:mainfrom
jhrozek:crd-strip-deprecated-descriptions

Conversation

@jhrozek

@jhrozek jhrozek commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Summary

The operator-crds Helm release was at about 97.6% of the 1 MiB limit on the Secret Helm stores each release in (#7456). Any change adding about 25 KB, such as a few new auth fields, breaks helm install and helm upgrade of the chart. Most CRDs serve the deprecated v1alpha1 next to v1beta1 with a full copy of the schema, and the field descriptions are most of that text and compress badly.

  • task operator-manifests still writes the full CRDs to files/crds. The chart templates are now built from a copy in which the schema descriptions are removed from every deprecated version except the preferred one, by a small tool in cmd/thv-operator/crd-strip-descriptions. The preferred version is the served version with the highest version priority: the one API discovery advertises and kubectl explain shows by default.
  • The stored release drops from 1,023,252 bytes (97.6%, measured on a kind cluster) to about 648,000 bytes (61.8%, from the size script).
  • Schemas, validation, CEL rules, defaults and the v1beta1 descriptions are unchanged. That includes MCPRegistry, which is deprecated as a whole kind: its v1beta1 is preferred, so it keeps its docs.
  • files/crds keeps every description, so the release tarball and the API compatibility check are unaffected.
  • A new CI step in the Helm charts workflow fails when the release goes above 90% of the limit.
  • A unit test runs the tool over the real CRDs. With stripping off, the output must be byte-identical to controller-gen's. With stripping on, every non-deprecated version and the preferred version must be unchanged. Fixtures also cover a kind deprecated as a whole and a migration to v1 in which a deprecated v1beta1 is still the storage version. CI's existing templates diff can't catch a lossy tool on its own, because the tool produces both sides of that diff.

Closes #7456

Type of change

  • Bug fix
  • New feature
  • Refactoring (no behavior change)
  • Dependency update
  • Documentation
  • Other (describe):

Test plan

  • Unit tests (task test)

  • E2E tests (task test-e2e)

  • Linting (task lint-fix)

  • Manual testing (describe below)

  • Ran the crd-strip-descriptions package tests with -race, including the new test over the real CRDs, and golangci-lint on that package.

  • Swapped in a storage-version rule instead of the preferred-version rule (through a Go build overlay). The kind-deprecated-as-a-whole and v1 migration cases fail, so the tests tell the two rules apart.

  • Regenerated the templates from files/crds and diffed them against the committed ones: no differences.

  • Rendered the chart before and after with helm template. After removing only schema description strings from the deprecated versions of the old output, the two are identical across all 14 CRDs.

  • On a kind cluster, with the first commit (before MCPRegistry's v1beta1 docs were kept):

    • Installed the chart from main, upgraded to this branch, rolled back and upgraded again.
    • Measured the real release Secrets at each step with Helm 4.2.3 and Helm 3.19.0. check-release-size.sh comes within 0.1-0.5% above the real size.
    • Probed admission for MCPGroup and MCPServer in both versions: defaults, pruning, enum, range and required-field checks. The results were byte-identical before and after the upgrade, and the v1alpha1 deprecation warning is still shown.
    • Ran kubectl explain: v1beta1 keeps its descriptions, and v1alpha1 has none.

API Compatibility

  • This PR does not break the v1beta1 API, OR the api-break-allowed label is applied and the migration guidance is described above.

Changes

File Change
cmd/thv-operator/crd-strip-descriptions/ New tool that removes schema descriptions from deprecated CRD versions and writes the YAML the way controller-gen does
cmd/thv-operator/Taskfile.yml operator-manifests builds the templates from a stripped copy of files/crds
deploy/charts/operator-crds/templates/ Regenerated (only description lines in v1alpha1 removed)
deploy/charts/operator-crds/hack/check-release-size.sh Estimates the stored release size and fails above 90% of 1 MiB
.github/workflows/helm-charts-test.yml Runs the size check
deploy/charts/operator-crds/CONTRIBUTING.md, .helmignore Documents how the templates are built; keeps hack/ out of the packaged chart
.github/workflows/api-compat.yml, secrets_admission_test.go Comments updated for the new generation step

Does this introduce a user-facing change?

Yes, small.

  • Before: kubectl explain --api-version=toolhive.stacklok.dev/v1alpha1 <kind> showed field descriptions.
  • After: it shows the fields without descriptions.

The default kubectl explain (v1beta1) is unchanged, and so is the behaviour of every resource.

Special notes for reviewers

  • This is a stopgap. The CRDs keep growing, and the deprecated versions still carry the full schema structure. At the recent growth rate, the 90% check will fire again in roughly 6 to 11 months. The lasting fix is to stop serving v1alpha1, which CONTRIBUTING.md now says.
  • Why the preferred version, not the storage version. For today's CRDs the two give the same output. They differ during a migration to v1: the deprecated v1beta1 would still be the storage version, so a storage rule would keep a second full copy of the docs that kubectl explain doesn't show by default.
  • Why only deprecated versions.
    • controller-gen's crd:maxDescLen=0 would save more, but it also removes the v1beta1 docs.
    • Moving the CRDs to the chart's crds/ directory stops Helm from upgrading them.
    • Splitting the chart into several releases risks deleting CRDs, and every resource, during the move.
  • Helm chart and tarball now differ. The chart's v1alpha1 schemas have no descriptions, while the thv-crds.tar.gz release asset keeps them. Applying the tarball with kubectl apply --server-side over a Helm-managed install now conflicts on .spec.versions even at the same release (--force-conflicts resolves it). Mixing the two methods already conflicted across releases, and the docs only describe Helm.

The operator-crds Helm release was at about 97.6% of the 1 MiB limit
on the Secret Helm stores each release in. Once it crosses the limit,
helm install and upgrade fail. Every CRD serves the deprecated v1alpha1
next to v1beta1 with a full copy of the schema, and the field
descriptions are most of that text and compress badly.

The chart templates are now generated from a copy of the CRDs in which
the descriptions of deprecated versions are removed. This brings the
release to about 61% of the limit. Schemas, validation, defaults and
the v1beta1 descriptions that kubectl explain shows by default are
unchanged. files/crds keeps the full CRDs, so the release tarball and
the API compatibility check are unaffected.

A CI step now fails when the release goes above 90% of the limit, and a
test checks against the real CRDs that the tool changes nothing besides
descriptions of deprecated versions. The CRDs keep growing, so this
buys headroom rather than removing the limit; the lasting fix is to
stop serving v1alpha1.

Closes stacklok#7456

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@jhrozek
jhrozek requested a review from ChrisJBurns as a code owner December 2, 2026 20:45
@codecov

codecov Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 70.11494% with 26 lines in your changes missing coverage. Please review.
✅ Project coverage is 83.04%. Comparing base (2279e41) to head (59db14e).
⚠️ Report is 7 commits behind head on main.

Files with missing lines Patch % Lines
cmd/thv-operator/crd-strip-descriptions/main.go 70.11% 26 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7466      +/-   ##
==========================================
+ Coverage   82.98%   83.04%   +0.05%     
==========================================
  Files         955      956       +1     
  Lines       99170    99426     +256     
==========================================
+ Hits        82300    82564     +264     
+ Misses      16865    16857       -8     
  Partials        5        5              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@rdimitrov rdimitrov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The approach looks right to me: working on the typed schema, the byte-identical round-trip test over the real CRDs, and the CI size check. One issue before this goes in, inline below.

func stripDeprecated(crd *apiextv1.CustomResourceDefinition) {
for i := range crd.Spec.Versions {
v := &crd.Spec.Versions[i]
if !v.Deprecated || v.Schema == nil {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

deprecated: true doesn't only mean "the old copy of the schema". MCPRegistry is deprecated as a whole kind, so both v1alpha1 and v1beta1 carry deprecated: true, and v1beta1 is its storage version. This strips every description from MCPRegistry: the template goes from 60 description: lines on main to 0 on this branch, and kubectl explain mcpregistry loses all field docs.

That contradicts the PR body ("the v1beta1 descriptions are unchanged") and the user-facing section, which only mentions v1alpha1. TestProcessRealCRDs doesn't catch it because it only compares non-deprecated versions. The same thing will happen silently to any kind that gets deprecated as a whole later.

Suggest skipping the storage version as well, and asserting the same in the test:

if !v.Deprecated || v.Storage || v.Schema == nil {
	continue
}
if !v.Deprecated || v.Storage {
	assert.Equal(t, v, dst.Spec.Versions[i], "version %s changed", v.Name)
}

MCPRegistry is small, so this gives up very little of the savings. If dropping MCPRegistry's docs is intended because the kind is going away, please say so in the PR body and the user-facing section instead.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, thanks. MCPRegistry was losing every description, and the test couldn't see it.

Fixed in 59db14e, with one change from your suggestion: the tool now keeps descriptions on the preferred version (the highest served version by version priority, which is what discovery advertises and kubectl explain shows by default) instead of the storage version. For today's CRDs that gives exactly the same output, and MCPRegistry's v1beta1 has its 30 descriptions back. The two only differ during a migration to v1, when the deprecated v1beta1 would still be the storage version. A storage rule would then keep a second full copy of the docs nobody reads by default, and a kind deprecated as a whole while storing its older version would lose the docs kubectl explain shows.

The real-CRD test now checks that the preferred version is unchanged, and works it out by sorting instead of calling the tool's helper. There are also fixtures for a kind deprecated as a whole and for the v1 migration; both fail if I swap the storage rule back in.

MCPRegistry is deprecated as a whole kind, so both of its versions are
marked deprecated. Stripping every deprecated version removed all of
its field docs, and kubectl explain mcpregistry showed none.

Keep the descriptions of the preferred version: the served version with
the highest version priority, which API discovery advertises and
kubectl explain shows by default. Strip only the other deprecated
versions. Keying on the storage version would give the same result
today, but not during a migration to v1, when an older, deprecated
version is still stored: it would keep docs nobody reads by default,
and a kind deprecated as a whole could lose the docs users do read.

The test over the real CRDs now checks that the preferred version is
unchanged, and two fixtures cover a kind deprecated as a whole and a
v1 migration. Also cover run() with tests.

Co-authored-by: Mecatl <noreply@mecatl.dev>
@jhrozek

jhrozek commented Dec 3, 2026

Copy link
Copy Markdown
Contributor Author

@rdimitrov, following up since this has been quiet since our reply on the MCPRegistry thread this morning. We kept the descriptions on the preferred version rather than the storage version, and the thread has the reasoning. If you still think the storage rule is the better one, tell us why and we'll switch it. Could you take another look when you get a chance?

This branch has not been deployed

No deployments
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.

operator-crds Helm release is close to the 1 MiB Secret limit

2 participants