Skip to content

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

Open
ferrohd wants to merge 3 commits intotektoncd:mainfrom
ferrohd:crd-openapi-schemas
Open

Generate OpenAPI schemas for all CRDs using controller-gen#3340
ferrohd wants to merge 3 commits 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.

ferrohd added 3 commits April 11, 2026 13:26
Add controller-gen / kubebuilder markers to all 15 CRD root types and
their list types so that controller-gen can produce fully-typed OpenAPI
v3 schemas instead of the current bare x-kubernetes-preserve-unknown-fields.

Markers added per root type:
  +kubebuilder:object:root=true
  +kubebuilder:resource:scope=Cluster (with shortName where applicable)
  +kubebuilder:subresource:status
  +kubebuilder:printcolumn (Version, Ready, Reason)

Escape-hatch fields that embed full k8s API types or opaque external
types are annotated with PreserveUnknownFields + Schemaless to keep the
generated CRD size manageable:
  - AdditionalOptions (Deployments, ConfigMaps, StatefulSets, HPAs)
  - TektonInstallerSet manifests (mf.Slice / unstructured)
  - TektonPrunerConfig (external pruner config)
  - SchedulerConfig (external kueue config)

The custom BoolValue type is annotated with +kubebuilder:validation:Type=string.
Add controller-gen v0.17.3 as a Makefile-managed tool binary alongside
ko and kustomize, with two new targets:

  make generate-crds   - runs controller-gen to produce CRD YAMLs from
                         Go types into config/base/generated-crds/
  make sync-helm-crds  - runs generate-crds then hack/sync-helm-crds.sh

hack/sync-helm-crds.sh takes the generated CRDs, injects the standard
version/release labels, copies them to config/{base,kubernetes/base,
openshift/base}/ with copyright headers, and assembles the Helm chart
kubernetes-crds.yaml / openshift-crds.yaml with their respective
{{- if }} conditionals.
Output of 'make sync-helm-crds' using the markers and toolchain from
the previous commits.

Every CRD now carries a typed spec/status schema derived from the Go
structs instead of the previous bare:

    openAPIV3Schema:
      type: object
      x-kubernetes-preserve-unknown-fields: true

This enables server-side validation, kubectl explain, IDE autocompletion
and proper field pruning for all operator.tekton.dev resources.

Files updated:
  - config/base/generated-crds/         (raw controller-gen output)
  - config/base/300-*_crd.yaml          (kustomize source-of-truth, 12 CRDs)
  - config/kubernetes/base/300-*        (dashboard CRD)
  - config/openshift/base/300-*         (addon + OPAC CRDs)
  - charts/tekton-operator/templates/   (Helm chart, 13 k8s + 14 ocp CRDs)
@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
Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
To complete the pull request process, please assign jkhelil after the PR has been reviewed.
You can assign the PR to them by writing /assign @jkhelil in a comment when ready.

The full list of commands accepted by this bot can be found 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 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.

@tekton-robot tekton-robot added the size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. label Apr 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

2 participants