Skip to content
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

Make API field defaulting and validation less error-prone #25460

Open
bgrant0607 opened this issue May 11, 2016 · 10 comments
Open

Make API field defaulting and validation less error-prone #25460

bgrant0607 opened this issue May 11, 2016 · 10 comments
Assignees
Labels
area/swagger lifecycle/frozen Indicates that an issue or PR should not be auto-closed due to staleness. priority/backlog Higher priority than priority/awaiting-more-evidence. sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery.

Comments

@bgrant0607
Copy link
Member

There are frequent errors in API field specification, such as:

For examples of multiple errors in one type, see:
#18885 (comment)

One way to make defaulting and validation less error prone would to be allow them to be specified declaratively, on API fields using tags or comments. Protocol buffers allow literal default values to be specified (though, unlike in Kubernetes, they aren't conveyed on the wire; non-literals, such as fields defaulted from other fields, can't be specified this way). Declarative validation, where possible (i.e., simple rules), was previously requested by #8116.

Since omitempty and pointer rules are apparently non-obvious, I think we should require specification of required vs optional and then either verify that the other properties are consistent or autogenerate them.

Auto-fixing field names in documentation is covered by #19319.

cc @lavalamp @thockin @kubernetes/sig-api-machinery

@bgrant0607 bgrant0607 added help-wanted priority/backlog Higher priority than priority/awaiting-more-evidence. sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. sig/contributor-experience Categorizes an issue or PR as relevant to SIG Contributor Experience. labels May 11, 2016
@smarterclayton
Copy link
Contributor

We talked about this today in the API SIG - there was general agreement
that validation should be divided into "schema driven" and "turing
complete", where the former is the list of items you describe above (and
possibly some others, like which values are allowed) that could be easily
specified declaratively, and should be in swagger. The remainder would be
a much smaller set, and could be duplicated on different API versions more
easily than today.

On Wed, May 11, 2016 at 3:52 AM, Brian Grant notifications@github.com
wrote:

There are frequent errors in API field specification, such as:

For examples of multiple errors in one type, see:
#18885 (comment)
#18885 (comment)

One way to make defaulting and validation less error prone would to be
allow them to be specified declaratively, on API fields using tags or
comments. Protocol buffers allow literal default values to be specified
(though, unlike in Kubernetes, they aren't conveyed on the wire;
non-literals, such as fields defaulted from other fields, can't be
specified this way). Declarative validation, where possible (i.e., simple
rules), was previously requested by #8116
#8116.

Since omitempty and pointer rules are apparently non-obvious, I think we
should require specification of required vs optional and then either verify
that the other properties are consistent or autogenerate them.

Auto-fixing field names in documentation is covered by #19319
#19319.

cc @lavalamp https://github.com/lavalamp @thockin
https://github.com/thockin @kubernetes/sig-api-machinery
https://github.com/orgs/kubernetes/teams/sig-api-machinery


You are receiving this because you are on a team that was mentioned.
Reply to this email directly or view it on GitHub
#25460

@smarterclayton
Copy link
Contributor

I'd like to move this along in 1.5 slightly, probably by focusing on the minimal thing that would allow required / optional to be correct (not just omitempty) and allow us to validate everything around that. Now that @mbohlool has generated openapi we can rely on struct tags more.

@mbohlool
Copy link
Contributor

I have a proof of concept for a validation framework #32824. If you think we can add something to that please comment there.

@fejta-bot
Copy link

Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale.
Stale issues rot after an additional 30d of inactivity and eventually close.

Prevent issues from auto-closing with an /lifecycle frozen comment.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or @fejta.
/lifecycle stale

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Dec 23, 2017
@fejta-bot
Copy link

Stale issues rot after 30d of inactivity.
Mark the issue as fresh with /remove-lifecycle rotten.
Rotten issues close after an additional 30d of inactivity.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or @fejta.
/lifecycle rotten
/remove-lifecycle stale

@k8s-ci-robot k8s-ci-robot added lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. and removed lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. labels Jan 22, 2018
@bgrant0607 bgrant0607 removed the sig/contributor-experience Categorizes an issue or PR as relevant to SIG Contributor Experience. label Jan 22, 2018
@bgrant0607
Copy link
Member Author

/remove-lifecycle rotten
/lifecycle frozen

I still think we need to move to declarative specifications as much as possible.

cc @enisoc

@k8s-ci-robot k8s-ci-robot added lifecycle/frozen Indicates that an issue or PR should not be auto-closed due to staleness. and removed lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. labels Jan 22, 2018
@felixfbecker
Copy link

Currently it is a big pain to work with YAML and the API in most strongly typed languages, because when deserialising a YAML file into swagger-generated Model classes, missing optional scalar fields like ContainerV1.failureThreshold (int) will get the runtime default value (0), but the server default value is 3, and this is only mentioned in the documentation, not in the schema. So when diffing the server state with the local instance, the patch will always include countless changes like this that reset values to their runtime default. But if the patch always excluded default values, then it would be impossible to generate a patch that resets a boolean from true to false.

What we would need is to expose the server default value in the schema through the JSON schema default field, so that the client can apply the right default values when deserialising, so that they won't make it into the patch if the values are the same.

@felixfbecker
Copy link

felixfbecker commented Aug 26, 2018

The inconsistency is also problematic - for example, int Container1.failureThreshold is a non-nullable with a default value of 3 (i.e. to set it the default, it has to be set explicitly to 3, or to check if it is the default it has to be checked if it's 3), but int PodSpecV1.TerminationGracePeriodSeconds is a nullable with default value of 30 (where the documentation says it should be set to null to use the default value).

Should all scalars with a default value be nullable or should they all be non-nullable? It's a bit cumbersome to work with a nullable type when querying the API when in reality the value will always be set because the server applies a default value.

@mbohlool mbohlool removed their assignment Apr 15, 2019
@thockin
Copy link
Member

thockin commented Aug 19, 2022

@apelisse I feel like we should probably close this old issue now, yes/no ?

@apelisse
Copy link
Member

I don't have a strong opinion on this one. We technically don't have validation markers yet (or at least, we could have more, CEL partially covers that too, @jpbetz).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/swagger lifecycle/frozen Indicates that an issue or PR should not be auto-closed due to staleness. priority/backlog Higher priority than priority/awaiting-more-evidence. sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery.
Projects
None yet
Development

No branches or pull requests

8 participants