-
-
Notifications
You must be signed in to change notification settings - Fork 19
feat(v2): Make ResourceNames::ensure_max_length public
#1260
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -99,7 +99,11 @@ impl ResourceNames { | |
| /// `max_length < 1 /* character */ + 1 /* dash */ + hash_length`. | ||
| /// | ||
| /// Kubernetes object names cannot contain non-ASCII characters. | ||
| fn ensure_max_length(resource_name: String, max_length: usize, hash_length: usize) -> String { | ||
| pub fn ensure_max_length( | ||
| resource_name: String, | ||
| max_length: usize, | ||
| hash_length: usize, | ||
| ) -> String { | ||
|
Comment on lines
+102
to
+106
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This function was written for resource names, where the assertions always hold. If it's now used to shorten arbitrary strings (which could also come from the user) then you can That said, I do see the usefulness. I'd suggest making it safe for arbitrary strings (which isn't trivial) and moving it to a string utility module. |
||
| assert!(resource_name.is_ascii()); | ||
| assert!(max_length >= 1 /* character */ + 1 /* dash */ + hash_length); | ||
|
|
||
|
|
||
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 constant belongs in
kvp::annotation.Rather than exposing the value publicly, it might be cleaner to offer a
sanitizefunction that takes a key prefix and name and returns a validkvp::key::Key.