Skip to content

Commit

Permalink
fixup! fix: add name validation for custom resource templates
Browse files Browse the repository at this point in the history
  • Loading branch information
cbang-akamai committed Mar 28, 2024
1 parent be963b3 commit ae6c703
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
type: string
x-kubernetes-validations:
- rule: 3 <= size(self) && size(self) <= 26
message: linode nodebalancer labels must be between 3..32 characters
message: "custom validation: linode nodebalancer: labels must be between 3..32 characters"
18 changes: 11 additions & 7 deletions config/crd/patches/validation_in_linodemachinetemplates.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,15 @@
x-kubernetes-validations:
- rule: 3 <= size(self) && size(self) <= 58
message: linode instance labels must be between 3..64 characters
# TODO: Combine these into one regex to validate ALL constraints on Linode instance labels at once?
# https://www.linode.com/docs/api/linode-instances/#linode-create
- rule: self.contains('^[a-z0-9](.*[a-z0-9])*$')
message: linode instance labels must begin and end with an alphanumeric character
- rule: self.contains('^[-_.[:alnum:]]*$')
message: linode instance labels may only consist of alphanumeric characters, hyphens (-), underscores (_) or periods (.)
- rule: self.matches('^[[:alnum:]]([-_.[:alnum:]]+[:alnum:])*$')
message: >
custom validation: linode instance: labels:
must begin and end with an alphanumeric character,
may only consist of alphanumeric characters, hyphens (-), underscores (_) or periods (.),
cannot have two hyphens (--), underscores (__) or periods (..) in a row;
regex used for validation is: '^[[:alnum:]]([-_.[:alnum:]]+[:alnum:])*$',
see: https://www.linode.com/docs/api/linode-instances/#linode-create
# TODO: We need to combine this into one regex to minimize time complexity 🥺
# See: https://github.com/google/cel-spec/blob/master/doc/langdef.md#time-complexity
- rule: "!(self.contains('--') || self.contains('__') || self.contains('..'))"
message: linode instance labels cannot have two hyphens (--), underscores (__) or periods (..) in a row
message: "custom validation: linode instance: labels cannot have two hyphens (--), underscores (__) or periods (..) in a row"

0 comments on commit ae6c703

Please sign in to comment.