Skip to content

DRA: migrate DeviceTaint and Conditions to declarative validation#135460

Open
dumko2001 wants to merge 9 commits intokubernetes:masterfrom
dumko2001:dra-declarative-validation-135073
Open

DRA: migrate DeviceTaint and Conditions to declarative validation#135460
dumko2001 wants to merge 9 commits intokubernetes:masterfrom
dumko2001:dra-declarative-validation-135073

Conversation

@dumko2001
Copy link
Copy Markdown

What type of PR is this?
/kind cleanup
/kind feature

What this PR does / why we need it:
This PR migrates the validation for Device.Taints and AllocatedDeviceStatus.Conditions from manual Go code to declarative markers, addressing items from the tracking issue #135073.

Changes:

staging/src/k8s.io/api/resource/v1/types.go:
Added // +k8s:maxItems=16 to Device.Taints.
Added // +k8s:maxItems=8, // +k8s:listType=map, and // +k8s:listMapKey=type to AllocatedDeviceStatus.Conditions.
pkg/apis/resource/validation/validation.go:
Updated validateDevice to mark Taints size as covered by declarative validation (sizeCovered).
Removed the manual length check for Conditions in validateDeviceStatus.
Ran make update to synchronize generated files (zz_generated.* and generated.proto).

Which issue(s) this PR is related to:
Fixes #135073

Special notes for your reviewer:
The tracking issue suggested adding // +k8s:unique=map for AllocatedDeviceStatus.Conditions.

I have omitted this specific tag because it causes a conflict in update-codegen:

tag "k8s:unique": unique tag may not be used with listType=set or listType=map
Since listType=map already enforces uniqueness on the key (type), the explicit unique tag is redundant.

Does this PR introduce a user-facing change?

NONE

Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:

@k8s-ci-robot k8s-ci-robot added release-note-none Denotes a PR that doesn't merit a release note. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. kind/feature Categorizes issue or PR as related to a new feature. labels Nov 26, 2025
@linux-foundation-easycla
Copy link
Copy Markdown

linux-foundation-easycla Bot commented Nov 26, 2025

CLA Signed

The committers listed above are authorized under a signed CLA.

@k8s-ci-robot k8s-ci-robot added the do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. label Nov 26, 2025
@k8s-ci-robot
Copy link
Copy Markdown
Contributor

This issue is currently awaiting triage.

If a SIG or subproject determines this is a relevant issue, they will accept it by applying the triage/accepted label and provide further guidance.

The triage/accepted label can be added by org members by writing /triage accepted in a comment.

Details

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 needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels Nov 26, 2025
@k8s-ci-robot
Copy link
Copy Markdown
Contributor

Welcome @dumko2001!

It looks like this is your first PR to kubernetes/kubernetes 🎉. 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/kubernetes 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
Copy link
Copy Markdown
Contributor

Hi @dumko2001. Thanks for your PR.

I'm waiting for a github.com 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.

Details

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 needs-priority Indicates a PR lacks a `priority/foo` label and requires one. label Nov 26, 2025
@k8s-ci-robot k8s-ci-robot added kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API wg/device-management Categorizes an issue or PR as relevant to WG Device Management. labels Nov 26, 2025
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. label Nov 26, 2025
@dumko2001 dumko2001 force-pushed the dra-declarative-validation-135073 branch from a6760d0 to 46eccab Compare November 26, 2025 14:16
@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 Nov 26, 2025
@k8s-triage-robot
Copy link
Copy Markdown

This PR may require API review.

If so, when the changes are ready, complete the pre-review checklist and request an API review.

Status of requested reviews is tracked in the API Review project.

@pohly pohly moved this from 🆕 New to 👀 In review in Dynamic Resource Allocation Dec 1, 2025
Copy link
Copy Markdown
Contributor

@lalitc375 lalitc375 left a comment

Choose a reason for hiding this comment

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

Thank you for the PR @dumko2001 . Totally appreciate it.

Please follow this pattern for adding tags.

The ideal PR structure for a PR contributing a DV tag migration is:

Commit # 1: IF NOT ALREADY WIRED UP FOR DV - Wire up the apigroup, add empty test and empty generated file. I don't need to review this, you know the pattern by now.

Commit # 2: Use a single DV tag on a single field. E.g. Add +k8s:required to required field. Includes generated code and robust test cases. Emphasis on test-cases -- we want enough to prove that a field is correct, but we don't want to duplicate all the per-tag tests (e.g. a k8s-short-name field has dozens of corner cases, but we really only need a few). We want each case to be as short and specific as possible, which is why the "tweak" pattern and the use of Origin for Invalid() errors is so important. Specify as little as possible to be sufficiently precise. Newcomers need guidance on this.

Commits # 3...N: Use DV tags on the same field, one per commit; repeat until that field is done or all that is left is not handled by DV yet. Includes generated code and tests for each field. (not the case for the specific examples below as they are for single tag migrations)

Commits N+1...M: Repeat the above for more fields. (not the case for the specific examples below as they are for single field migrations)

The emphasis is on lots of small commits. Maintaining commit discipline is hard but worthwhile.

If DV exposes bugs in the existing testing or the hand-written validation itself (!!), those should be fixed as a PR of its own or as commits at the front of the PR.

Comment thread pkg/apis/resource/validation/validation.go
Comment thread staging/src/k8s.io/api/resource/v1/types.go
// +optional
// +listType=atomic
// +featureGate=DRADeviceTaints
// +k8s:maxItems=16
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Add tests for these new validation tags in pkg/registry/resource/resourceslice/declarative_validation_test.go

@lalitc375
Copy link
Copy Markdown
Contributor

/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 Dec 15, 2025
@k8s-ci-robot k8s-ci-robot added the do-not-merge/contains-merge-commits Indicates a PR which contains merge commits. label Jan 11, 2026
@dumko2001 dumko2001 force-pushed the dra-declarative-validation-135073 branch from f47596c to ea3fb7f Compare January 11, 2026 07:37
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/contains-merge-commits Indicates a PR which contains merge commits. label Jan 11, 2026
@dumko2001 dumko2001 force-pushed the dra-declarative-validation-135073 branch from ea3fb7f to d2dc655 Compare January 11, 2026 07:56
@dumko2001
Copy link
Copy Markdown
Author

@lalitc375 Addresses all feedback:

Refactored Tags: Fixed invalid MinLength and redundant Enum tags; added missing +k8s:optional.
Restored Duplicate Logic: Reverted duplicate checks to standard handwritten validation. This preserves existing behavior and test coverage without complex workarounds.
Rebase: Rebased on master, carefully preserving your recent ResourceSlice map key changes during conflict resolution.
Verified with make update and local tests.

@dumko2001 dumko2001 requested a review from lalitc375 January 11, 2026 09:39
Comment thread staging/src/k8s.io/api/resource/v1/types.go
Comment thread pkg/registry/resource/resourceslice/declarative_validation_test.go
Comment thread pkg/registry/resource/resourceclaim/declarative_validation_test.go Outdated
Comment thread pkg/registry/resource/resourceclaim/declarative_validation_test.go
@dumko2001
Copy link
Copy Markdown
Author

dumko2001 commented Jan 14, 2026

@lalitc375 Addressed all 4 comments:

Added +k8s:listMapKey=type test with normalization rule
Added at-limit taints test (16 taints)
Moved ResourceVersion to test loop
Added at-limit conditions test (8 conditions)

@dumko2001 dumko2001 requested a review from lalitc375 January 14, 2026 05:59
Comment thread pkg/apis/resource/validation/validation.go
Comment thread pkg/apis/resource/validation/validation.go
Comment thread pkg/registry/resource/resourceslice/declarative_validation_test.go
Comment thread pkg/registry/resource/resourceclaim/declarative_validation_test.go
@dumko2001 dumko2001 requested a review from lalitc375 January 30, 2026 17:12
@dumko2001 dumko2001 force-pushed the dra-declarative-validation-135073 branch from 04915d8 to 467bc3f Compare January 31, 2026 03:24
@dumko2001
Copy link
Copy Markdown
Author

@lalitc375 Need clarification on removing .type from field paths.

The duplicate validation uses metav1validation.ValidateConditions which outputs conditions[1].type. Other K8s code (policy, storagemigration) uses the same function with this path format.

Options:

Keep normalization rule to map DV → HW format for testing
Skip duplicate condition equivalence tests (DV handles duplicates correctly anyway)
Which approach?

@dumko2001
Copy link
Copy Markdown
Author

/test pull-kubernetes-unit

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Feb 26, 2026
- Remove invalid +k8s:validation:MinLength=1 tag from DeviceTaint.Key
- Remove redundant +k8s:validation:Enum tag from DeviceTaint.Effect
- Add missing +k8s:optional tag to AllocatedDeviceStatus.Conditions
- Applied to v1, v1beta1, and v1beta2 API versions
- Add 'valid: at limit taints' test (16 taints) for ResourceSlice
- Add 'valid: at limit conditions' test (8 conditions) for ResourceClaim
- Add 'invalid: duplicate condition type' test for +k8s:listMapKey=type
- Move ResourceVersion assignment to test loop
- Add normalization rule for conditions path matching
- Mark duplicate condition errors as covered by declarative
@dumko2001 dumko2001 force-pushed the dra-declarative-validation-135073 branch from 467bc3f to 3d09157 Compare March 8, 2026 19:19
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Mar 8, 2026
@dumko2001
Copy link
Copy Markdown
Author

@lalitc375 can you review pls ?

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Mar 27, 2026
@k8s-ci-robot
Copy link
Copy Markdown
Contributor

PR needs rebase.

Details

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.

@dims dims added the lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. label May 5, 2026
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. kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. kind/feature Categorizes issue or PR as related to a new feature. lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. release-note-none Denotes a PR that doesn't merit a release note. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. wg/device-management Categorizes an issue or PR as relevant to WG Device Management.

Projects

Status: 👀 In review

Development

Successfully merging this pull request may close these issues.

[Umbrella] DRA Declarative Validation Migration Tracking Issue

6 participants