Skip to content

feat: Generate OpenAPI schemas for all CRDs using controller-gen#3340

Open
ferrohd wants to merge 1 commit intotektoncd:mainfrom
ferrohd:crd-openapi-schemas
Open

feat: Generate OpenAPI schemas for all CRDs using controller-gen#3340
ferrohd wants to merge 1 commit intotektoncd:mainfrom
ferrohd:crd-openapi-schemas

Conversation

@ferrohd
Copy link
Copy Markdown

@ferrohd ferrohd commented Apr 11, 2026

Changes

Replace the hand-written CRDs that used a bare x-kubernetes-preserve-unknown-fields: true with no spec/status schema, with fully-typed OpenAPI v3 schemas generated from the Go types using controller-gen.

Problem: Every CRD in this project had no resource metadata defined — just type: object with preserve-unknown-fields. This meant no server-side validation, no kubectl explain, no IDE autocompletion, and no field pruning.

Solution: Use controller-gen to generate proper schemas from the existing Go types (which are already richly typed), then sync them into the config/ directories and Helm chart.

Commit breakdown

  1. Add kubebuilder markers to CRD Go types: Adds +kubebuilder:object:root, +kubebuilder:resource:scope=Cluster, +kubebuilder:subresource:status, and +kubebuilder:printcolumn markers to all 15 root types and list types. Escape-hatch fields that embed full k8s API types (AdditionalOptions, mf.Slice, external configs) are marked with PreserveUnknownFields + Schemaless to keep CRD size manageable.

  2. Add controller-gen toolchain and CRD sync script: Adds controller-gen v0.17.3 to the Makefile (make generate-crds, make sync-helm-crds) and a hack/sync-helm-crds.sh script that syncs generated CRDs into config/{base,kubernetes/base,openshift/base}/ and assembles the Helm chart CRD template files with proper conditionals and labels.

  3. Regenerate CRD manifests: Mechanical output of make sync-helm-crds. All 15 CRDs now carry typed spec/status schemas.

What this enables

  • Server-side validation: the API server rejects unknown/malformed fields
  • kubectl explain: users can discover the API from the CLI
  • IDE autocompletion: tools that consume the OpenAPI schema get full field info
  • Field pruning: unknown fields are rejected instead of silently preserved

Notes

  • The AdditionalOptions fields (Deployments, ConfigMaps, StatefulSets, HPAs) and a few external types (pruner config, scheduler config, mf.Slice manifests) retain x-kubernetes-preserve-unknown-fields since they intentionally accept arbitrary k8s objects.

Submitter Checklist

These are the criteria that every PR should meet, please check them off as you
review them:

See the contribution guide for more details.

Release Notes

CRD manifests now include full OpenAPI v3 schemas generated for all operator.tekton.dev custom resources.

@tekton-robot tekton-robot added the release-note Denotes a PR that will be considered when it comes time to generate release notes. label Apr 11, 2026
@tekton-robot tekton-robot requested review from jkhelil and khrm April 11, 2026 11:49
@linux-foundation-easycla
Copy link
Copy Markdown

linux-foundation-easycla Bot commented Apr 11, 2026

CLA Signed

The committers listed above are authorized under a signed CLA.

  • ✅ login: ferrohd / name: Alessandro (51d6d0f)

@tekton-robot tekton-robot added the size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. label Apr 11, 2026
@ferrohd ferrohd changed the title Generate OpenAPI schemas for all CRDs using controller-gen feat: Generate OpenAPI schemas for all CRDs using controller-gen Apr 14, 2026
Copy link
Copy Markdown
Member

@vdemeester vdemeester left a comment

Choose a reason for hiding this comment

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

Nice work! One suggestion: can we consider adding a CRD size validation step similar to what tektoncd/pipeline does in hack/update-schemas.sh — it validates each generated CRD stays under 256KB (JSON-serialized) to avoid issues with etcd's object size limits.

It's a nit though, so we could do it in a follow-up as it's definitely not as problematic as on tektoncd/pipeline.

Comment thread Makefile Outdated
@tekton-robot
Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: vdemeester

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@tekton-robot tekton-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Apr 15, 2026
@ferrohd ferrohd force-pushed the crd-openapi-schemas branch from 89ca00d to e1b1458 Compare April 15, 2026 17:41
@vdemeester
Copy link
Copy Markdown
Member

@ferrohd can you squash you commits and use rebase instead of merge to update the PR from main ? 🙏🏼

@ferrohd ferrohd force-pushed the crd-openapi-schemas branch from b8e9630 to 4fc623f Compare April 20, 2026 10:58
@jkhelil
Copy link
Copy Markdown
Member

jkhelil commented Apr 21, 2026

@ferrohd can you rebase this pr please ?

@ferrohd ferrohd force-pushed the crd-openapi-schemas branch from 4fc623f to f273cb0 Compare April 21, 2026 12:43
@tekton-robot tekton-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Apr 21, 2026
Replace the hand-written CRDs that used x-kubernetes-preserve-unknown-fields
with no spec/status schema with fully-typed OpenAPI v3 schemas generated
from the Go types using controller-gen v0.18.0.

This enables:
- Server-side validation of CR fields
- kubectl explain support for all CRD specs
- IDE autocompletion via OpenAPI schema discovery
- Proper field pruning of unknown fields

Changes:
- Add kubebuilder markers (+kubebuilder:object:root, resource, subresource,
  printcolumn) to all 15 CRD root types and list types
- Mark escape-hatch fields (AdditionalOptions, mf.Slice, external configs)
  with PreserveUnknownFields+Schemaless to keep CRD size manageable
- Add controller-gen v0.18.0 to Makefile (generate-crds / sync-helm-crds)
- Create hack/sync-helm-crds.sh to sync generated CRDs to config/ and
  Helm chart, with 256KB JSON size validation per CRD
- Regenerate all CRD YAML files in config/ and charts/
@ferrohd ferrohd force-pushed the crd-openapi-schemas branch from f273cb0 to 51d6d0f Compare April 22, 2026 11:56
@tekton-robot tekton-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Apr 22, 2026
@jkhelil jkhelil requested a review from pramodbindal April 23, 2026 07:40
@jkhelil
Copy link
Copy Markdown
Member

jkhelil commented Apr 23, 2026

@pramodbindal @enarha @anithapriyanatarajan
Can you have sometime to review this PR please ?

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

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants