Serve OpenAPI spec for registered CRDs#67205
Conversation
e3ada48 to
e1e5526
Compare
e1e5526 to
b384394
Compare
a5b4f86 to
ef38608
Compare
|
/retest |
0a0e490 to
af368cf
Compare
|
This PR is ready for review. Please take a look :) Please see the gist https://gist.github.com/roycaihw/1bb6eb7973b5496cb501ee50c8ee1ee3 for an example of constructed openapi spec for CRD: |
103ae5e to
45c0e83
Compare
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: roycaihw, smarterclayton 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 |
de18cc7 to
12f796b
Compare
12f796b to
4625bf7
Compare
|
/lgtm |
|
I wasn't able to see this from a casual scan of the code, but do we have a way to pass description for fields and model objects back from this? If not, we definitely need that in order to make |
|
@smarterclayton the description of a scheme prop is copied into the published schema. So from the code it looks like this should work. @roycaihw can you add an e2e test which calls kubectl explain against such a CRD? |
|
@smarterclayton this shows up in the openapi spec (but kubectl explain does not do anything, should it?) |
|
looks like the individual schema item does not include a |
|
interestingly, it looks like the |
|
The end use case is that a CRD is able to show something like the following
for any CRD property:
explain pods.spec.serviceAccountName
KIND: Pod
VERSION: v1
FIELD: serviceAccountName <string>
DESCRIPTION:
ServiceAccountName is the name of the ServiceAccount to use to run this
pod. More info:
https://kubernetes.io/docs/tasks/configure-pod-container/configure-service-account/
|
|
this adds the GVK to the openapi spec: diff --git a/staging/src/k8s.io/apiextensions-apiserver/pkg/openapi/construction.go b/staging/src/k8s.io/apiextensions-apiserver/pkg/openapi/construction.go
index 804681da1f..0327e6eacb 100644
--- a/staging/src/k8s.io/apiextensions-apiserver/pkg/openapi/construction.go
+++ b/staging/src/k8s.io/apiextensions-apiserver/pkg/openapi/construction.go
@@ -96,6 +96,11 @@ func (c *SwaggerConstructor) ConstructCRDOpenAPISpec() *spec.Swagger {
var schema spec.Schema
if c.schema != nil {
schema = *c.schema
+ schema.AddExtension("x-kubernetes-group-version-kind", map[string]string{
+ "group": c.group,
+ "kind": c.kind,
+ "version": c.version,
+ })
}but explain is still confused: and kubectl validation doesn't pick up the schema and complain about unknown fields: |
|
@liggitt The format of |
|
kubectl explain and validation works now. Will send a PR with an e2e test |
that actually illustrates a problem... the published schema does not contain standard object fields kind/apiVersion/metadata this was not caught by the tests because of the delay in publishing the schema and the missing group version kind. at this point, I think it is too late to rush to fix these issues. I think we need to roll back this PR and queue it up for 1.14 (or file for an exception while the issues are worked on out of master) |
What this PR does / why we need it:
Generate and serve the OpenAPI spec for registered CRDs
Which issue(s) this PR fixes (optional, in
fixes #<issue number>(, fixes #<issue_number>, ...)format, will close the issue(s) when PR gets merged):Fixes #58603
Special notes for your reviewer:
Release note:
reverted in #71158, original release note was:
/sig api-machinery
cc @mbohlool @sttts