-
Notifications
You must be signed in to change notification settings - Fork 211
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using kube-openapi + 'kubectl explain' on Custom Resources? #97
Comments
We don't publish the validation OpenAPI schema of CRD as part of the swagger.json. We should do that (with some loss in expressivity because we are still on OpenAPI v2 there, but on v3 for CRD validation). I am sure we also have an issue for that. This isn't too hard to do, just nobody did it. |
I don't agree with the |
Thanks @sttts for the inputs. I will be happy to contribute on this issue. Can you share the link to the issue |
is there a plan for this? |
@mingfang I haven't heard anything on it yet. I the mean while we have implemented the solution outlined in the blog post. OpenAPI Spec for Postgres custom resource can be queried as shown in line: |
This issue kubernetes/kubectl#546 may be useful |
It looks like progress relating to this is being made in kubernetes v1.13. |
kubernetes/kubernetes#67205 was moved out of 1.13 because we hit some snags. We opened kubernetes/kubernetes#71192 to continue the development. It will address the |
Issues go stale after 90d of inactivity. If this issue is safe to close now please do so with Send feedback to sig-testing, kubernetes/test-infra and/or fejta. |
the publish CRD openapi feature has been merged in 1.14 kubernetes/kubernetes#71192 website documentation on how to enable the feature is to be merged in kubernetes/website#12910 /close |
@roycaihw: Closing this issue. In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
@roycaihw It looks like 1.14 does not fully address this issue.
kubectl explain only shows the metadata but not the spec. kubectl explain crontabs --recursive
KIND: CronTab
VERSION: stable.example.com/v1
DESCRIPTION:
<empty>
FIELDS:
apiVersion <string>
kind <string>
metadata <Object>
annotations <map[string]string>
labels <map[string]string>
name <string>
namespace <string>
<removed non-relevant fields>
spec <> I expected the spec to be filled in. How does kubectl handle this? |
You forgot to specify |
@stts Thanks. I confirm that setting spec.type = object works. |
I ran a few tests with variations of the crontab CRD. In all cases, the request sent by
is the same {"apiVersion":"stable.example.com/v1","kind":"CronTab",
"metadata":{"name":"my-new-cron-object","namespace":"default"},
"spec":{"cronSpec":"* * * * */5","image":"my-awesome-cron-image"}} Can I assume from this that kubectl and api-server always expects the spec to be an object regardless of whether there is an openAPIV3Schema and spec.type? |
@mingfang if you don't specifiy it, the type of |
I think this needs to be documented. |
@devdattakulkarni |
@mingfang: Thanks!! |
@sttts Reading through https://kubernetes.io/docs/tasks/access-kubernetes-api/custom-resources/custom-resource-definitions/#publish-validation-schema-in-openapi-v2 and the examples by @mingfang at https://github.com/mingfang/kubernetes-crd-test |
@devdattakulkarni The reason is because kubectl explain works by loading the openapi published by the apiserver. The new feature in 1.14 is to publish CRDs with validation schema as part fo the openapi, which enables my test case #2 and #3 to work. You are correct that most CRDs fall in the test case #1 scenario and do not have openapi validation. Without it, there's really nothing to "explain". Hopefully more CRDs will include the validation going forward. |
@mingfang I understand the implementation. But I don't understand why there is no need to "explain" a CRD that does not have any validation defined. To me, "explain" is about showing the fields that are available in Custom Kind Spec and their descriptions - what do they do, how to use them, etc. This has nothing to do with validation -- at least I don't see how validation can be a dependency for this. |
@devdattakulkarni Without openAPIV3Schema, the only fields to explain are the basic metadata fields. Basically the CRD here https://github.com/mingfang/kubernetes-crd-test#test-case-1 can have the same explain output here https://github.com/mingfang/kubernetes-crd-test#test-case-2. I made the same comment here kubernetes/kubernetes#71159 (comment) but apparently that can't be done due to backwards compatibility issue with kubectl. In fact my Terraform plugin requires the metadata fields and I had to hack it here https://github.com/mingfang/terraform-provider-k8s/blob/e04774a198874111e505c40fdaeef4149db15f82/k8s/k8sconfig.go#L200 |
@mingfang Thanks for the pointer to #71159. Reading through the comments in there, I agree with you that not everyone will necessarily provide validation schema in the CRD definition. The backward compatibility issue with kubectl seems to be the blocker. But even after that is resolved, I am wondering how would explain behave for spec properties for which validation is not defined in the schema. Disclaimer: I haven't experimented with schema validation, so don't know whether validation needs to be defined for all the Spec properties or if it okay to define it only for some subset. |
I was wondering if 'kubectl explain' can be used to find out information about Custom Resources?
Based on my understanding of kube-openapi and 'kubectl explain' workflow, it seems to me that this is currently not possible. Is this correct understanding?
I have written up my analysis here:
https://medium.com/@cloudark/understanding-kubectl-explain-9d703396cc8
Could you take a look and let me know if it is correct?
cc: @sttts
The text was updated successfully, but these errors were encountered: