Kubernetes Yaml Parser and Validating Schema

1,875 views
Skip to first unread message

krma...@gmail.com

unread,
Apr 6, 2017, 3:28:50 AM4/6/17
to Kubernetes developer/contributor discussion
Hi All
We have a thin layer on top of Kubernetes yaml and we are using github.com/ghodss/yaml to validate it.

When i use kubectl with a k8s yaml, i see that kubectl can do a lot more validation then what is possible with a simple yaml parser like the above. For e.g. if the indentation is wrong or unrecognized element, etc.
When i use the github.com/ghodss/yaml parser, it silently drops the indentation issues and we dont get the errors untill we have converted it to kubernetes yaml and sent them to the apiserver.

From briefly looking at kubectl code, it seems like the kubectl is using swagger schema to do the validation. I am not very familiar with it.My questions are:-

- Is swagger schema validation is how kubectl is getting richer validation ?
- Is it possible to get the same level of validation with some other libraries ?

Any pointers would be helpful.

Mayank

Brian Grant

unread,
Apr 6, 2017, 1:28:53 PM4/6/17
to Mayank, Kubernetes developer/contributor discussion, K8s API Machinery SIG, kubernete...@googlegroups.com
+SIGs CLI and API machinery

On Thu, Apr 6, 2017 at 12:28 AM, <krma...@gmail.com> wrote:
Hi All
We have a thin layer on top of Kubernetes yaml and we are using github.com/ghodss/yaml to validate it.

When i use kubectl with a k8s yaml, i see that kubectl can do a lot more validation then what is possible with a simple yaml parser like the above. For e.g. if the indentation is wrong or unrecognized element, etc.
When i use the github.com/ghodss/yaml parser, it silently drops the indentation issues and we dont get the errors untill we have converted it to kubernetes yaml and sent them to the apiserver.

From briefly looking at kubectl code, it seems like the kubectl is using swagger schema to do the validation. I am not very familiar with it.My questions are:-

- Is swagger schema validation is how kubectl is getting richer validation ?

Yes.
 
- Is it possible to get the same level of validation with some other libraries ?

You mean that you want to be able to invoke what kubectl does as a library?

I'd eventually like to see that, as well as other general-purpose kubectl functionality, and it's in the plan:


For schema validation specifically, I'd also like to see server-side support:


We also need to update the validation logic to use the newer OpenAPI spec:


 

Any pointers would be helpful.

Mayank

--
You received this message because you are subscribed to the Google Groups "Kubernetes developer/contributor discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kubernetes-dev+unsubscribe@googlegroups.com.
To post to this group, send email to kubernetes-dev@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kubernetes-dev/211e128d-1fe7-4059-a591-6a4a0e4a4d59%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Brendan Burns

unread,
Apr 11, 2017, 12:49:59 AM4/11/17
to Kubernetes developer/contributor discussion, krma...@gmail.com, kubernetes-sig...@googlegroups.com, kubernete...@googlegroups.com
The relevant (highly kubernetes specific) code is here:



On Thursday, April 6, 2017 at 10:28:53 AM UTC-7, Brian Grant wrote:
+SIGs CLI and API machinery
On Thu, Apr 6, 2017 at 12:28 AM, <krma...@gmail.com> wrote:
Hi All
We have a thin layer on top of Kubernetes yaml and we are using github.com/ghodss/yaml to validate it.

When i use kubectl with a k8s yaml, i see that kubectl can do a lot more validation then what is possible with a simple yaml parser like the above. For e.g. if the indentation is wrong or unrecognized element, etc.
When i use the github.com/ghodss/yaml parser, it silently drops the indentation issues and we dont get the errors untill we have converted it to kubernetes yaml and sent them to the apiserver.

From briefly looking at kubectl code, it seems like the kubectl is using swagger schema to do the validation. I am not very familiar with it.My questions are:-

- Is swagger schema validation is how kubectl is getting richer validation ?

Yes.
 
- Is it possible to get the same level of validation with some other libraries ?

You mean that you want to be able to invoke what kubectl does as a library?

I'd eventually like to see that, as well as other general-purpose kubectl functionality, and it's in the plan:


For schema validation specifically, I'd also like to see server-side support:


We also need to update the validation logic to use the newer OpenAPI spec:


 

Any pointers would be helpful.

Mayank

--
You received this message because you are subscribed to the Google Groups "Kubernetes developer/contributor discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kubernetes-de...@googlegroups.com.
To post to this group, send email to kuberne...@googlegroups.com.

krma...@gmail.com

unread,
Apr 13, 2017, 2:41:42 AM4/13/17
to Kubernetes developer/contributor discussion, krma...@gmail.com, kubernetes-sig...@googlegroups.com, kubernete...@googlegroups.com
Thanks Brendan and Brian for the pointers. I wanted to get the same kind of validation that kubectl offers for my own yamls which are wrappers over kubernetes yamls. It seems swagger schema is the right way to go about it.

Brian, for the issues you pointed, yes it would be indeed helpful to be able to do the same validation that kubectl does as a library. For e.g. is all the client side validation that is available in kubectl also avaialable in client-go ? That would be nice to have

-Mayank
Reply all
Reply to author
Forward
This conversation is locked
You cannot reply and perform actions on locked conversations.
0 new messages