Skip to content

Conversation

@lalitc375
Copy link
Contributor

What type of PR is this?

/kind feature
/kind api-change

What this PR does / why we need it:

This PR introduces the k8s-resource-fully-qualified-name format for declarative validation. This new format is used to validate the MatchAttribute field in DeviceConstraint, ensuring that it is a valid fully qualified name.

This change also corrects the error type for an empty domain or name in a qualified name from Required to Invalid. This provides a more accurate error message to the user.

Which issue(s) this PR is related to:

KEP: kubernetes/enhancements#5073

Special notes for your reviewer:

The error type for an empty domain or name in validateQualifiedName has been changed from field.Required to field.Invalid.

Does this PR introduce a user-facing change?

NONE

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

- [KEP]: https://github.com/kubernetes/enhancements/issues/5073

@k8s-ci-robot k8s-ci-robot added 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. kind/feature Categorizes issue or PR as related to a new feature. kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Oct 14, 2025
@k8s-ci-robot
Copy link
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.

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-priority Indicates a PR lacks a `priority/foo` label and requires one. area/code-generation sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. wg/device-management Categorizes an issue or PR as relevant to WG Device Management. and removed do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Oct 14, 2025
@lalitc375 lalitc375 force-pushed the device-attirubute branch 2 times, most recently from f685293 to 1bea5c7 Compare October 14, 2025 21:13
@lalitc375 lalitc375 changed the title Device attirubute [feat] Add k8s-resource-fully-qualified-name format Oct 14, 2025
@k8s-triage-robot
Copy link

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.

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Oct 17, 2025
@pohly pohly moved this from 🆕 New to ✅ Done in Dynamic Resource Allocation Oct 21, 2025
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Oct 21, 2025
@lalitc375
Copy link
Contributor Author

/assign @aaron-prindle @jpbetz

@k8s-ci-robot k8s-ci-robot added the size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. label Oct 27, 2025
@lalitc375 lalitc375 force-pushed the device-attirubute branch 2 times, most recently from fa056fe to 185bdd8 Compare October 27, 2025 18:14
@aaron-prindle
Copy link
Contributor

/retest

var allErrs field.ErrorList
s := string(*value)
if len(s) == 0 {
allErrs = append(allErrs, field.Required(fldPath, "name required"))
Copy link
Member

Choose a reason for hiding this comment

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

The last arg to Required() is almost never needed , and it's not clear that "required" is the right framing. What do I mean?

The field which invokes this is either required or optional. By the time you get here, requiredness should already be be asserted. Empty required values would be rejected and empty optional values would never call here. So if you are here it's either because there is a non-empty value or someone forgot to assert requiredness.

I think I would, instead, do the split and if the name is empty, let it fail the validateCIdentifier() or LongName() calls

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was done to closely mirror the handwritten validation code errors. I think we can rewrite hand validation code in the same way.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, lots of handwritten code is sloppy because it is used in exactly one place. This is our chance to clean up some of it

}
var allErrs field.ErrorList
if len(*value) == 0 {
allErrs = append(allErrs, field.Required(fldPath, "name can't be empty"))
Copy link
Member

Choose a reason for hiding this comment

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

Same comment as above.

Also it's odd how these chain -- you validate length here, then resourcesQualifiedName() validates it again

}

s := string(*value)
allErrs = append(allErrs, resourcesQualifiedName(ctx, op, fldPath, value, nil)...)
Copy link
Member

Choose a reason for hiding this comment

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

why not pass s instead of value -- potentially save on template expansions and is more obvious.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This need to pointer, Replaced it with &s. both should have same impact?

}
// TODO: This validation is incomplete. It should reject qualified names
// that contain more than one slash. Currently, names like "a/b/c" are not
// handled and are implicitly accepted.
Copy link
Member

Choose a reason for hiding this comment

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

Worse - they seem to be accepted regardless of what value they hold. I know we want to avoid side-quests, but this seems like something we should fix fairly aggressively.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes.

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Oct 28, 2025
@lalitc375 lalitc375 force-pushed the device-attirubute branch 2 times, most recently from df039c3 to 4a7d759 Compare October 28, 2025 21:39
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Oct 28, 2025
Copy link
Member

@thockin thockin left a comment

Choose a reason for hiding this comment

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

Any test which uses Matcher and Origin should probably NOT be embedding detail strings. I'd like to fix that error string and you're just adding places for me to go fix it.

name: "invalid name with dots",
input: "prefix.com/name.with.dots",
wantErrs: field.ErrorList{
field.Invalid(fldPath, "name.with.dots", "a valid C identifier must start with alphabetic character or '_', followed by a string of alphanumeric characters or '_' (e.g. 'my_name', or 'MY_NAME', or 'MyName', regex used for validation is '[A-Za-z_][A-Za-z0-9_]*')").WithOrigin("format=k8s-resource-fully-qualified-name"),
Copy link
Member

Choose a reason for hiding this comment

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

The Matcher doesn't need the detail string, just the origin. The fact that these giant error strings get copied into a million tests is a huge part of why we have origins in the first place,

Or at least pick a small substring that gives the confidence that the right thing went wrong

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Or at least pick a small substring that gives the confidence that the right thing went wrong

I have reduced the string size. This helps in figuring the validation is not circuited before expected blocks.

@k8s-ci-robot k8s-ci-robot added needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. do-not-merge/contains-merge-commits Indicates a PR which contains merge commits. and removed needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. labels Oct 29, 2025
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/contains-merge-commits Indicates a PR which contains merge commits. label Oct 29, 2025
Copy link
Member

@thockin thockin left a comment

Choose a reason for hiding this comment

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

Thanks!

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Oct 29, 2025
@k8s-ci-robot
Copy link
Contributor

LGTM label has been added.

Git tree hash: ca08a4dbe8b89f466fc149c06091a75ef54b0e1d

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: jpbetz, lalitc375, thockin

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

The pull request process is described 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 added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Oct 29, 2025
@k8s-ci-robot k8s-ci-robot merged commit de28a5b into kubernetes:master Oct 29, 2025
21 checks passed
@k8s-ci-robot k8s-ci-robot added this to the v1.35 milestone Oct 29, 2025
@lalitc375 lalitc375 deleted the device-attirubute branch November 3, 2025 17:46
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. area/code-generation 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/feature Categorizes issue or PR as related to a new feature. lgtm "Looks good to me", indicates that a PR is ready to be merged. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. release-note-none Denotes a PR that doesn't merit a release note. sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. wg/device-management Categorizes an issue or PR as relevant to WG Device Management.

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

6 participants