Skip to content

Conversation

wazery
Copy link

@wazery wazery commented Aug 11, 2025

Implements +kubebuilder:feature-gate=<gate-name> marker that allows fields to be conditionally included in generated CRDs based on enabled feature gates.

  • Add centralized featuregate package with evaluation and parsing logic
  • Implement CRD feature gate markers for conditional field inclusion
  • Add RBAC feature gate support with multiple gate evaluation
  • Extend Webhook generator with feature gate capabilities
  • Include comprehensive test coverage and golden output files

Addresses #1238

@k8s-ci-robot k8s-ci-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Aug 11, 2025
Copy link

linux-foundation-easycla bot commented Aug 11, 2025

CLA Signed

The committers listed above are authorized under a signed CLA.

  • ✅ login: wazery / name: Wazery (e3a9853)

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

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

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

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 requested a review from vincepri August 11, 2025 15:18
@k8s-ci-robot k8s-ci-robot added the cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. label Aug 11, 2025
@k8s-ci-robot
Copy link
Contributor

Welcome @wazery!

It looks like this is your first PR to kubernetes-sigs/controller-tools 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes-sigs/controller-tools has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot k8s-ci-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Aug 11, 2025
@k8s-ci-robot
Copy link
Contributor

Hi @wazery. Thanks for your PR.

I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

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-sigs/prow repository.

@k8s-ci-robot k8s-ci-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Aug 11, 2025
Copy link
Contributor

@JoelSpeed JoelSpeed left a comment

Choose a reason for hiding this comment

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

I'm keen to seen progress on this issue, thanks @wazery for starting the push forward.

Feature gating is complex when it comes to CRDs. I'd be keen to see if we can also work out a plan for how we will gate specific markers, is that something we can align on as a project before we move forward?

Specifically I've seen needs for feature gated different enum sets, different feature gated XValidations and different values for things like Min/Max items that are feature gated.

But perhaps we actually need to be able to support gating all of the various markers we support?

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Aug 11, 2025
@k8s-ci-robot
Copy link
Contributor

@wazery: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
pull-controller-tools-test-main 4d70735 link true /test pull-controller-tools-test-main

Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR.

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-sigs/prow repository. I understand the commands that are listed here.

@wazery wazery changed the title ✨ Add feature gate marker support for conditional CRD field inclusion ✨ WIP Add feature gate marker support for conditional CRD field inclusion Aug 11, 2025
@wazery wazery force-pushed the w-feature-gate-support branch from 3001605 to b15c521 Compare August 11, 2025 18:30
@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. and removed cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels Aug 11, 2025
@wazery wazery force-pushed the w-feature-gate-support branch from b15c521 to de2450b Compare August 11, 2025 18:35
@wazery
Copy link
Author

wazery commented Aug 12, 2025

I'm keen to seen progress on this issue, thanks @wazery for starting the push forward.

Feature gating is complex when it comes to CRDs. I'd be keen to see if we can also work out a plan for how we will gate specific markers, is that something we can align on as a project before we move forward?

Specifically I've seen needs for feature gated different enum sets, different feature gated XValidations and different values for things like Min/Max items that are feature gated.

But perhaps we actually need to be able to support gating all of the various markers we support?

/ok-to-test

Thanks a lot Joel for your review, I truly appreciate it and learn much from it.

As you can see in the current implementation it's very initial, and allows only binary field inclusion so either the entire field is in or out. Yet we can enhance the implementation further to address your cases:

  • Feature-gated enum values
  • Feature-gated validation rules (XValidations)
  • Feature-gated marker values (Min/MaxItems, etc.)
  • Conditional marker application

For example:

Option A: Inline Feature Gate Syntax

// Feature-gated enum values
// +kubebuilder:validation:Enum=stable;production
// +kubebuilder:validation:Enum=alpha;beta;experimental,featureGate=alpha

// Feature-gated validation rules  
// +kubebuilder:validation:XValidation=rule="self.size > 0"
// +kubebuilder:validation:XValidation=rule="self.advanced == true",featureGate=alpha

// Feature-gated min/max values
// +kubebuilder:validation:MinItems=1
// +kubebuilder:validation:MinItems=5,featureGate=strict

Option B: Dedicated Feature Gate Markers

// +kubebuilder:validation:Enum=stable;production
// +kubebuilder:validation:Enum:featureGate=alpha,value=alpha;beta;experimental

// +kubebuilder:validation:XValidation=rule="self.size > 0"  
// +kubebuilder:validation:XValidation:featureGate=alpha,rule="self.advanced == true"

Option C: Block-based Feature Gating

// +kubebuilder:feature-gate:alpha
// +kubebuilder:validation:Enum=alpha;beta;experimental  
// +kubebuilder:validation:XValidation=rule="self.advanced == true"
// +kubebuilder:feature-gate:end

// +kubebuilder:validation:Enum=stable;production  // always applied

I love to hear your thoughts on how do you think we have to move forward on this PR, and truly appreciated your help 🙇.

wazery pushed a commit to wazery/controller-tools that referenced this pull request Aug 12, 2025
Based on feedback from PR kubernetes-sigs#1259 review comments, enhance RBAC feature gates with:

- Support for complex feature gate expressions using OR (|) and AND (&) logic
- Enhanced documentation with clear usage examples
- Validation for feature gate expressions with proper error handling
- Comprehensive test coverage for multiple gate scenarios

New feature gate syntax:
- Single gate: featureGate=alpha
- OR logic: featureGate=alpha|beta (enabled if ANY gate is true)
- AND logic: featureGate=alpha&beta (enabled if ALL gates are true)

Examples:
// +kubebuilder:rbac:featureGate=alpha|beta,groups=apps,resources=deployments,verbs=get;list
// +kubebuilder:rbac:featureGate=alpha&beta,groups="",resources=services,verbs=get;list

Addresses maintainer feedback on expression validation, multiple gate support,
and improved documentation clarity.
@k8s-ci-robot k8s-ci-robot added cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Aug 12, 2025
wazery added a commit to wazery/controller-tools that referenced this pull request Aug 12, 2025
Based on feedback from PR kubernetes-sigs#1259 review comments, enhance RBAC feature gates with:

- Support for complex feature gate expressions using OR (|) and AND (&) logic
- Enhanced documentation with clear usage examples
- Validation for feature gate expressions with proper error handling
- Comprehensive test coverage for multiple gate scenarios

New feature gate syntax:
- Single gate: featureGate=alpha
- OR logic: featureGate=alpha|beta (enabled if ANY gate is true)
- AND logic: featureGate=alpha&beta (enabled if ALL gates are true)

Examples:
// +kubebuilder:rbac:featureGate=alpha|beta,groups=apps,resources=deployments,verbs=get;list
// +kubebuilder:rbac:featureGate=alpha&beta,groups="",resources=services,verbs=get;list

Addresses maintainer feedback on expression validation, multiple gate support,
and improved documentation clarity.
@wazery wazery force-pushed the w-feature-gate-support branch from ff80782 to cc41ffa Compare August 12, 2025 12:58
@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. and removed cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels Aug 12, 2025
@JoelSpeed
Copy link
Contributor

From your suggestions, I'd be interested to see if we can move towards Option A, though I don't know how simple that is for markers where we currently don't have keyed values.

So for example, in XValidation, it's easy to add another value as it's already a multi-value marker. For the single value markers, adding an optional additional field isn't something I've looked into (not recently at least), but from the UX perspective sounds like the best IMO

Interested to see if other maintainers have opinions on this project @alvaroaleman @sbueringer (and @everettraven who is a colleague who helps me with API review at RH)

wazery pushed a commit to wazery/controller-tools that referenced this pull request Aug 26, 2025
Introduces pkg/featuregate to eliminate code duplication across CRD, RBAC,
and Webhook generators. This addresses the main architectural concerns
raised in PR kubernetes-sigs#1259 review.

Features:
- Centralized parsing and validation logic
- Strict mode for unknown gate validation
- Support for complex AND/OR expressions
- Backward compatible legacy functions
- Uses k8s.io/apimachinery/pkg/util/sets
- Comprehensive test coverage

The package provides both legacy functions for backward compatibility
and a new Registry API for strict validation of known feature gates.
@k8s-ci-robot k8s-ci-robot added cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. and removed cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Aug 26, 2025
@wazery wazery force-pushed the w-feature-gate-support branch 5 times, most recently from 101f809 to 2e1498d Compare August 26, 2025 20:37
@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Aug 26, 2025
@wazery wazery force-pushed the w-feature-gate-support branch from 2e1498d to e53dccf Compare August 26, 2025 20:46
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Aug 26, 2025
@wazery wazery force-pushed the w-feature-gate-support branch from e53dccf to 53df8d4 Compare August 26, 2025 20:51
@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. and removed cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels Aug 26, 2025
@wazery wazery force-pushed the w-feature-gate-support branch 3 times, most recently from a933760 to 73f7c9b Compare August 27, 2025 20:32
…ok generators

- Add centralized featuregate package with evaluation and parsing logic
- Implement CRD feature gate markers for conditional field inclusion
- Add RBAC feature gate support with multiple gate evaluation
- Extend Webhook generator with feature gate capabilities
- Include comprehensive test coverage and golden output files
@wazery wazery force-pushed the w-feature-gate-support branch from 73f7c9b to e3a9853 Compare August 27, 2025 20:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants