From 1f4919377b0ef8dd92b790db7418fbb7339b8888 Mon Sep 17 00:00:00 2001 From: Cindy Bang Date: Wed, 27 Mar 2024 14:00:00 -0400 Subject: [PATCH] fixup! fix: add name validation for custom resource templates --- .../validation_in_linodeclustertemplates.yaml | 5 +++- .../validation_in_linodemachinetemplates.yaml | 26 +++++++++++++------ 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/config/crd/patches/validation_in_linodeclustertemplates.yaml b/config/crd/patches/validation_in_linodeclustertemplates.yaml index 579ae5542..b3b7b49bd 100644 --- a/config/crd/patches/validation_in_linodeclustertemplates.yaml +++ b/config/crd/patches/validation_in_linodeclustertemplates.yaml @@ -6,4 +6,7 @@ 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: + template: must be between 3..26 characters, + linode nodebalancer: labels must be between 3..32 characters diff --git a/config/crd/patches/validation_in_linodemachinetemplates.yaml b/config/crd/patches/validation_in_linodemachinetemplates.yaml index 518d79602..817d30677 100644 --- a/config/crd/patches/validation_in_linodemachinetemplates.yaml +++ b/config/crd/patches/validation_in_linodemachinetemplates.yaml @@ -6,12 +6,22 @@ type: string 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 (.) + message: > + custom validation: + template: must be between 3..58 characters, + linode instance: labels must be between 3..64 characters + - 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: Consider combining this into the regex above 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