-
Notifications
You must be signed in to change notification settings - Fork 41.7k
[feat] Add k8s-resource-fully-qualified-name format #134602
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
This issue is currently awaiting triage. If a SIG or subproject determines this is a relevant issue, they will accept it by applying the The 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. |
f685293 to
1bea5c7
Compare
|
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. |
1bea5c7 to
87dc870
Compare
87dc870 to
148436e
Compare
|
/assign @aaron-prindle @jpbetz |
148436e to
743b3c4
Compare
fa056fe to
185bdd8
Compare
|
/retest |
| var allErrs field.ErrorList | ||
| s := string(*value) | ||
| if len(s) == 0 { | ||
| allErrs = append(allErrs, field.Required(fldPath, "name required")) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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")) |
There was a problem hiding this comment.
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)...) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes.
df039c3 to
4a7d759
Compare
There was a problem hiding this 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"), |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
4a7d759 to
1029044
Compare
bbab2e1 to
37ba7bb
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
/lgtm
/approve
|
LGTM label has been added. Git tree hash: ca08a4dbe8b89f466fc149c06091a75ef54b0e1d
|
|
[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 |
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-nameformat for declarative validation. This new format is used to validate theMatchAttributefield inDeviceConstraint, 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
RequiredtoInvalid. 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
validateQualifiedNamehas been changed fromfield.Requiredtofield.Invalid.Does this PR introduce a user-facing change?
Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.: