From abf9733c3900774784c1f5a127f5d2f8bbaeff8a Mon Sep 17 00:00:00 2001 From: Stavros kois Date: Sun, 15 Jan 2023 11:31:09 +0200 Subject: [PATCH] fix test --- .../templates/lib/container/_resources.tpl | 43 +++++++++---------- .../templates/lib/container/_security.tpl | 6 +-- 2 files changed, 23 insertions(+), 26 deletions(-) diff --git a/library/common/1.0.0/templates/lib/container/_resources.tpl b/library/common/1.0.0/templates/lib/container/_resources.tpl index bd70442532..39f5eda13f 100644 --- a/library/common/1.0.0/templates/lib/container/_resources.tpl +++ b/library/common/1.0.0/templates/lib/container/_resources.tpl @@ -84,29 +84,26 @@ memory: {{ . }} {{- $value := .value -}} {{- $required := .required -}} - {{- with (toString $value) -}} {{/* Stringify to avoid falsy values evaluating as false */}} - - {{- if $required -}} {{/* If requred and it's empty fail (requests are requried) */}} - {{- if eq . "" -}} - {{- fail (printf " cannot be empty." $object $key) -}} - {{- end -}} + {{- if $required -}} {{/* If requred and it's empty fail (requests are requried) */}} + {{- if kindIs "invalid" $value -}} + {{- fail (printf " cannot be empty." $object $key) -}} {{- end -}} - - {{/* If it's not null validate input */}} - {{- if ne . "" -}} {{/* Limits can be null, means "no limit" */}} - {{- if eq $key "cpu" -}} - {{/* https://regex101.com/r/D4HouI/1 */}} - {{- if not (mustRegexMatch "^(0\\.[1-9]|[1-9][0-9]*)(\\.[0-9]|m?)$" .) -}} - {{- fail (printf " has invalid format in value (%s). Valid formats are (Plain Integer eg. 1) (Float eg. 0.5) (Milicpu 500m)." $object $key .) -}} - {{- end -}} - - {{- else if eq $key "memory" -}} - {{/* https://regex101.com/r/NNPV2D/1 */}} - {{- if not (mustRegexMatch "^[1-9][0-9]*([EPTGMK]i?|e[0-9]+)?$" .) -}} - {{- fail (printf " has invalid format in value (%s). Valid formats are (Suffixed with EPTGMK eg. 1G) (Suffixed with EPTGMK + i eg. 1Gi) (Plain integer (in bytes) eg. 1024) (Exponent eg. 134e6)." $object $key .) -}} - {{- end -}} - {{- end -}} - {{- end -}} - {{- end -}} + + {{/* If it's not null validate input */}} + {{- if not (kindIs "invalid" $value) -}} {{/* Limits can be null, means "no limit" */}} + {{- if eq $key "cpu" -}} + {{/* https://regex101.com/r/D4HouI/1 */}} + {{- if not (mustRegexMatch "^(0\\.[1-9]|[1-9][0-9]*)(\\.[0-9]|m?)$" (toString $value)) -}} + {{- fail (printf " has invalid format in value (%v). Valid formats are (Plain Integer eg. 1) (Float eg. 0.5) (Milicpu 500m)." $object $key $value) -}} + {{- end -}} + + {{- else if eq $key "memory" -}} + {{/* https://regex101.com/r/NNPV2D/1 */}} + {{- if not (mustRegexMatch "^[1-9][0-9]*([EPTGMK]i?|e[0-9]+)?$" (toString $value)) -}} + {{- fail (printf " has invalid format in value (%v). Valid formats are (Suffixed with EPTGMK eg. 1G) (Suffixed with EPTGMK + i eg. 1Gi) (Plain integer (in bytes) eg. 1024) (Exponent eg. 134e6)." $object $key $value) -}} + {{- end -}} + {{- end -}} + {{- end -}} + {{- end -}} diff --git a/library/common/1.0.0/templates/lib/container/_security.tpl b/library/common/1.0.0/templates/lib/container/_security.tpl index 4a8ab335b8..3a60dbc06c 100644 --- a/library/common/1.0.0/templates/lib/container/_security.tpl +++ b/library/common/1.0.0/templates/lib/container/_security.tpl @@ -83,13 +83,13 @@ The reason is not splitted, is that on one of the places needs a combo of all va {{- fail (printf " key has value (%v). But it must be boolean." $returnValue.privileged) -}} {{- end -}} - {{- if eq (toString $returnValue.runAsUser) "" -}} + {{- if kindIs "invalid" $returnValue.runAsUser -}} {{- fail (printf " key cannot be empty. Set a value or remove the key for the default (%v) to take effect." $defaultSecCont.runAsUser) -}} {{- else if not (mustHas (kindOf $returnValue.runAsUser) (list "int" "float64")) -}} {{- fail (printf " key has value of (%q). But must be an int." $returnValue.runAsUser) -}} {{- end -}} - {{- if eq (toString $returnValue.runAsGroup) "" -}} + {{- if kindIs "invalid" $returnValue.runAsGroup -}} {{- fail (printf " key cannot be empty. Set a value or remove the key for the default (%v) to take effect." $defaultSecCont.runAsGroup) -}} {{- else if not (mustHas (kindOf $returnValue.runAsGroup) (list "int" "float64")) -}} {{- fail (printf " key has value of (%q). But must be an int." $returnValue.runAsGroup) -}} @@ -227,7 +227,7 @@ The reason is not splitted, is that on one of the places needs a combo of all va {{- fail (printf " key must be a string, so the format is kept intact.") -}} {{- end -}} - {{- if eq (toString $returnValue.PUID) "" -}} + {{- if kindIs "invalid" $returnValue.PUID -}} {{- fail (printf " key cannot be empty. Set a value or remove the key for the default (%v) to take effect." $defaultSecEnvs.PUID) -}} {{- else if not (mustHas (kindOf $returnValue.PUID) (list "int" "float64")) -}} {{- fail (printf " key has value of (%q). But must be an int." $returnValue.PUID) -}}