Skip to content

docs: add declarative validation patterns for feature-gates.md#8907

Open
yongruilin wants to merge 1 commit intokubernetes:masterfrom
yongruilin:dv-featuregate
Open

docs: add declarative validation patterns for feature-gates.md#8907
yongruilin wants to merge 1 commit intokubernetes:masterfrom
yongruilin:dv-featuregate

Conversation

@yongruilin
Copy link
Contributor

Documents declarative validation (DV) patterns for interacting with feature gates using +k8s:ifEnabled and +k8s:ifDisabled tags. The existing doc only covered handwritten validation patterns. As Kubernetes migrates to
declarative validation, feature authors need guidance on:

  • Using +k8s:forbidden + +k8s:ifEnabled for feature-gated new API fields
  • Using +k8s:ifEnabled/+k8s:ifDisabled for conditional field constraints and enum values
  • Wiring feature gates to validation options via rest.WithOptions
  • How DV ratcheting replaces the handwritten "already in use" pattern

Also clarifies existing validation subsections as "Handwritten validation" to disambiguate from the DV approach.

Which issue(s) this PR fixes:

Fixes #

@k8s-ci-robot k8s-ci-robot added area/developer-guide Issues or PRs related to the developer guide size/L Denotes a PR that changes 100-499 lines, ignoring generated files. sig/architecture Categorizes an issue or PR as relevant to SIG Architecture. labels Mar 17, 2026
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: yongruilin
Once this PR has been reviewed and has the lgtm label, please assign dims for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added sig/contributor-experience Categorizes an issue or PR as relevant to SIG Contributor Experience. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Mar 17, 2026
@yongruilin
Copy link
Contributor Author

/assign @thockin

Comment on lines 336 to 338
When a feature gate is disabled, the system should behave as if the API fields
do not exist. API operations which try to use the field are expected to proceed
as if the field was unknown and the "extra" data was discarded.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This documentation is surprising. While we do wipe the field for purposes of create. We continue to respect the field once it is "in use". I think we should update this paragraph and a paragraph about "in-use".

Take for example pod.spec.initContainer.resetPolicy. If this field is set when creating a pod, it creates a pod with a sidecar container. Ignoring or unsetting the field results in a pod that will treat the sidecar container as a normal init container, which is almost certainly going to break the workload.

Some other examples: InPlacePodVerticalScaling, HPAConfigurableTolerance, PreferSameTrafficDistribution, RecursiveReadOnlyMounts, ContainerStopSignals.

In all these examples, once a field is set, even after the FG is disabled, it continue to remain set AND remain mutable.

Copy link
Contributor Author

@yongruilin yongruilin Mar 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the current wording implies fields are always discarded when the gate is off, but in practice most dropDisabled* functions follow a !Enabled(featureX) && !fieldInUse(old). (Though not consistent — some cases drop unconditionally without an in-use check)

This also carries into validation - when gates off, some keeps validating when the fields is "in-use", while some directly forbid any update.

I think a feature gate should control the entrypoint, not the lifecycle of existing data:

  • Create / not in use: drop the field — no new adoption of a disabled feature.
  • In use: preserve the field, keep it mutable, and validate normally — data integrity matters, and freezing the field prevents users from fixing bad values when the gate was disabled precisely because something went wrong.

@thockin since you authored this section, thoughts?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/developer-guide Issues or PRs related to the developer guide cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. sig/architecture Categorizes an issue or PR as relevant to SIG Architecture. sig/contributor-experience Categorizes an issue or PR as relevant to SIG Contributor Experience. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants