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

Allowing marking fields that should skip generating 'default' values in schemas #896

Open
munnerz opened this issue Mar 26, 2024 · 3 comments
Labels
lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale.

Comments

@munnerz
Copy link
Member

munnerz commented Mar 26, 2024

When generating schemas that reference external types, sometimes it is helpful to be able to avoid setting 'default' markers for fields within the type's schema.

As noted in kubernetes/kubernetes#95587 - it is recommended that defaulting should be skipped for templates of other resources (instead allowing the apiserver to set these defaults with this template is actually submitted to the apiserver).

Without a way to avoid generating these defaults, any controller that relies on hashing of say, a PodTemplate to determine whether an update is needed to the Pod will not be able to know if the object has actually changed and needs an update, or if a new field is introduced.

This is especially problematic when you consider stateful systems, as a change to a CRD that introduces a new default value will trigger a re-creation of all underlying pods.

Many alternatives are discussed in kubernetes/community#6764 to solve this, including having controllers only hash the fields they are interested in. This is problematic because over time as new fields are added, controllers may 'miss' these and therefore not trigger updates when the value is actually changed either.

Proposal

Adding a new marker that can be set on fields, e.g. //+ kubebuilder:default:skip=true which will cause default values to not be set in the generated sub-schema.

@munnerz
Copy link
Member Author

munnerz commented Mar 26, 2024

My only concern when implementing this so far, is currently markers do not recurse into sub-schemas. Is this intentional, and are there issues in doing this sort of recursive lookup?

An example of a problematic declarative default in a core type: https://github.com/kubernetes/api/blob/5147c1a32f6a0b9b155bb84e59f933e0ff8a3792/core/v1/types.go#L2144

@sbueringer
Copy link
Member

Sounds reasonable to me. No idea, about the recursive lookup.

Not really familiar with the current implementation but maybe some sort of "post-processing" to remove previously added defaults recursively would work? (not sure if that's different to what you suggested)

@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough contributors to adequately respond to all issues.

This bot triages un-triaged issues according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Mark this issue as fresh with /remove-lifecycle stale
  • Close this issue with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/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 Jul 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale.
Projects
None yet
Development

No branches or pull requests

4 participants