feat: Generate OpenAPI schemas for all CRDs using controller-gen#3340
feat: Generate OpenAPI schemas for all CRDs using controller-gen#3340ferrohd wants to merge 1 commit intotektoncd:mainfrom
Conversation
|
|
vdemeester
left a comment
There was a problem hiding this comment.
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.
|
[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 DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
89ca00d to
e1b1458
Compare
|
@ferrohd can you squash you commits and use rebase instead of merge to update the PR from main ? 🙏🏼 |
b8e9630 to
4fc623f
Compare
|
@ferrohd can you rebase this pr please ? |
4fc623f to
f273cb0
Compare
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/
f273cb0 to
51d6d0f
Compare
|
@pramodbindal @enarha @anithapriyanatarajan |
Changes
Replace the hand-written CRDs that used a bare
x-kubernetes-preserve-unknown-fields: truewith nospec/statusschema, with fully-typed OpenAPI v3 schemas generated from the Go types usingcontroller-gen.Problem: Every CRD in this project had no resource metadata defined — just
type: objectwith preserve-unknown-fields. This meant no server-side validation, nokubectl explain, no IDE autocompletion, and no field pruning.Solution: Use
controller-gento 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
Add kubebuilder markers to CRD Go types: Adds
+kubebuilder:object:root,+kubebuilder:resource:scope=Cluster,+kubebuilder:subresource:status, and+kubebuilder:printcolumnmarkers to all 15 root types and list types. Escape-hatch fields that embed full k8s API types (AdditionalOptions, mf.Slice, external configs) are marked withPreserveUnknownFields + Schemalessto keep CRD size manageable.Add controller-gen toolchain and CRD sync script: Adds
controller-genv0.17.3 to the Makefile (make generate-crds,make sync-helm-crds) and ahack/sync-helm-crds.shscript that syncs generated CRDs intoconfig/{base,kubernetes/base,openshift/base}/and assembles the Helm chart CRD template files with proper conditionals and labels.Regenerate CRD manifests: Mechanical output of
make sync-helm-crds. All 15 CRDs now carry typed spec/status schemas.What this enables
kubectl explain: users can discover the API from the CLINotes
AdditionalOptionsfields (Deployments, ConfigMaps, StatefulSets, HPAs) and a few external types (pruner config, scheduler config, mf.Slice manifests) retainx-kubernetes-preserve-unknown-fieldssince 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:
make test lintbefore submitting a PRSee the contribution guide for more details.
Release Notes