Skip to content

✨ Add support for k8s:enum markers#1352

Open
alvaroaleman wants to merge 2 commits intokubernetes-sigs:mainfrom
alvaroaleman:enum
Open

✨ Add support for k8s:enum markers#1352
alvaroaleman wants to merge 2 commits intokubernetes-sigs:mainfrom
alvaroaleman:enum

Conversation

@alvaroaleman
Copy link
Member

This change adds support for the k8s:enum marker as described in the kep.

It is a rebase of #1250 plus a test

Closes #1250

/assign @JoelSpeed @lalitc375

@alvaroaleman alvaroaleman added the tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges. label Feb 21, 2026
@k8s-ci-robot
Copy link
Contributor

@alvaroaleman: GitHub didn't allow me to assign the following users: lalitc375.

Note that only kubernetes-sigs members with read permissions, repo collaborators and people who have commented on this issue/PR can be assigned. Additionally, issues/PRs can only have 10 assignees at the same time.
For more information please see the contributor guide

Details

In response to this:

This change adds support for the k8s:enum marker as described in the kep.

It is a rebase of #1250 plus a test

Closes #1250

/assign @JoelSpeed @lalitc375

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
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: alvaroaleman

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

The pull request process is described 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 approved Indicates a PR has been approved by an approver from all required OWNERS files. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Feb 21, 2026
ValidationAtMostOneOfPrefix = validationPrefix + "AtMostOneOf"
ValidationAtLeastOneOfPrefix = validationPrefix + "AtLeastOneOf"

// K8sEnumTag indicates that the given type is an enum; all const values of this type are considered values in the enum
Copy link
Contributor

Choose a reason for hiding this comment

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

@lalitc375 Do you know in DV if there would be a way to gate a new value within an enum based on some combination of +k8s:ifEnabled?

// - "Forbid": forbids concurrent runs, skipping next run if previous run hasn't finished yet;
// - "Replace": cancels currently running job and replaces it with a new one
// +optional
K8sConcurrencyPolicy K8sConcurrencyPolicy `json:"k8sConcurrencyPolicy,omitempty"`
Copy link
Contributor

Choose a reason for hiding this comment

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

Are folks likely to put the tag on a field, does the generator error in that case?

testEnv = &envtest.Environment{}
testEnv = &envtest.Environment{
CRDInstallOptions: envtest.CRDInstallOptions{
Paths: []string{"testdata.kubebuilder.io_enums.yaml"},
Copy link
Contributor

Choose a reason for hiding this comment

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

What do we do for other test suites? They must also install schemas right?


// infoToSchema creates a schema for the type in the given set of type information.
func infoToSchema(ctx *schemaContext) *apiextensionsv1.JSONSchemaProps {
if ctx.info.Markers.Get(crdmarkers.K8sEnumTag) != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

This is surprisingly early in the flow of the types to schema conversion

Does this make sense here vs in somewhere like typeToSchema? What's the flow for the existing enum marker?

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

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. 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. tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants